Commit a39e6395 authored by Sharp Hall's avatar Sharp Hall

Notify user when data is weird

parent 2f5d79a8
<html>
<head>
<title>wheresepta</title>
<link rel="stylesheet" href="style.css?1.0.0" type="text/css" />
<link rel="stylesheet" href="style.css?1.1.0" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="app"><div class="notice">Please wait! Loading!</div>
<script src="bundle.js?1.0.0"></script>
<script src="bundle.js?1.1.0"></script>
</body>
</html>
......@@ -15,6 +15,8 @@ var VEHICLE_STOP_THRESHOLD = 0.3;
var STOP_DISTANCE_THRESHOLD = 0.2;
var REFRESH_SECONDS = 25;
var DETOUR_RELOAD_SECONDS = 60 * 10;
var DATA_WEIRDNESS_THRESHOLD = 5;
var DATA_WEIRDNESS_CLUES = ["MIDVALE", "FRONTIER"];
var septaRoutes = {};
......@@ -121,7 +123,8 @@ class WhereSepta extends React.Component {
vehicles: {},
location: null,
loaded: false,
detours: []
detours: [],
dataWeirdness: 0
};
this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
}
......@@ -139,6 +142,13 @@ class WhereSepta extends React.Component {
this.detourTimer = setInterval(() => this.loadDetours(), DETOUR_RELOAD_SECONDS * 1000);
}
dataWeirdness(data) {
return _.chain(data)
.values()
.filter(vehicles => _.findIndex(vehicles, vehicle => DATA_WEIRDNESS_CLUES.includes(vehicle.destination)) !== -1)
.value().length;
}
pullNewData() {
if (document.visibilityState == "visible") {
$.ajax({
......@@ -146,9 +156,11 @@ class WhereSepta extends React.Component {
jsonp: "callback",
dataType: "jsonp",
success: (newData) => {
console.log(this.dataWeirdness(newData.routes[0]));
this.setState({
vehicles: markRoutes(newData.routes[0]),
loaded: true
loaded: true,
dataWeirdness: this.dataWeirdness(newData.routes[0])
});
}
});
......@@ -270,8 +282,14 @@ class WhereSepta extends React.Component {
})
.value();
var detours = _.filter(this.state.detours, detour => selectedRoutes.includes(detour.route_id));
var notices = [];
if (this.state.dataWeirdness >= DATA_WEIRDNESS_THRESHOLD) {
notices.push("We think SEPTA data may be weird right now. " +
this.state.dataWeirdness + " routes included a vehicle with a destination of " +
DATA_WEIRDNESS_CLUES.join(', '));
}
return(
<VehicleList detours={detours} vehicleList={vehicles} routeList={selectedRoutes} />
<VehicleList notices={notices} detours={detours} vehicleList={vehicles} routeList={selectedRoutes} />
);
}
}
......@@ -338,6 +356,7 @@ class VehicleList extends React.Component {
:
<Notice text="You are not near any SEPTA stops." />
}
{this.props.notices.map(notice => <Notice text={notice} key={notice} />)}
<div className="detours">
{this.props.detours.map(detour => (
<Detour detour={detour} key={detour.route_id} />
......
{
"name": "wheresepta",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "main.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment