Skip to content

Commit

Permalink
contest: add trivial ui
Browse files Browse the repository at this point in the history
Add UI which shows the branch creation as a table.

Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed Nov 10, 2023
1 parent d44feed commit 51f0aed
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
57 changes: 57 additions & 0 deletions contest/contest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PW status</title>
<link rel="shortcut icon" href="/favicon-contest.png" type="image/png" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script>
<script src="contest.js"></script>
<script>
do_it();
</script>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}

td, th {
border: 1px solid #eeeeee;
text-align: left;
padding: 8px;
}

tr:nth-child(even) {
background-color: #eeeeee;
}
.row {
display: flex;
}

.column {
flex: 50%;
padding: 1em;
}
</style>
</head>
<body>
<div class="row">
<div class="column">
<table id="results">
<tr>
<th>Date</th>
<th>Branch</th>
<th>Remote</th>
<th>Executor</th>
<th>Group</th>
<th>Test</th>
<th>Result</th>
</tr>
</table>
</div>
</div>
</body>
</html>
51 changes: 51 additions & 0 deletions contest/contest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function colorify_str(value)
{
if (value == "pass") {
ret = '<p style="color:green">';
} else if (value == "skip") {
ret = '<p style="color:blue">';
} else {
ret = '<p style="color:red">';
}
return ret + value + '</p>';
}

function load_result_table(data_raw)
{
var table = document.getElementById("results");

$.each(data_raw, function(i, v) {
$.each(v.results, function(j, r) {
var row = table.insertRow();

var date = row.insertCell(0);
var branch = row.insertCell(1);
var remote = row.insertCell(2);
var exe = row.insertCell(3);
var group = row.insertCell(4);
var test = row.insertCell(5);
var res = row.insertCell(6);

dt = new Date(v.end);
date.innerHTML = dt.toLocaleString();
branch.innerHTML = v.branch;
remote.innerHTML = v.remote;
exe.innerHTML = v.executor;
group.innerHTML = r.group;
test.innerHTML = r.test;
res.innerHTML = colorify_str(r.result);
});
});
}

function results_doit(data_raw)
{
load_result_table(data_raw);
}

function do_it()
{
$(document).ready(function() {
$.get("static/nipa/results.json", results_doit)
});
}
Binary file added contest/favicon-contest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions contest/results-faker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0

import datetime
import json
import os


"""
Combined test runner and collector.
It generates fake data for the UI to display.
It holds no history, only live branches will show up.
"""


def main() -> None:
with open(os.sys.argv[1], "r") as fp:
branches = json.load(fp)

results = []
for br in branches:
data = {"executor": "faker", "remote": "local",
"branch": br["branch"]}

br_dt = datetime.datetime.fromisoformat(br["date"])
br_dt += datetime.timedelta(minutes=2)
data["start"] = br_dt.isoformat()
br_dt += datetime.timedelta(minutes=3)
data["end"] = br_dt.isoformat()

data["results"] = [
{"test": "branch-created", "group": "fake", "result": "pass",
"link": "https://netdev.bots.linux.dev/static/nipa/branches.json"}
]

results.append(data)

with open(os.sys.argv[2], "w") as fp:
json.dump(results, fp)


if __name__ == "__main__":
main()

0 comments on commit 51f0aed

Please sign in to comment.