forked from alltheplaces/alltheplaces.xyz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspiders.html
272 lines (247 loc) · 10.1 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
<!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) {
let red = (percentage > 50 ? 1 - 2 * (percentage - 50) / 100.0 : 1.0) * 255;
let green = (percentage > 50 ? 1.0 : 2 * percentage / 100.0) * 255;
return "rgb(" + red + "," + green + ",0)";
}
let NUM_BUILDS = 5; // Maximum number of builds to display.
let MAX_STABILITY = 500; // Don't grade a standard deviation any more than this.
// 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.
let buildsBySpider = {};
statsList.forEach(statsRun => {
let runName = statsRun["name"]
statsRun.results.forEach(spiderEntry => {
let spiderName = spiderEntry["spider"]
if (!buildsBySpider[spiderName]) {
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.
const row = [entry[0]];
// Only count builds which were run (i.e. have a numeric, possibly zero, entry).
let numValidBuilds = 0;
let sumFeatures = 0;
statsList.forEach(statsRun => {
let runName = statsRun["name"]
if (entry[1][runName]) {
numValidBuilds++;
sumFeatures += entry[1][runName].features;
}
})
const mean = (numValidBuilds === 0) ? 0 : (sumFeatures / numValidBuilds);
let sumSqDeviations = 0;
statsList.forEach(statsRun => {
let runName = statsRun["name"]
if (entry[1][runName]) {
let dev = entry[1][runName].features - mean;
sumSqDeviations += (dev * dev);
}
});
const variance = sumSqDeviations / numValidBuilds;
const stDev = Math.sqrt(variance);
if (sumFeatures > 0) {
const perc = 100 - ((Math.min(stDev, MAX_STABILITY) / MAX_STABILITY ) * 100);
row.push({stDev, perc});
} else {
row.push({stDev:null, perc: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)
})
// 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 = "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: 10,
dom: 'l<"selector-div">frtip',
order: [[2, 'desc']],
columns: [
{
title: "Spider",
},
{
title: "Stability",
data: {
"sort": "1.stDev",
"_": "1.perc",
},
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 === "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);
}
}
}
},
});
$('div.selector-div').html('<label class="selector-label">Links give <select id="format-select" aria-controls="spider-table"><option value="geojson">Feature GeoJSON</option><option value="statistics">Spider stats JSON</option><option value="logs">Spider error logs</option></select></label>');
document.getElementById('format-select').onchange = onLinkFormatChange
</script>
</body>
</html>