-
Notifications
You must be signed in to change notification settings - Fork 10
/
spiders.html
297 lines (275 loc) · 11.9 KB
/
spiders.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.datatables.net/fixedcolumns/4.1.0/css/fixedColumns.dataTables.min.css" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
<title>All the Places Spiders</title>
<style>
body {
font-size: 12px;
padding: 10px 100px;
margin-left: auto;
margin-right: auto;
}
@media (max-width: 960px) {
body { padding: 10px 30px }
/* 820 = 960 - (100-30) * 2 */
@media (min-width: 820px) {
body { width: 820px }
}
}
[data-value="0"] {
color: red;
background-color: pink;
}
.stability-header {
text-align: center !important;
}
.stability-box {
width: 10px;
height: 10px;
border-radius: 10px;
background-color: grey;
position: relative;
right: 0;
margin: auto;
}
.selector-label {
margin-left: 20px;
}
.selector-label>select {
height: 25px;
}
.selector-div {
display: inline-block;
}
</style>
</head>
<body>
<table id="spider-table" class="display" style="width:100%">
<tfoot>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/fixedcolumns/4.1.0/js/dataTables.fixedColumns.min.js" crossorigin="anonymous"></script>
<script src="./shared.js"></script>
<script type=module>
function getColorGradient(percentage) {
if (percentage > 98) {
// Don't mess around with colour gradients for "obviously" good.
return "rgb(0,255,0)";
}
else if (percentage < 70) {
// Don't mess around with colour gradients for "obviously" bad.
return "rgb(255,0,0)";
}
// We give the inbetween scenario a colour gradient.
let inflection = 90
let red = (percentage > inflection ? 1 - 2 * (percentage - inflection) / 100.0 : 1.0) * 255;
let green = (percentage > inflection ? 1.0 : 2 * percentage / 100.0) * 255;
return "rgb(" + red + "," + green + ",0)";
}
const LINK_FORMAT_OPTIONS = [
['map', 'Map'],
['geojson', 'Feature GeoJSON'],
['statistics', 'Spider stats JSON'],
['logs', 'Spider error logs'],
];
const GITHUB_URL = "https://github.com/alltheplaces/alltheplaces/tree/master";
let NUM_BUILDS = 5; // Maximum number of builds to display.
const URL_QUERY_PARAMS = getUrlQueryParams();
function calculateStability(row) {
// Normalise the POI count data such that each run outputs the same maximum number.
let NORMALISED_MAX_POIS = 10000.0
let maxFeatures = 0;
for (let i = 2; i <= NUM_BUILDS + 1; i++) {
if (row[i] > maxFeatures) {
maxFeatures = row[i]
}
}
if (maxFeatures > 0) {
let multiplier = NORMALISED_MAX_POIS / maxFeatures;
let sumSqDeviations = 0;
let runCount = 0;
// Calculate the variance from the MAXIMUM value for each (normalised count) run that occurred.
for (let i = 2; i <= NUM_BUILDS + 1; i++) {
if (row[i] != null) {
let dev = NORMALISED_MAX_POIS - (multiplier * row[i]);
sumSqDeviations += (dev * dev);
runCount++;
}
}
const stDev = Math.sqrt(sumSqDeviations / runCount);
// Set a stability number from 0 to 100.
row[1] = 100 - ((Math.min(stDev, NORMALISED_MAX_POIS) / NORMALISED_MAX_POIS) * 100);
}
}
// Fetch the stats JSON for a particular run.
async function fetchStatsForHistoryListEntry(entry) {
const statsResponse = await window.fetch(entry["stats_url"])
const stats = await statsResponse.json()
stats["name"] = entry["name"]
return stats
}
const historyList = await fetchHistoryList();
historyList.splice(NUM_BUILDS)
console.log(historyList)
// Fetch the stats JSON for the runs we will be rendering.
const statsList = await Promise.all(historyList.map(fetchStatsForHistoryListEntry))
// Re-pivot the build data by spider.
const spiderToFilename = {};
const buildsBySpider = {};
statsList.forEach(statsRun => {
let runName = statsRun["name"]
statsRun.results.forEach(spiderEntry => {
let spiderName = spiderEntry["spider"];
spiderToFilename[spiderName] = spiderEntry["filename"];
buildsBySpider[spiderName] ||= {}
buildsBySpider[spiderName][runName] = {
errors: spiderEntry["errors"],
features: spiderEntry["features"],
elapsed: spiderEntry["elapsed_time"],
}
})
})
// Compute standard deviation and convert to flat tabular format.
let data = [];
Object.entries(buildsBySpider).forEach(entry => {
// Set spider name as the first entry in the row, second entry is for the run stability calculation.
const row = [entry[0], null];
// Now push the number of features in each run for this spider on to the row.
statsList.forEach(statsRun => {
let runName = statsRun["name"]
row.push(entry[1][runName]?.features ?? null)
})
// Calculate how "stable" we think the runs have been for this spider based on historical POI counts.
calculateStability(row)
// Finally add the row to the data table
data.push(row);
});
// Default link format is Featire GeoJSON, the selector in the table header can change this.
let linkFormat = Number.isFinite(parseFloat(URL_QUERY_PARAMS['link_format']))
? LINK_FORMAT_OPTIONS[parseFloat(URL_QUERY_PARAMS['link_format']) - 1]?.[0]
: URL_QUERY_PARAMS['link_format']?.trim();
linkFormat ||= "geojson";
function onLinkFormatChange() {
linkFormat = document.getElementById('format-select').value
dataTable.draw("page")
}
// Render with datatable
let dataTable = $("#spider-table").DataTable({
data,
lengthMenu: [
[10, 15, 20, 25, 50, 75, 100, -1],
[10, 15, 20, 25, 50, 75, 100, "All"],
],
pageLength: parseFloat(URL_QUERY_PARAMS['page_length']) || 10,
dom: 'l<"selector-div">frtip',
order: [[2, 'desc']],
search: { search: URL_QUERY_PARAMS['search'] || '' },
columns: [
{
title: "Spider",
createdCell(cell) {
$(cell).html(`${cell.innerText}<a target="_blank" href="${GITHUB_URL}/${spiderToFilename[cell.innerText]}">✎</a>`);
}
},
{
title: "Stability",
createdCell(cell, cellData) {
const box = $("<div>").addClass("stability-box");
if (Number.isFinite(cellData)) {
box.css("background-color", getColorGradient(cellData));
}
$(cell).empty().append(box);
},
},
...historyList.map(historyEntry => ({
title: historyEntry["name"],
createdCell(cell, cellData, rowData) {
if (cellData || cellData === 0) {
cell.setAttribute("data-value", cellData);
}
},
})),
],
columnDefs: [
{
className: 'dt-center', targets: [1]
},
{
className: 'dt-right', targets: [2,3,4,5,6]
},
{
targets: statsList.map((_, i) => i + 2),
createdCell(cell, cellData) {
cell.dataset.value = cellData;
},
}
],
"footerCallback": function (row, data, start, end, display) {
let api = this.api()
// Total up the numeric columns (all next to each)
let columns = [2,3,4,5,6]
for (let i in columns) {
let total = api
.column(columns[i], {filter: "applied"})
.data()
.reduce(function (a, b) {
return a + b;
}, 0);
// Update total in footer
$(api.column(columns[i]).footer()).html(total.toLocaleString("us-US"));
}
},
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
for (let i = 2; i <= 7; i++) {
if (data[i] || data[i] === 0) {
let linkUrl = null
if ((linkFormat === "map") && historyList[i - 2]["output_url"]) {
let mapUrl = new URL("https://alltheplaces-data.openaddresses.io/map.html");
mapUrl.searchParams.set("show", new URL("output/" + data[0] + ".geojson", historyList[i - 2]["output_url"]).toString());
linkUrl = mapUrl.toString();
}
else if ((linkFormat === "geojson") && historyList[i - 2]["output_url"]) {
linkUrl = new URL("output/" + data[0] + ".geojson", historyList[i - 2]["output_url"]).toString()
}
else if ((linkFormat === "statistics") && historyList[i - 2]["stats_url"]) {
linkUrl = new URL(data[0] + ".json", historyList[i - 2]["stats_url"]).toString()
}
else if ((linkFormat === "logs") && historyList[i - 2]["output_url"]) {
linkUrl = new URL("logs/" + data[0] + ".txt", historyList[i - 2]["output_url"]).toString()
}
let linkData = data[i].toLocaleString("us-US")
if (linkUrl) {
$('td:eq(' + i + ')', row).html('<a href ="' + linkUrl + '">' + linkData + '</a>');
}
else {
$('td:eq(' + i + ')', row).html(linkData);
}
}
}
},
});
const linkFormatOptionsHtml = LINK_FORMAT_OPTIONS.map(([val, label], i) => `<option value="${val}">${label}</option>`).join('');
$('div.selector-div').html(`<label class="selector-label">Links give <select id="format-select" aria-controls="spider-table">${linkFormatOptionsHtml}</select></label>`);
document.getElementById('format-select').value = linkFormat;
document.getElementById('format-select').onchange = onLinkFormatChange;
</script>
</body>
</html>