forked from monsooncollective/yatayat
-
Notifications
You must be signed in to change notification settings - Fork 3
/
data_quality.html
268 lines (238 loc) · 8.73 KB
/
data_quality.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<html>
<head>
<title> Kathmandu Public Transport </title>
<link rel="stylesheet" href="lib/leaflet/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="lib/leaflet/leaflet.ie.css" />
<![endif]-->
<style>
body {
margin:0;
}
#error {
position: absolute;
bottom: 0;
right: 0;
height: 200px;
background-color: black;
color: #00ff00;
width: 100%;
overflow: auto;
}
#errorLog li:hover {
background-color: #111;
color: red;
cursor: pointer;
}
#routepicker {
position: absolute;
top: 0;
right: 0;
}
</style>
<script src="lib/jquery-1.7.2.min.js"></script>
<script src="lib/underscore-min.js"></script>
<script src="lib/leaflet/leaflet.js"></script>
<script src="lib/wax.leaf.min.js"></script>
<script src="lib/kdtree/src/web/kdTree.js"></script>
<script src="yatayat.js"></script>
<script src="dataquality.js"></script>
</head>
<body>
<div id="publicTransportMap" style="width: 100%; height: 100%">Loading ...</div>
<pre></pre>
<pre id="error"><b>WARNINGS</b><ol id="errorLog"> </ol></pre>
<select id="routepicker"></select>
<script type="text/javascript" language="javascript">
// initialize the map
var map = new L.Map('publicTransportMap'),
renderLayer,
sys;
// <iframe width='500' height='300' frameBorder='0' src='http://a.tiles.mapbox.com/v3/suress.map-n0sqwkgh.html#12/27.70131190165252/85.35158157348633'></iframe>
var osmUrl='http://a.tiles.mapbox.com/v3/suress.map-n0sqwkgh.html#12/27.70131190165252/85.35158157348633'
var osm=new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 22})
map.addLayer(osm)
// var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
// var osmAttrib='Map data © OpenStreetMap contributors';
// var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 22, attribution: osmAttrib})
//map.setView(new L.LatLng(),9);
// map.addLayer(osm)
// Changes which route is being viewed -- by changing page-global-var renderLayer
function editRouteByIdx(idx) {
if(renderLayer) {
map.removeLayer(renderLayer);
}
renderLayer = YY.error_render(sys, sys.routes[idx], document.getElementById('errorLog'));
map.addLayer(renderLayer);
}
// Simple helper function; find the route index.
function getRouteIdx(id) {
for(var idx=0; idx<sys.routes.length; idx++) {
if(sys.routes[idx].id === id) {
return idx;
}
}
return -1;
}
// Given the window hash, change the route on display
function editRouteByHash() {
var route_id = window.location.hash.slice(1);
var idx = getRouteIdx(route_id);
if(idx < 0) {
return;
}
var $rp = $("#routepicker");
editRouteByIdx(idx);
if($rp[0].selectedIndex != idx) {
$rp[0].selectedIndex = idx;
}
}
// Watch hash changes and edit route
window.onhashchange = editRouteByHash;
function routeToggler(system) {
var $rp = $('#routepicker')
.change(function() {
window.location.hash = "#"+sys.routes[$rp[0].selectedIndex].id;
});
system.routes.forEach(function(route) {
var $opt = $('<option>')
.html(route.name)
.appendTo($rp);
});
}
YY.fromConfig("config.overpass.json", function(system) {
map.setView(new L.LatLng(YY.LAT, YY.LNG), 13);
system.routes.sort(function(x,y) { return x.name > y.name ? 1 : -1; });
sys = system;
routeToggler(sys); //generates the route selection box on top right corner
renderLayer = YY.error_render(sys, sys.routes[0], document.getElementById("errorLog"));
map.addLayer(renderLayer);
editRouteByHash();
});
if(YY.TILE_SOURCE) {
if (YY.WAX) {
wax.tilejson(YY.TILE_SOURCE, function(tilejson) {
map.addLayer(new wax.leaf.connector(tilejson));
});
} else {
var tiles = new L.TileLayer(YY.TILE_SOURCE, {
attribution: YY.ATTRIBUTION,
maxZoom: 18
});
map.addLayer(tiles);
}
}
YY.error_render = function(system, route, log) {
var layer = new L.LayerGroup();
log.innerHTML = "";
// Check for four classes of errors
// 1. Nearby stops (are they the same?)
var nearby = DQ.nearbyDifferentStops(route, system);
var nearbycol = 'yellow';
// 2. Unnamed stop
var unnamed = DQ.unnamedStops(route);
var unnamedcol = 'black';
// 3. Similarly-named stop (that are far away)
var simnames = DQ.similarNames(route, system);
var simnamescol = 'magenta';
// 4.1 Routes without a start / terminus
var noTerminus = DQ.noTerminus(route);
// 4.2 Unconnected segments (show only if terminus found)
var unconnected = DQ.unconnectedSegments(route);
var unconnectedcol = 'red';
// 5. Stops with the same name one after another
// XXX: TODO
var samename = DQ.sameName(route);
var samenamecol = 'green';
var addLog = function(msg, latlng, marker) {
var $msg = document.createElement('li');
$msg.innerHTML = msg;
var pop = function() {
var popup = new L.Popup();
popup.setLatLng(latlng);
popup.setContent(msg);
map.openPopup(popup);
};
$msg.onclick = pop;
marker.on('click', pop);
log.appendChild($msg);
}
var goodPop = function(msg, latlng, marker) {
var pop = function() {
var popup = new L.Popup();
popup.setLatLng(latlng);
popup.setContent(msg);
map.openPopup(popup);
};
marker.on('click', pop);
}
_.each(route._unconnectedSegments, function(seg, idx) {
var latlngs = seg.listOfLatLng.map(function(LL) { return new L.LatLng(LL[0], LL[1]); });
var poly = new L.Polyline(latlngs, {color: unconnectedcol});
if (noTerminus && !idx) {
var msg = "no start-point (or terminus) defined";
addLog(msg, latlngs[Math.floor(latlngs.length / 2)], poly);
} else if (!noTerminus) {
var msg = "unconnected segment (id:"+seg.id+")";
addLog(msg, latlngs[Math.floor(latlngs.length / 2)], poly);
}
layer.addLayer(poly);
});
_.each(route.segments,function(seg, idx) {
var latlngs = seg.listOfLatLng.map(function(LL) { return new L.LatLng(LL[0], LL[1]); });
var poly = new L.Polyline(latlngs, {color: 'blue'});
layer.addLayer(poly);
goodPop("seg: "+seg.id, latlngs[Math.floor(latlngs.length / 2)], poly);
});
route.stops.forEach(function(stop) {
var marker;
var ll = new L.LatLng(stop.lat, stop.lng);
if(stop.id in nearby) {
marker = new L.CircleMarker(ll,
{color: nearbycol});
var routename = "";
for(var rid in nearby[stop.id].routeDict) {
routename = nearby[stop.id].routeDict[rid].name;
}
var msg = stop.name + " is rather close to " + nearby[stop.id].name + " (in route: "+ routename + ") but they have different names (id:"+stop.id+")";
addLog(msg, ll, marker);
}
else if(stop.id in unnamed) {
marker = new L.CircleMarker(ll,
{color: unnamedcol});
var msg = "unnamed stop (id:"+stop.id+")";
addLog(msg, ll, marker);
}
else if(stop.id in simnames) {
marker = new L.CircleMarker(ll,
{color: simnamescol});
var routename = "";
for(var rid in simnames[stop.id].routeDict) {
routename = simnames[stop.id].routeDict[rid].name;
}
var msg = stop.name + " (id:"+stop.id+") has a similar name to far-off stop " + simnames[stop.id].name + ' in route ' + routename;
addLog(msg, ll, marker);
}
else if(stop.id in samename) {
marker = new L.CircleMarker(ll,
{color: samenamecol});
var routename = "";
for(var rid in samename[stop.id].routeDict) {
routename = samename[stop.id].routeDict[rid].name;
}
var msg = stop.name + " (id:"+stop.id+") has a similar name to far-off stop " + samename[stop.id].name + ' in route ' + routename;
addLog(msg, ll, marker);
}
else {
marker = new L.CircleMarker(ll,
{color: 'red', opacity:1});
goodPop(stop.name + " (id:"+stop.id+")", ll, marker);
}
if(marker)
layer.addLayer(marker);
});
return layer;
};
</script>
</body>
</html>