-
Notifications
You must be signed in to change notification settings - Fork 33
/
tests.html
693 lines (644 loc) · 31.7 KB
/
tests.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<meta charset="utf8" />
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-IUOUHAPazai08QFs7W4MbzTlwEWFo7z/4zw8YmxEiko=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.2.1/dist/sql-wasm.js" integrity="sha256-1mDb9YqGizNOF0OlwicJqO7i2swLOzZAFBAAOeIE+XM=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]" integrity="sha256-Uv9BNBucvCPipKQ2NS9wYpJmi8DTOEfTA/nH2aoJALw=" crossorigin="anonymous"></script>
</head>
<html>
<body>
<div class="d-flex justify-content-between flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom box-shadow">
<div>
<h4 class="my-0 mr-md-auto font-weight-normal">CI Weather Report</h4>
<small>Brought to you by <b>MM</b></small>
</div>
<div>
<h4 class="my-0 mr-md-auto font-weight-normal" id="weather"></h4>
<small id="description"></small>
</div>
<form action="" class="form-inline">
<div class="form-group pr-3">
<label for="repo" class="col-form-label pr-3">Repo</label>
<select id="repo" class="form-control"></select>
</div>
<div class="form-group">
<label for="days" class="col-form-label pr-3">Days</label>
<select id="days" class="form-control"></select>
</div>
</form>
</div>
<nav aria-label="breadcrumb" id="nav" hidden>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#" id="overview">Overview</a></li>
<li class="breadcrumb-item active" aria-current="page" id="current"></li>
</ol>
</nav>
<div class="container-fluid px-5">
<div class="d-flex flex-wrap">
<div class="pr-3" id="t1"></div>
<div id="t2"></div>
</div>
<div class="row">
<div class="col-md-12">
<h2 id="g1-title"></h2>
<canvas id="g1" style="width: 100%; height: 256px"></canvas>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h2 id="g2-title"></h2>
<canvas id="g2" style="width: 100%; height: 256px"></canvas>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h2 id="g3-title"></h2>
<canvas id="g3" style="width: 100%; height: 256px"></canvas>
<div id="g3-details"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h2 id="g4-title"></h2>
<canvas id="g4" style="width: 100%; height: 256px"></canvas>
</div>
</div>
</div>
</body>
<script>
// Pretty format test names
function normalize(name, project) {
name = name.slice(name.lastIndexOf("/") + 1);
if (project !== "cockpit-project/cockpit") {
project = project.slice(project.indexOf("/") + 1); // Remove org
project = project.replace("cockpit-", ""); // Remove "cockpit-" prefix
name = `(${project}) ${name}`;
}
return name;
}
function formatDate(date) {
return `${date.getDate()}.${date.getMonth() + 1}`;
}
// Init select
function select(selector, key, value, values) {
const elem = document.getElementById(selector);
values.forEach(v => {
const option = document.createElement("OPTION");
option.value = v;
option.innerHTML = v;
option.selected = v == value;
elem.appendChild(option);
});
elem.addEventListener("change", e => {
params.set(key, e.target.value);
history.replaceState(null, null, "?"+params.toString());
location.reload();
});
}
const DAY = 86400;
const params = new URLSearchParams(window.location.search);
const days = Number(params.get('days') || 14);
const test = params.get('test');
let repo = params.get('repo') || "All";
select("days", "days", days, [3, 5, 7, 9, 14, 21]);
if (test) {
document.getElementById("nav").hidden = false;
document.getElementById("current").innerHTML = test;
document.getElementById("overview").onclick = () => {
params.delete("test");
history.replaceState(null, null, "?"+params.toString());
location.reload();
};
} else {
document.getElementById("nav").hidden = true;
}
const config = {
locateFile: filename => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.2.1/dist/${filename}`
};
initSqlJs(config).then(SQL => {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'test-results.db', true);
xhr.responseType = 'arraybuffer';
xhr.onload = e => {
const uInt8Array = new Uint8Array(xhr.response);
const db = new SQL.Database(uInt8Array);
const since = (new Date().getTime() / 1000) - days * DAY;
// Find what repos we have reports in the last N days
const repos = db.exec(`
SELECT DISTINCT(project)
FROM TestRuns
WHERE time > ${since}`)[0].values;
repos.unshift("All");
// Init repos select only here as we need to read from DB first
select("repo", "repo", repo, repos);
if (repo === "All")
repo = "%"; // Use SQL wildcard
if (test) {
const top10 = [];
const runs_by_context_table = db.exec(`
SELECT context, COUNT(*)
FROM TestRuns
JOIN Tests ON Tests.run = TestRuns.id
WHERE time > ${since} AND Tests.testname = '${test}' AND project LIKE '${repo}'
GROUP BY context`);
const runs_by_context = {};
runs_by_context_table[0].values.forEach(row => {
runs_by_context[row[0]] = row[1];
});
const fails_by_context = db.exec(`
SELECT context, COUNT(*)
FROM TestRuns
JOIN Tests ON Tests.run = TestRuns.id
WHERE time > ${since} AND Tests.failed = 1 AND Tests.testname = '${test}' AND project LIKE '${repo}'
GROUP BY context
ORDER BY COUNT(*) DESC`)[0].values;
let total_failures = fails_by_context.reduce((acc, row) => acc + row[1], 0);
fails_by_context.forEach(([context, failcount]) => {
const urls = db.exec(`
SELECT DISTINCT TestRuns.url
FROM TestRuns JOIN Tests ON TestRuns.id = Tests.run
WHERE testname = '${test}' AND TestRuns.context = '${context}' AND failed = 1 AND project LIKE '${repo}'
ORDER BY run DESC
LIMIT 2`);
const links = urls[0].values.map(u => u[0]);
top10.push([context, ((failcount * 100) / runs_by_context[context]).toFixed(2), links]);
});
if (!top10.length)
top10.push([`No failures in the last ${days} days`, 0, []]);
createTable("t1", "Most affected OSes", ["Operating system", "Fail rate (%)", "Logs"], top10);
// Show % of failed tests per day
const labels = [];
const points = [];
const yesterday = new Date();
yesterday.setHours(0, 0, 0, 0);
let to = new Date();
let from = yesterday;
for (let i = 0; i < days; i++) {
const failed = db.exec(`
SELECT (t2.count * 100.0) / COUNT(*), COUNT(*)
FROM Tests
JOIN TestRuns ON Tests.run = TestRuns.id
JOIN (
SELECT COUNT(*) as count
FROM Tests
JOIN TestRuns ON Tests.run = TestRuns.id
WHERE TestRuns.time > ${from.getTime() / 1000} AND TestRuns.time < ${to.getTime() / 1000} AND Tests.failed = 1 AND Tests.testname = '${test}' AND project LIKE '${repo}'
) AS t2
WHERE TestRuns.time > ${from.getTime() / 1000} AND TestRuns.time < ${to.getTime() / 1000} AND Tests.testname = '${test}' AND project LIKE '${repo}'`);
labels.unshift(`${formatDate(from)} (${failed[0].values[0][1]} runs)`);
points.unshift(failed[0].values[0][0]);
to = new Date(yesterday);
to.setDate(yesterday.getDate() - i);
from = new Date(yesterday);
from.setDate(yesterday.getDate() - i - 1);
}
createGraph("g1", "Failures per day", labels, [{
data: points,
borderColor: "rgba(24, 42, 94, 0.8)",
fill: false,
spanGaps: true,
}, {
data: Array(days + 1).fill(10),
borderColor: "rgba(1, 2, 3, 0.3)",
fill: false,
spanGaps: true,
}], null, "%");
const all = db.exec(`
SELECT COUNT(*) AS failed
FROM TestRuns
JOIN Tests ON Tests.run = TestRuns.id
WHERE time > ${since} AND Tests.testname = '${test}' AND project LIKE '${repo}'`)[0].values[0][0];
document.getElementById("description").innerHTML = `Showing results from ${all} test runs (${total_failures} failed).`;
} else {
const prs_count = db.exec(`
SELECT COUNT(DISTINCT(revision))
FROM TestRuns
WHERE time > ${since} AND project LIKE '${repo}'`)[0].values[0][0];
const tests_count = db.exec(`
SELECT COUNT(*)
FROM Tests
JOIN TestRuns ON Tests.run = TestRuns.id
WHERE time > ${since} AND project LIKE '${repo}'`)[0].values[0][0];
document.getElementById("description").innerHTML = `Showing results from ${prs_count} PRs and ${tests_count} tests.`;
// Select unexpected messages
let messages = db.exec(`
SELECT retry_reason, TestRuns.url
FROM Tests
JOIN TestRuns ON Tests.run = TestRuns.id
WHERE TestRuns.time > ${since} AND project LIKE '${repo}' AND
retry_reason IS NOT null AND
retry_reason IS NOT 'be robust against unstable tests' AND
retry_reason IS NOT 'test affected tests 3 times' AND
retry_reason IS NOT 'due to failure of test harness or framework'`);
if (messages.length)
messages = messages[0].values.reduce((a, m) => {if (m) a.push([m[0], m[1]]); return a;}, []);
// Replace any numbers > 100 with 0 (usually time stamps or PIDs)
messages = messages.map(m => [m[0].replace(/\d\d[\d\.]+/, '0'), m[1]]);
// Replace any partial paths like dracut.xf8hG with dracut.xxx
messages = messages.map(m => [m[0].replace(/(\/[^\/ \t]{3,}\.)[^\/ \t]+/, "$1xxx"), m[1]]);
const counter = messages.reduce((counter, m) => {
counter[m[0]] = ++counter[m[0]] || 1;
return counter;
}, {});
const data = [];
Object.keys(counter).forEach(m => {
if (counter[m] > 1) { // Don't show message that happened just once
const logs = messages.reduce((a, mx) => {if (mx[0] === m && a.indexOf(mx[1]) < 0) a.push(mx[1]); return a;}, []).splice(0, 2);
data.push([m, counter[m], logs]);
}
});
data.sort((a, b) => a[1] < b[1]);
if (data.length > 0)
createTable("t2", "Unexpected messages", ["Message", "Count", "Logs"], data);
// Get all failures sorted by descending fail rate
const top_failures = [];
const result = db.exec(`
SELECT allruns.testname, project, failruns.context, (failruns.failed * 100.0) / COUNT(run) AS percent
FROM Tests AS allruns
JOIN TestRuns ON allruns.run = TestRuns.id
JOIN (
SELECT testname, context, COUNT(run) as failed
FROM Tests
JOIN TestRuns ON Tests.run = TestRuns.id
WHERE TestRuns.time > ${since} AND Tests.failed = 1 AND project LIKE '${repo}'
GROUP BY testname, context
) AS failruns ON allruns.testname = failruns.testname AND TestRuns.context = failruns.context
WHERE TestRuns.time > ${since} AND failruns.failed > 1 AND project LIKE '${repo}'
GROUP BY allruns.testname, failruns.context
ORDER BY percent DESC`);
if (result.length) {
const rows = result[0].values;
// If we have more than 10 results, truncate below 10% failure rate
if (rows.length > 10) {
for (let i = 0; i < rows.length; i++) {
if (rows[i][3] < 10) {
rows.splice(i);
break;
}
}
}
rows.forEach(row => {
const urls = db.exec(`
SELECT DISTINCT TestRuns.url
FROM TestRuns JOIN Tests ON TestRuns.id = Tests.run
WHERE testname = '${row[0]}' AND failed = 1 AND project LIKE '${repo}' AND context = '${row[2]}'
ORDER BY run DESC
LIMIT 2`);
const links = urls[0].values.map(u => u[0]);
top_failures.push([{name: normalize(row[0], row[1]), key_name: row[0], key: "test"}, row[2], row[3].toFixed(2), links]);
});
} else
top_failures.push([`No failures in the last ${days} days`, "", 0, []]);
createTable("t1", "Top failures", ["Test name", "Context", "Fail rate (%)", "Logs"], top_failures);
// Show average waiting time in queue per day
const time_points = [];
const wait_points = [];
const test_points = [];
const wait_labels = [];
const pr_labels = [];
const pr_points = [];
let max = 0;
let all = 0;
let all_runs = 0;
let max_runs = 0;
const yesterday = new Date();
yesterday.setHours(0, 0, 0, 0);
let to = new Date();
let from = yesterday;
for (let i = 0; i < days; i++) {
const wait = db.exec(`
SELECT SUM(wait_seconds) / COUNT(*), COUNT(*)
FROM TestRuns
WHERE time > ${from.getTime() / 1000} AND time < ${to.getTime() / 1000} AND project LIKE '${repo}'`);
all_runs = wait[0].values[0][1];
wait_points.unshift(wait[0].values[0][0]);
wait_labels.unshift(`${formatDate(from)} (${all_runs} runs)`);
// % of tests that took longer than 60 minutes from trigger to completion
const time = db.exec(`
SELECT COUNT(*)
FROM TestRuns
WHERE wait_seconds + run_seconds > 3600 AND time > ${from.getTime() / 1000} AND time < ${to.getTime() / 1000} AND project LIKE '${repo}'`);
time_points.unshift((time[0].values[0][0] * 100) / all_runs);
const tests = db.exec(`
SELECT state, description, COUNT(TestRuns.id)
FROM TestRuns
LEFT JOIN Tests ON Tests.run = TestRuns.id
WHERE time > ${from.getTime() / 1000} AND time < ${to.getTime() / 1000} AND project LIKE '${repo}'
AND state != "success"
GROUP BY TestRuns.id`);
if (tests.length) {
let not_tested = 0; // Never picked
let testing = 0; // Never finished (merged while still running)
let error = 0; // Aborted without status
let in_prep = 0; // Failed in preparation
let failed = 0; // Some tests failed
tests[0].values.forEach(v => {
if (v[0] === "pending" && v[2] <= 1) not_tested++;
else if (v[0] === "pending") testing++;
else if (v[0] === "error") error++;
else if (v[2] <= 1) in_prep++;
else failed++;
});
test_points.unshift([(not_tested * 100) / all_runs, (testing * 100) / all_runs, (error * 100) / all_runs, (in_prep * 100) / all_runs, (failed * 100) / all_runs]);
max_runs = Math.max(max_runs, 100 - ((all_runs - (not_tested + testing + error + in_prep + failed)) * 100) / all_runs);
} else if (all_runs > 0) {
test_points.unshift([0, 0, 0, 0, 0]);
} else {
test_points.unshift([null, null, null, null, null]);
}
const prs = db.exec(`
SELECT revision, context, state, MAX(retry) as top
FROM TestRuns
JOIN ( SELECT revision AS rev, MAX(time) AS time
FROM TestRuns
GROUP BY revision
) AS t1 ON t1.rev = revision
WHERE t1.time > ${from.getTime() / 1000} AND t1.time < ${to.getTime() / 1000} AND project LIKE '${repo}'
GROUP BY revision, context`);
if (prs.length) {
const shas = {};
prs[0].values.forEach(i => {
if (i[2] !== "success")
shas[i[0]] = -1;
else if (shas[i[0]] !== -1) // No context failed
shas[i[0]] = Math.max(shas[i[0]] || 0, i[3]);
});
all = Object.keys(shas).length;
let red = 0; // Merged with failed test
let orange = 0; // Merged green with one max one retry
let green = 0; // Merged green without any retry
Object.values(shas).forEach(v => {
if (v === -1) red++;
else if (v === 0) green++;
else if (v === 1) orange++;
});
pr_points.unshift([(orange * 100) / all, ((all - green - orange - red) * 100) / all, (red * 100) / all]);
max = Math.max(max, 100 - (green * 100) / all);
} else {
all = 0;
pr_points.unshift([null, null, null]);
}
pr_labels.unshift(`${formatDate(from)} (${all} PRs)`);
to = new Date(yesterday);
to.setDate(yesterday.getDate() - i);
from = new Date(yesterday);
from.setDate(yesterday.getDate() - i - 1);
}
createGraph("g1", "Pull requests semaphore", pr_labels, [{
data: Array(days + 1).fill(25),
borderColor: "rgba(50, 150, 50, 0.3)",
fill: false,
spanGaps: true,
label: "Limit for one retry",
yAxisID: "limit",
}, {
data: Array(days + 1).fill(5),
borderColor: "rgba(120, 120, 50, 0.3)",
fill: false,
spanGaps: true,
label: "Limit for any retry",
yAxisID: "limit",
}, {
data: pr_points.map(p => p[2]),
borderColor: "rgba(180, 25, 52, 0.8)",
backgroundColor: "rgba(180, 25, 52, 0.8)",
spanGaps: true,
label: "Merged red",
yAxisID: "main",
}, {
data: pr_points.map(p => p[1]),
borderColor: "rgba(180, 100, 25, 0.8)",
backgroundColor: "rgba(180, 100, 25, 0.8)",
spanGaps: true,
label: "Green with 2+ retries",
yAxisID: "main",
}, {
data: pr_points.map(p => p[0]),
borderColor: "rgba(180, 180, 25, 0.8)",
backgroundColor: "rgba(180, 180, 25, 0.8)",
spanGaps: true,
label: "Green with 1 retry",
yAxisID: "main",
}], {
scales: {
yAxes: [{
id: "limit",
display: false,
ticks: {
min: 0,
max: max,
},
}, {
id: "main",
stacked: true,
ticks: {
min: 0,
max: max,
},
scaleLabel: {
display: true,
labelString: "% (stacked)",
},
}]
},
responsive: false,
});
createGraph("g2", "Test runs semaphore", wait_labels, [{
data: Array(days + 1).fill(10),
borderColor: "rgba(120, 120, 50, 0.3)",
fill: false,
spanGaps: true,
label: "Limit for non-completed (except 'Failed tests')",
yAxisID: "limit",
}, {
data: test_points.map(p => p[0]),
borderColor: "rgba(25, 52, 180, 0.8)",
backgroundColor: "rgba(25, 52, 180, 0.8)",
spanGaps: true,
label: "Never picked",
yAxisID: "main",
}, {
data: test_points.map(p => p[1]),
borderColor: "rgba(25, 180, 180, 0.8)",
backgroundColor: "rgba(25, 180, 180, 0.8)",
spanGaps: true,
label: "Never finished",
yAxisID: "main",
}, {
data: test_points.map(p => p[2]),
borderColor: "rgba(180, 25, 25, 0.8)",
backgroundColor: "rgba(180, 25, 25, 0.8)",
spanGaps: true,
label: "Aborted",
yAxisID: "main",
}, {
data: test_points.map(p => p[3]),
borderColor: "rgba(180, 100, 25, 0.8)",
backgroundColor: "rgba(180, 100, 25, 0.8)",
spanGaps: true,
label: "Failed in preparation",
yAxisID: "main",
}, {
data: test_points.map(p => p[4]),
borderColor: "rgba(180, 180, 25, 0.8)",
backgroundColor: "rgba(180, 180, 25, 0.8)",
spanGaps: true,
label: "Failed tests",
yAxisID: "main",
}], {
scales: {
yAxes: [{
id: "limit",
display: false,
ticks: {
min: 0,
max: max_runs,
},
}, {
id: "main",
stacked: true,
ticks: {
min: 0,
max: max_runs,
},
scaleLabel: {
display: true,
labelString: "% (stacked)",
},
}]
},
responsive: false,
});
createGraph("g3", "Tests that did not finish within 60 minutes", wait_labels, [{
data: time_points,
borderColor: "rgba(94, 42, 24, 0.8)",
fill: false,
spanGaps: true,
}, {
data: Array(days + 1).fill(5),
borderColor: "rgba(1, 2, 3, 0.3)",
fill: false,
spanGaps: true,
}], null, "%");
// Render logs for last 15 tests that did not finish within 60 minutes
const time_logs = db.exec(`
SELECT context, time, url, wait_seconds + run_seconds AS took
FROM TestRuns
WHERE wait_seconds + run_seconds > 3600 AND time > ${since} AND project LIKE '${repo}'
ORDER BY time DESC
LIMIT 15`);
if (time_logs.length) {
const parent_logs = document.createElement("div");
time_logs[0].values.forEach((t, i) => {
const ea = document.createElement("A");
if (i < time_logs[0].values.length - 1)
ea.className="mr-3";
ea.textContent = `${formatDate(new Date(t[1] * 1000))} ${t[0]} (${Math.floor(t[3]/60)}mins)`;
ea.href = t[2];
parent_logs.appendChild(ea);
});
document.getElementById("g3-details").appendChild(parent_logs);
}
createGraph("g4", "Average time waiting in queue", wait_labels, [{
data: wait_points,
borderColor: "rgba(24, 42, 94, 0.8)",
fill: false,
spanGaps: true,
}, {
data: Array(days + 1).fill(300),
borderColor: "rgba(1, 2, 3, 0.3)",
fill: false,
spanGaps: true,
}], null, "seconds");
}
};
xhr.send();
});
function createGraph(id, name, labels, datasets, options, ylabel) {
document.getElementById(id).innerHTML = "";
document.getElementById(id + "-title").innerHTML = name;
if (!options)
options = {
legend: {
display: false,
},
responsive: false,
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: ylabel,
},
}]
}
};
// Create graph itself
const ctx = document.getElementById(id);
new Chart(ctx, {
type: "line",
data: {
labels: labels,
datasets: datasets,
},
options: options,
});
}
function createTable(id, name, columns, data) {
const wrapper = document.createElement("DIV");
// Create title of the table
const title = document.createElement("H2");
title.textContent = name;
wrapper.appendChild(title);
// Create table itself
const table = document.createElement("TABLE");
table.className="table table-striped";
// Create heading
const head = document.createElement("THEAD");
let row = document.createElement("TR");
columns.forEach(c => {
const th = document.createElement("TH");
th.textContent = c;
row.appendChild(th);
});
head.appendChild(row);
table.appendChild(head);
// Fill the table with data
const body = document.createElement("TBODY");
data.forEach(r => {
row = document.createElement("TR");
r.forEach(d => {
// Array with logs
const td = document.createElement("TD");
if (d instanceof Array) {
d.forEach((a, i) => {
const ea = document.createElement("A");
if (i < d.length - 1)
ea.className="mr-3";
ea.textContent = "log";
ea.href = a;
td.appendChild(ea);
});
} else if (typeof d == "object") {
const ea = document.createElement("A");
ea.className="mr-3";
ea.textContent = d.name;
ea.href="#";
ea.onclick = () => {
params.set(d.key, d.key_name);
history.replaceState(null, null, "?"+params.toString());
location.reload();
};
td.appendChild(ea);
} else {
td.textContent = d;
}
row.appendChild(td);
});
body.appendChild(row);
});
table.appendChild(body);
wrapper.appendChild(table);
document.getElementById(id).innerHTML = "";
document.getElementById(id).appendChild(wrapper);
}
</script>
</html>