Reformat everything

This commit is contained in:
Joscha 2024-05-11 18:32:36 +02:00
parent 93663fff8c
commit 36ce75b43d
12 changed files with 560 additions and 526 deletions

View file

@ -5,11 +5,13 @@ Run benchmarks against commits in a git repo and present their results.
## Building from source
The following tools are required:
- `cargo` and `rustc` (best installed via [rustup](https://rustup.rs/))
- `tsc`, the [typescript](https://www.typescriptlang.org/) compiler
Once you have installed these tools, run the following command to install or
update tablejohn to `~/.cargo/bin/tablejohn`:
```
cargo install --force --git https://github.com/Garmelon/tablejohn
```

View file

@ -24,7 +24,9 @@ export class Commits {
update(response: CommitsResponse) {
console.assert(response.hashByHash.length == response.authorByHash.length);
console.assert(response.hashByHash.length == response.committerDateByHash.length);
console.assert(
response.hashByHash.length == response.committerDateByHash.length,
);
console.assert(response.hashByHash.length == response.summaryByHash.length);
let commits = this.#loadCommits(response);
@ -36,15 +38,18 @@ export class Commits {
commit.indexByGraph = idx;
}
const committerDatesNormal = commits.map(c => c.committerDate);
const committerDatesDayEquidistant = this.#makeDayEquidistant(committerDatesNormal);
const committerDatesNormal = commits.map((c) => c.committerDate);
const committerDatesDayEquidistant =
this.#makeDayEquidistant(committerDatesNormal);
// To prevent exceptions and other weirdness from messing up our state,
// we update everything in one go.
this.#graphId = response.graphId;
this.#commitsByGraph = commits;
this.#committerDatesNormal = this.#epochTimesToDates(committerDatesNormal);
this.#committerDatesDayEquidistant = this.#epochTimesToDates(committerDatesDayEquidistant);
this.#committerDatesDayEquidistant = this.#epochTimesToDates(
committerDatesDayEquidistant,
);
}
#loadCommits(response: CommitsResponse): Commit[] {
@ -95,7 +100,7 @@ export class Commits {
*/
#sortCommitsTopologically(commits: Commit[]): Commit[] {
const visited: Set<string> = new Set();
const visiting: Commit[] = commits.filter(c => c.parents.length == 0);
const visiting: Commit[] = commits.filter((c) => c.parents.length == 0);
const sorted: Commit[] = [];
@ -128,7 +133,7 @@ export class Commits {
* Assumes the times are sorted.
*/
#makeDayEquidistant(times: number[]): number[] {
const days: { day: number, amount: number; }[] = [];
const days: { day: number; amount: number }[] = [];
for (const time of times) {
const day = time % SECONDS_PER_DAY;
const prev = days.at(-1);
@ -152,6 +157,6 @@ export class Commits {
}
#epochTimesToDates(times: number[]): Date[] {
return times.map(t => new Date(1000 * t));
return times.map((t) => new Date(1000 * t));
}
}

View file

@ -23,28 +23,43 @@ class Folder {
}
toHtmlElement(name: string): HTMLElement {
if (this.children.size > 0) { // Folder
if (this.children.size > 0) {
// Folder
name = `${name}/`;
if (this.metric === null) { // Folder without metric
return el("details", { "class": "no-metric" },
if (this.metric === null) {
// Folder without metric
return el(
"details",
{ class: "no-metric" },
el("summary", {}, name),
this.childrenToHtmlElements(),
);
} else { // Folder with metric
return el("details", {},
el("summary", {},
el("input", { "type": "checkbox", "name": this.metric }),
" ", name,
} else {
// Folder with metric
return el(
"details",
{},
el(
"summary",
{},
el("input", { type: "checkbox", name: this.metric }),
" ",
name,
),
this.childrenToHtmlElements(),
);
}
} else if (this.metric !== null) { // Normal metric
return el("label", {},
el("input", { "type": "checkbox", "name": this.metric }),
" ", name,
} else if (this.metric !== null) {
// Normal metric
return el(
"label",
{},
el("input", { type: "checkbox", name: this.metric }),
" ",
name,
);
} else { // Metric without metric, should never happen
} else {
// Metric without metric, should never happen
return el("label", {}, name);
}
}
@ -69,7 +84,8 @@ export class Metrics {
getSelected(): Set<string> {
const selected = new Set<string>();
const checkedInputs = this.#div.querySelectorAll<HTMLInputElement>("input:checked");
const checkedInputs =
this.#div.querySelectorAll<HTMLInputElement>("input:checked");
for (const input of checkedInputs) {
selected.add(input.name);
}

View file

@ -24,7 +24,7 @@ export type CommitsResponse = {
export type MeasurementsResponse = {
graphId: number;
dataId: number;
measurements: { [key: string]: (number | null)[]; };
measurements: { [key: string]: (number | null)[] };
};
async function getData<R>(url: string): Promise<R> {
@ -41,7 +41,9 @@ export async function getCommits(): Promise<CommitsResponse> {
return getData("commits");
}
export async function getMeasurements(metrics: string[]): Promise<MeasurementsResponse> {
const params = new URLSearchParams(metrics.map(m => ["metric", m]));
export async function getMeasurements(
metrics: string[],
): Promise<MeasurementsResponse> {
const params = new URLSearchParams(metrics.map((m) => ["metric", m]));
return getData(`measurements?${params}`);
}

View file

@ -1,7 +1,11 @@
/**
* Create an {@link HTMLElement}.
*/
export function el(name: string, attributes: { [key: string]: string; }, ...children: (string | Node)[]) {
export function el(
name: string,
attributes: { [key: string]: string },
...children: (string | Node)[]
) {
let element = document.createElement(name);
for (let [name, value] of Object.entries(attributes)) {
element.setAttribute(name, value);

View file

@ -3,11 +3,14 @@ const REFRESH_SECONDS = 10;
function update() {
fetch("inner")
.then(response => response.text())
.then(text => {
.then((response) => response.text())
.then((text) => {
INNER.innerHTML = text;
let count = document.getElementById("queue")?.dataset["count"]!;
document.title = document.title.replace(/^queue \(\S+\)/, `queue (${count})`);
document.title = document.title.replace(
/^queue \(\S+\)/,
`queue (${count})`,
);
});
}

View file

@ -7,7 +7,7 @@
}
body {
margin: .7em;
margin: 0.7em;
}
details,
@ -20,7 +20,7 @@ ul {
h2 {
font-size: 1.7em;
margin: 1em 0 .5em;
margin: 1em 0 0.5em;
}
a {
@ -33,7 +33,7 @@ a:hover {
}
button {
padding: 0 .5ch;
padding: 0 0.5ch;
}
button.linkish {
@ -45,7 +45,7 @@ button.linkish {
}
details {
padding: .3em 1ch;
padding: 0.3em 1ch;
background-color: #ddd;
}
@ -88,8 +88,7 @@ tbody tr:hover {
th,
td {
padding: .1em 0;
padding: 0.1em 0;
}
th + th,
@ -170,17 +169,17 @@ nav a:hover {
.graph-container #plot {
margin-right: 1em;
margin-bottom: 1em;
box-shadow: 0 0 .5em black;
box-shadow: 0 0 0.5em black;
}
.graph-container #metrics {
flex: 0 50ch;
box-shadow: 0 0 .5em black;
box-shadow: 0 0 0.5em black;
}
.metrics-list {
background-color: #ddd;
padding: .3em 1ch;
padding: 0.3em 1ch;
}
.metrics-list * {
@ -204,8 +203,8 @@ nav a:hover {
}
.metrics-list summary ~ * {
border-left: .1ch solid black;
margin-left: .9ch;
border-left: 0.1ch solid black;
margin-left: 0.9ch;
padding-left: 1ch;
}
@ -240,7 +239,9 @@ nav a:hover {
column-gap: 1ch;
}
.commit-like dl, .commit-like dt, .commit-like dd {
.commit-like dl,
.commit-like dt,
.commit-like dd {
margin: 0;
}

View file

@ -1,4 +1,5 @@
{ // See also https://aka.ms/tsconfig
{
// See also https://aka.ms/tsconfig
"include": ["scripts/**/*"],
"compilerOptions": {
@ -19,6 +20,6 @@
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"strict": true,
"strict": true
}
}