@milabench/bujang 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/api.d.ts +16 -3
- package/dist/components/OrganizerNav.d.ts +28 -0
- package/dist/components/ProjectsNav.d.ts +15 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +6132 -5023
- package/dist/index.js.map +1 -1
- package/dist/paths.d.ts +25 -3
- package/dist/routes.d.ts +7 -2
- package/dist/types.d.ts +77 -5
- package/dist/views/CollectionView.d.ts +22 -0
- package/dist/views/JobDataOverview.d.ts +1 -1
- package/dist/views/JobsView.d.ts +12 -1
- package/dist/views/LogDisplay.d.ts +2 -0
- package/dist/views/OrganizerValuesView.d.ts +13 -0
- package/dist/views/OverviewPanels.d.ts +13 -2
- package/dist/views/ProjectDetailsView.d.ts +3 -0
- package/dist/views/ProjectsView.d.ts +18 -0
- package/dist/views/dataCharts.d.ts +1 -1
- package/package.json +1 -1
- package/src/api.ts +36 -6
- package/src/components/OrganizerNav.tsx +121 -0
- package/src/components/ProjectsNav.tsx +101 -0
- package/src/index.ts +10 -2
- package/src/paths.ts +47 -6
- package/src/routes.tsx +19 -4
- package/src/types.ts +77 -6
- package/src/views/CollectionView.tsx +68 -0
- package/src/views/JanitorView.tsx +2 -1
- package/src/views/JobDataOverview.tsx +23 -6
- package/src/views/JobLogs.tsx +2 -1
- package/src/views/JobSubmit.tsx +68 -0
- package/src/views/JobsTable.tsx +44 -6
- package/src/views/JobsView.tsx +26 -9
- package/src/views/LogDisplay.tsx +5 -2
- package/src/views/OrganizerValuesView.tsx +207 -0
- package/src/views/OverviewPanels.tsx +531 -7
- package/src/views/ProjectDetailsView.tsx +112 -0
- package/src/views/ProjectsView.tsx +117 -8
- package/src/views/SetupView.tsx +39 -1
- package/src/views/dataCharts.tsx +1 -1
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { Alert, Badge, Box, Button, Card, Code, Dialog, Flex, HStack, Input, NativeSelect, Spinner, Table, Text, VStack, Wrap } from '@chakra-ui/react';
|
|
4
4
|
import { useQueries, useQuery } from '@tanstack/react-query';
|
|
5
|
-
import { LuArrowDown, LuArrowLeft, LuArrowRight, LuArrowUp, LuChevronDown, LuChevronRight, LuColumns2, LuDownload, LuExternalLink, LuFile, LuFolder, LuPlus, LuSettings, LuX } from 'react-icons/lu';
|
|
5
|
+
import { LuArrowDown, LuArrowLeft, LuArrowRight, LuArrowUp, LuChevronDown, LuChevronRight, LuColumns2, LuDownload, LuExternalLink, LuFile, LuFilter, LuFilterX, LuFolder, LuPlus, LuSettings, LuX } from 'react-icons/lu';
|
|
6
6
|
import { getJobArtifacts, getJobDataRows, jobArtifactUrl } from '../api';
|
|
7
|
-
import type { ApiError, ColumnsPanel, JobArtifacts, JobData, JobOverviewLayout, OverviewBlock, OverviewLayout, OverviewPanel, StatName, StatsMetric } from '../types';
|
|
7
|
+
import type { ApiError, CollectionJob, ColumnsPanel, CompareMetric, CompareRuleColor, CompareRuleOp, CompareScale, CompareStat, JobArtifacts, JobData, JobOverviewLayout, OverviewBlock, OverviewLayout, OverviewPanel, StatName, StatsMetric } from '../types';
|
|
8
|
+
import { Link } from 'react-router-dom';
|
|
9
|
+
import { useBujangPaths } from '../context';
|
|
10
|
+
import { NO_JOB_ID } from '../constants';
|
|
8
11
|
import { MonacoEditor } from '../components/MonacoEditor';
|
|
9
12
|
import { formatSize } from './JobArtifacts';
|
|
10
13
|
import {
|
|
@@ -1049,8 +1052,14 @@ const SOURCE_TEXT: Record<JobOverviewLayout['source']['kind'], string> = {
|
|
|
1049
1052
|
plugin: 'from the plugin',
|
|
1050
1053
|
setting: 'the default layout (settings)',
|
|
1051
1054
|
default: 'the built-in layout',
|
|
1055
|
+
experiments: 'saved for the experiment',
|
|
1056
|
+
groups: 'saved for the group',
|
|
1057
|
+
projects: 'saved in the project folder',
|
|
1052
1058
|
};
|
|
1053
1059
|
|
|
1060
|
+
/** The singular of a collection scope, for the buttons */
|
|
1061
|
+
const SCOPE_NAME: Record<string, string> = { experiments: 'experiment', groups: 'group', projects: 'project' };
|
|
1062
|
+
|
|
1054
1063
|
/** The layout shown: the one of the job, or the built-in explorer of its data */
|
|
1055
1064
|
export type OverviewView = 'job' | 'explore';
|
|
1056
1065
|
|
|
@@ -1078,12 +1087,13 @@ export const LayoutBar: React.FC<{
|
|
|
1078
1087
|
editing: boolean;
|
|
1079
1088
|
saving: boolean;
|
|
1080
1089
|
onEdit: (on: boolean) => void;
|
|
1081
|
-
onSave: (target: 'experiment' | 'script' | 'default') => void;
|
|
1090
|
+
onSave: (target: 'experiment' | 'script' | 'default' | 'collection') => void;
|
|
1082
1091
|
onDiscard: () => void;
|
|
1083
1092
|
onReset: () => void;
|
|
1084
1093
|
}> = ({ found, source, view, onView, dirty, editing, saving, onEdit, onSave, onDiscard, onReset }) => {
|
|
1085
1094
|
const { keys } = found;
|
|
1086
|
-
const
|
|
1095
|
+
const collection = keys.collection;
|
|
1096
|
+
const saved = source.kind !== 'file' && source.kind !== 'plugin' && source.kind !== 'setting' && source.kind !== 'default';
|
|
1087
1097
|
return (
|
|
1088
1098
|
<Card.Root {...cardProps}>
|
|
1089
1099
|
<Card.Body py={2}>
|
|
@@ -1098,7 +1108,7 @@ export const LayoutBar: React.FC<{
|
|
|
1098
1108
|
>
|
|
1099
1109
|
{found.layouts.map((entry, i) => (
|
|
1100
1110
|
<option key={layoutKeyOf(entry.source)} value={layoutKeyOf(entry.source)}>
|
|
1101
|
-
{entry.label ?? layoutLabel(entry.source)}{i === 0 ? ' (this job)' : ''}
|
|
1111
|
+
{entry.label ?? layoutLabel(entry.source)}{i === 0 && !collection ? ' (this job)' : ''}
|
|
1102
1112
|
</option>
|
|
1103
1113
|
))}
|
|
1104
1114
|
<option value="explore">Explore data</option>
|
|
@@ -1108,7 +1118,9 @@ export const LayoutBar: React.FC<{
|
|
|
1108
1118
|
<Text color="var(--color-text-muted)">
|
|
1109
1119
|
{view === 'job'
|
|
1110
1120
|
? <>{SOURCE_TEXT[source.kind]} {source.name && <Code>{source.name}</Code>}</>
|
|
1111
|
-
:
|
|
1121
|
+
: collection
|
|
1122
|
+
? 'plot the data of the jobs, and add the charts to the layout'
|
|
1123
|
+
: 'plot the data of the job, and add the charts to its layout'}
|
|
1112
1124
|
</Text>
|
|
1113
1125
|
{dirty && <Badge size="xs" colorPalette="orange">not saved</Badge>}
|
|
1114
1126
|
</HStack>
|
|
@@ -1118,7 +1130,18 @@ export const LayoutBar: React.FC<{
|
|
|
1118
1130
|
{editing ? 'Done' : 'Edit'}
|
|
1119
1131
|
</Button>
|
|
1120
1132
|
)}
|
|
1121
|
-
{dirty && (
|
|
1133
|
+
{dirty && collection && (
|
|
1134
|
+
<>
|
|
1135
|
+
<Button size="xs" variant="outline" loading={saving} onClick={() => onSave('collection')}
|
|
1136
|
+
title={collection.scope === 'projects'
|
|
1137
|
+
? 'Saved in the project folder: layouts/overview.yaml, versioned with the code'
|
|
1138
|
+
: `The Overview of this ${SCOPE_NAME[collection.scope]}`}>
|
|
1139
|
+
Save for {SCOPE_NAME[collection.scope]} <Code ml={1}>{collection.key}</Code>
|
|
1140
|
+
</Button>
|
|
1141
|
+
<Button size="xs" variant="ghost" onClick={onDiscard}>Discard</Button>
|
|
1142
|
+
</>
|
|
1143
|
+
)}
|
|
1144
|
+
{dirty && !collection && (
|
|
1122
1145
|
<>
|
|
1123
1146
|
{keys.experiment && (
|
|
1124
1147
|
<Button size="xs" variant="outline" loading={saving} onClick={() => onSave('experiment')}
|
|
@@ -1183,6 +1206,7 @@ const AddButtons: React.FC<{ files: JobData['files']; blocks: OverviewBlock[]; o
|
|
|
1183
1206
|
<Button size="2xs" variant="outline" onClick={() => onAdd({ kind: 'artifacts', title: 'Artifacts' })}><LuPlus /> Artifacts</Button>
|
|
1184
1207
|
<Button size="2xs" variant="outline" onClick={() => onAdd({ kind: 'files', title: 'Files' })}><LuPlus /> Files</Button>
|
|
1185
1208
|
<Button size="2xs" variant="outline" onClick={() => onAdd({ kind: 'stats', title: 'Stats' })}><LuPlus /> Stats</Button>
|
|
1209
|
+
<Button size="2xs" variant="outline" onClick={() => onAdd({ kind: 'compare', title: 'Jobs' })}><LuPlus /> Compare</Button>
|
|
1186
1210
|
<Button size="2xs" variant="outline" onClick={() => onAdd({ kind: 'logs', title: 'Logs' })}><LuPlus /> Logs</Button>
|
|
1187
1211
|
{children}
|
|
1188
1212
|
</Wrap>
|
|
@@ -1222,6 +1246,9 @@ export const LayoutPanels: React.FC<{
|
|
|
1222
1246
|
if (panel.kind === 'stats') {
|
|
1223
1247
|
return <StatsPanel key={id} jrJobId={jrJobId} files={files} panel={panel} actions={actions} />;
|
|
1224
1248
|
}
|
|
1249
|
+
if (panel.kind === 'compare') {
|
|
1250
|
+
return <ComparePanel key={id} jrJobId={jrJobId} files={files} panel={panel} actions={actions} />;
|
|
1251
|
+
}
|
|
1225
1252
|
if (panel.kind === 'files') {
|
|
1226
1253
|
return <FilesPanel key={id} jrJobId={jrJobId} files={files} panel={panel} actions={actions} />;
|
|
1227
1254
|
}
|
|
@@ -1337,3 +1364,500 @@ export const LayoutPanels: React.FC<{
|
|
|
1337
1364
|
</OneRank.Provider>
|
|
1338
1365
|
);
|
|
1339
1366
|
};
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
/** The jobs of a collection Overview (experiment, group, project), given by its page to the compare blocks */
|
|
1370
|
+
export const CollectionJobs = createContext<CollectionJob[] | null>(null);
|
|
1371
|
+
|
|
1372
|
+
export const COMPARE_STATS: CompareStat[] = ['last', 'first', 'min', 'max', 'mean', 'count'];
|
|
1373
|
+
|
|
1374
|
+
/** The statistic of the values of a field, in the order of the rows */
|
|
1375
|
+
const compareStat = (values: number[], stat: CompareStat): number | null => {
|
|
1376
|
+
if (!values.length) return stat === 'count' ? 0 : null;
|
|
1377
|
+
switch (stat) {
|
|
1378
|
+
case 'first': return values[0];
|
|
1379
|
+
case 'min': return Math.min(...values);
|
|
1380
|
+
case 'max': return Math.max(...values);
|
|
1381
|
+
case 'mean': return values.reduce((a, b) => a + b, 0) / values.length;
|
|
1382
|
+
case 'count': return values.length;
|
|
1383
|
+
default: return values[values.length - 1];
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
const argText = (value: unknown) => (value === undefined || value === null ? '' : typeof value === 'object' ? JSON.stringify(value) : String(value));
|
|
1388
|
+
|
|
1389
|
+
const STATE_COLORS: Record<string, string> = { COMPLETED: 'green', RUNNING: 'blue', PENDING: 'yellow', FAILED: 'red', CANCELLED: 'gray', TIMEOUT: 'orange' };
|
|
1390
|
+
|
|
1391
|
+
/** The arguments bujang sets itself (label, pipeline, project): not the script's, left out of the argument columns */
|
|
1392
|
+
const isBujangArg = (name: string) => name.startsWith('BUJANG_') || name.startsWith('JR_');
|
|
1393
|
+
const STEP_ARG = 'BUJANG_PIPELINE_STEP';
|
|
1394
|
+
|
|
1395
|
+
/** The short unique part of a job id: its `_<8 characters>` suffix */
|
|
1396
|
+
const shortId = (id: string) => /_([0-9a-z]{8})$/i.exec(id)?.[1] ?? id;
|
|
1397
|
+
|
|
1398
|
+
/** A column filter: `>0.9`, `<=3`, `!=0`, `=64`, `1..5` (on numbers), `!text` (does not contain), else contains */
|
|
1399
|
+
const matchesFilter = (filter: string, text: string, num: number | null): boolean => {
|
|
1400
|
+
const f = filter.trim();
|
|
1401
|
+
if (!f) return true;
|
|
1402
|
+
const range = /^(-?[\d.e+-]+)\s*\.\.\s*(-?[\d.e+-]+)$/i.exec(f);
|
|
1403
|
+
if (range && Number.isFinite(Number(range[1])) && Number.isFinite(Number(range[2]))) {
|
|
1404
|
+
return num !== null && num >= Number(range[1]) && num <= Number(range[2]);
|
|
1405
|
+
}
|
|
1406
|
+
const cmp = /^(>=|<=|!=|==|=|>|<)\s*(.+)$/.exec(f);
|
|
1407
|
+
if (cmp) {
|
|
1408
|
+
const ref = Number(cmp[2]);
|
|
1409
|
+
if (Number.isFinite(ref) && num !== null) return ruleMatches(cmp[1] === '=' ? '==' : (cmp[1] as CompareRuleOp), ref, num);
|
|
1410
|
+
if (cmp[1] === '=' || cmp[1] === '==') return text.toLowerCase() === cmp[2].trim().toLowerCase();
|
|
1411
|
+
if (cmp[1] === '!=') return text.toLowerCase() !== cmp[2].trim().toLowerCase();
|
|
1412
|
+
return false;
|
|
1413
|
+
}
|
|
1414
|
+
if (f.startsWith('!')) return !text.toLowerCase().includes(f.slice(1).toLowerCase());
|
|
1415
|
+
return text.toLowerCase().includes(f.toLowerCase());
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
export const COMPARE_OPS: CompareRuleOp[] = ['<', '<=', '>', '>=', '==', '!='];
|
|
1419
|
+
export const COMPARE_COLORS: CompareRuleColor[] = ['good', 'bad', 'warn', 'info'];
|
|
1420
|
+
|
|
1421
|
+
const ruleMatches = (op: CompareRuleOp, ref: number, v: number) => {
|
|
1422
|
+
switch (op) {
|
|
1423
|
+
case '<': return v < ref;
|
|
1424
|
+
case '<=': return v <= ref;
|
|
1425
|
+
case '>': return v > ref;
|
|
1426
|
+
case '>=': return v >= ref;
|
|
1427
|
+
case '==': return v === ref;
|
|
1428
|
+
default: return v !== ref;
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
const RULE_COLORS: Record<CompareRuleColor, string> = {
|
|
1433
|
+
good: 'var(--color-status-completed)',
|
|
1434
|
+
bad: 'var(--color-status-failed)',
|
|
1435
|
+
warn: 'var(--color-status-pending)',
|
|
1436
|
+
info: 'var(--color-status-running)',
|
|
1437
|
+
};
|
|
1438
|
+
const tint = (color: string, percent = 30) => `color-mix(in srgb, ${color} ${percent}%, transparent)`;
|
|
1439
|
+
|
|
1440
|
+
/** The background of a metric cell: the first rule it matches, else its place on the column's color scale */
|
|
1441
|
+
const cellFormat = (m: CompareMetric, v: number | null, range: { min: number; max: number } | null): { bg?: string; best?: boolean } => {
|
|
1442
|
+
if (v === null) return {};
|
|
1443
|
+
const rule = (m.rules ?? []).find((r) => ruleMatches(r.op, r.value, v));
|
|
1444
|
+
if (rule) return { bg: tint(RULE_COLORS[rule.color]) };
|
|
1445
|
+
if (!m.scale || !range) return {};
|
|
1446
|
+
const best = m.scale === 'higher' ? v === range.max : v === range.min;
|
|
1447
|
+
if (range.max === range.min) return { best };
|
|
1448
|
+
const t = (v - range.min) / (range.max - range.min);
|
|
1449
|
+
const good = Math.round(100 * (m.scale === 'higher' ? t : 1 - t));
|
|
1450
|
+
return { bg: tint(`color-mix(in srgb, ${RULE_COLORS.good} ${good}%, ${RULE_COLORS.bad})`, 35), best };
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
interface CompareRow {
|
|
1454
|
+
key: string;
|
|
1455
|
+
job: CollectionJob | null;
|
|
1456
|
+
stats: (number | null)[];
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/** A column of the compare table: its text (filter, sort), its number (filter, sort), its cell */
|
|
1460
|
+
interface CompareColumn {
|
|
1461
|
+
key: string;
|
|
1462
|
+
label: React.ReactNode;
|
|
1463
|
+
help: string;
|
|
1464
|
+
end?: boolean;
|
|
1465
|
+
text: (r: CompareRow) => string;
|
|
1466
|
+
num: (r: CompareRow) => number | null;
|
|
1467
|
+
cell: (r: CompareRow) => React.ReactNode;
|
|
1468
|
+
cellProps?: (r: CompareRow) => Record<string, unknown>;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
const numberOf = (text: string): number | null => {
|
|
1472
|
+
const n = Number(text);
|
|
1473
|
+
return text !== '' && Number.isFinite(n) ? n : null;
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
/**
|
|
1477
|
+
* A row per job (`_job` of the rows; per file in a job's Overview): its short id, label, state and pipeline
|
|
1478
|
+
* step, the arguments of its script, then a statistic of each metric (the last loss, the best one, ...)
|
|
1479
|
+
* with its conditional formatting. Sorted by a click on a column, filtered by the inputs under the header.
|
|
1480
|
+
*/
|
|
1481
|
+
export const ComparePanel: React.FC<PanelProps<'compare'>> = ({ jrJobId, files, panel, actions }) => {
|
|
1482
|
+
const paths = useBujangPaths();
|
|
1483
|
+
const jobs = useContext(CollectionJobs);
|
|
1484
|
+
const metrics = useMemo(() => panel.metrics ?? [], [panel.metrics]);
|
|
1485
|
+
const queryFiles = useQueryFiles(files);
|
|
1486
|
+
const [open, setOpen] = useEditor(actions.onEditor);
|
|
1487
|
+
const events = useMemo(() => [...new Set(metrics.map((m) => m.event))], [metrics]);
|
|
1488
|
+
const results = useQueries({
|
|
1489
|
+
queries: events.map((event) => {
|
|
1490
|
+
const query = {
|
|
1491
|
+
files: queryFiles,
|
|
1492
|
+
events: event ? [event] : undefined,
|
|
1493
|
+
fields: [...new Set(metrics.filter((m) => m.event === event).map((m) => m.field))],
|
|
1494
|
+
limit: ROW_LIMIT,
|
|
1495
|
+
};
|
|
1496
|
+
return {
|
|
1497
|
+
queryKey: ['bujang-job-data-rows', jrJobId, query],
|
|
1498
|
+
queryFn: () => getJobDataRows(jrJobId, query),
|
|
1499
|
+
staleTime: 30_000,
|
|
1500
|
+
};
|
|
1501
|
+
}),
|
|
1502
|
+
});
|
|
1503
|
+
const error = results.find((r) => r.error)?.error as ApiError | undefined;
|
|
1504
|
+
const truncated = results.some((r) => (r.data?.length ?? 0) >= ROW_LIMIT);
|
|
1505
|
+
|
|
1506
|
+
// per job (or file), per metric: the values in the order of the rows
|
|
1507
|
+
const keyOf = (row: Record<string, unknown>) => String(row._job ?? row._file ?? '');
|
|
1508
|
+
const values = useMemo(() => {
|
|
1509
|
+
const out = new Map<string, number[][]>();
|
|
1510
|
+
metrics.forEach((m, i) => {
|
|
1511
|
+
const rows = results[events.indexOf(m.event)]?.data ?? [];
|
|
1512
|
+
for (const row of rows) {
|
|
1513
|
+
const v = row[m.field];
|
|
1514
|
+
if (typeof v !== 'number' || !Number.isFinite(v)) continue;
|
|
1515
|
+
const key = keyOf(row);
|
|
1516
|
+
if (!out.has(key)) out.set(key, metrics.map(() => []));
|
|
1517
|
+
out.get(key)![i].push(v);
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1520
|
+
return out;
|
|
1521
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1522
|
+
}, [metrics, events, ...results.map((r) => r.data)]);
|
|
1523
|
+
|
|
1524
|
+
// the rows: the jobs of the collection, else what the data has
|
|
1525
|
+
const rows = useMemo((): CompareRow[] => {
|
|
1526
|
+
const list: { key: string; job: CollectionJob | null }[] = jobs
|
|
1527
|
+
? jobs.map((j) => ({ key: j.jr_job_id, job: j }))
|
|
1528
|
+
: [...values.keys()].sort().map((key) => ({ key, job: null }));
|
|
1529
|
+
return list.map(({ key, job }) => ({
|
|
1530
|
+
key,
|
|
1531
|
+
job,
|
|
1532
|
+
stats: metrics.map((m, i) => compareStat(values.get(key)?.[i] ?? [], m.stat ?? 'last')),
|
|
1533
|
+
}));
|
|
1534
|
+
}, [jobs, values, metrics]);
|
|
1535
|
+
|
|
1536
|
+
// the arguments shown: the panel's, else the script's ones that differ between the jobs
|
|
1537
|
+
const argNames = useMemo(() => {
|
|
1538
|
+
if (panel.args?.length) return panel.args;
|
|
1539
|
+
if (!jobs?.length) return [];
|
|
1540
|
+
const names = [...new Set(jobs.flatMap((j) => Object.keys(j.args || {})))].filter((n) => !isBujangArg(n)).sort();
|
|
1541
|
+
const differ = names.filter((n) => new Set(jobs.map((j) => argText(j.args?.[n]))).size > 1);
|
|
1542
|
+
return jobs.length > 1 ? differ : names;
|
|
1543
|
+
}, [panel.args, jobs]);
|
|
1544
|
+
const hasSteps = useMemo(() => !!jobs?.some((j) => j.args?.[STEP_ARG] !== undefined), [jobs]);
|
|
1545
|
+
|
|
1546
|
+
// the color scale of each metric: its range over the rows
|
|
1547
|
+
const ranges = useMemo(() => metrics.map((m, i) => {
|
|
1548
|
+
if (!m.scale) return null;
|
|
1549
|
+
const vs = rows.map((r) => r.stats[i]).filter((v): v is number => v !== null);
|
|
1550
|
+
return vs.length ? { min: Math.min(...vs), max: Math.max(...vs) } : null;
|
|
1551
|
+
}), [metrics, rows]);
|
|
1552
|
+
|
|
1553
|
+
const columns = useMemo((): CompareColumn[] => {
|
|
1554
|
+
const id = (r: CompareRow) => (r.job ? shortId(r.job.jr_job_id) : r.key);
|
|
1555
|
+
const cols: CompareColumn[] = [{
|
|
1556
|
+
key: 'id',
|
|
1557
|
+
label: jobs ? 'id' : 'file',
|
|
1558
|
+
help: jobs ? 'the unique part of the job id' : 'the data file',
|
|
1559
|
+
text: id,
|
|
1560
|
+
num: () => null,
|
|
1561
|
+
cell: (r) => (r.job
|
|
1562
|
+
? <Link to={paths.jobLogs(NO_JOB_ID, r.job.jr_job_id)} title={r.job.jr_job_id}><Text as="span" fontFamily="mono">{id(r)}</Text></Link>
|
|
1563
|
+
: <Text as="span" fontFamily="mono">{r.key}</Text>),
|
|
1564
|
+
}];
|
|
1565
|
+
if (jobs) {
|
|
1566
|
+
cols.push({
|
|
1567
|
+
key: 'job',
|
|
1568
|
+
label: 'job',
|
|
1569
|
+
help: 'its label (BUJANG_JOB_LABEL), else its id',
|
|
1570
|
+
text: (r) => r.job?.label || r.key,
|
|
1571
|
+
num: () => null,
|
|
1572
|
+
cell: (r) => <Text as="span" title={r.job?.jr_job_id}>{r.job?.label || r.key}</Text>,
|
|
1573
|
+
}, {
|
|
1574
|
+
key: 'state',
|
|
1575
|
+
label: 'state',
|
|
1576
|
+
help: 'its Slurm state',
|
|
1577
|
+
text: (r) => r.job?.state ?? '',
|
|
1578
|
+
num: () => null,
|
|
1579
|
+
cell: (r) => <Badge size="xs" colorPalette={STATE_COLORS[r.job?.state ?? ''] ?? 'gray'}>{r.job?.state}</Badge>,
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
if (hasSteps) {
|
|
1583
|
+
const step = (r: CompareRow) => argText(r.job?.args?.[STEP_ARG]);
|
|
1584
|
+
cols.push({
|
|
1585
|
+
key: 'step',
|
|
1586
|
+
label: 'step',
|
|
1587
|
+
help: `its pipeline step (${STEP_ARG})`,
|
|
1588
|
+
text: step,
|
|
1589
|
+
num: () => null,
|
|
1590
|
+
cell: (r) => <Text as="span" fontFamily="mono">{step(r)}</Text>,
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
for (const n of argNames) {
|
|
1594
|
+
const text = (r: CompareRow) => argText(r.job?.args?.[n]);
|
|
1595
|
+
cols.push({
|
|
1596
|
+
key: `a:${n}`,
|
|
1597
|
+
label: <Text as="span" fontFamily="mono">{n}</Text>,
|
|
1598
|
+
help: `argument ${n}`,
|
|
1599
|
+
text,
|
|
1600
|
+
num: (r) => numberOf(text(r)),
|
|
1601
|
+
cell: (r) => <Text as="span" fontFamily="mono">{text(r)}</Text>,
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
metrics.forEach((m, i) => {
|
|
1605
|
+
const value = (r: CompareRow) => r.stats[i];
|
|
1606
|
+
cols.push({
|
|
1607
|
+
key: `m:${i}`,
|
|
1608
|
+
label: m.title || `${m.stat ?? 'last'} ${m.field}`,
|
|
1609
|
+
help: `${m.stat ?? 'last'} ${m.field} of the ${m.event || 'records'} rows`,
|
|
1610
|
+
end: true,
|
|
1611
|
+
text: (r) => (value(r) === null ? '' : formatStat(value(r)!)),
|
|
1612
|
+
num: value,
|
|
1613
|
+
cell: (r) => {
|
|
1614
|
+
const v = value(r);
|
|
1615
|
+
const { best } = cellFormat(m, v, ranges[i]);
|
|
1616
|
+
return <Text as="span" fontWeight={best ? 'bold' : undefined}>{v === null ? '—' : formatStat(v)}</Text>;
|
|
1617
|
+
},
|
|
1618
|
+
cellProps: (r) => {
|
|
1619
|
+
const { bg } = cellFormat(m, value(r), ranges[i]);
|
|
1620
|
+
return bg ? { style: { background: bg } } : {};
|
|
1621
|
+
},
|
|
1622
|
+
});
|
|
1623
|
+
});
|
|
1624
|
+
return cols;
|
|
1625
|
+
}, [jobs, hasSteps, argNames, metrics, ranges, paths]);
|
|
1626
|
+
|
|
1627
|
+
const [filters, setFilters] = useState<Record<string, string>>({});
|
|
1628
|
+
const [showFilters, setShowFilters] = useState(true);
|
|
1629
|
+
const filtering = Object.values(filters).some((f) => f.trim());
|
|
1630
|
+
const filtered = useMemo(() => rows.filter((r) => columns.every((c) => matchesFilter(filters[c.key] ?? '', c.text(r), c.num(r)))), [rows, columns, filters]);
|
|
1631
|
+
|
|
1632
|
+
const [sort, setSort] = useState<{ col: string; desc: boolean } | null>(null);
|
|
1633
|
+
const sorted = useMemo(() => {
|
|
1634
|
+
const col = sort && columns.find((c) => c.key === sort.col);
|
|
1635
|
+
if (!sort || !col) return filtered;
|
|
1636
|
+
const value = (r: CompareRow): string | number => col.num(r) ?? col.text(r);
|
|
1637
|
+
return [...filtered].sort((a, b) => {
|
|
1638
|
+
const x = value(a);
|
|
1639
|
+
const y = value(b);
|
|
1640
|
+
if (x === '') return 1;
|
|
1641
|
+
if (y === '') return -1;
|
|
1642
|
+
const c = typeof x === 'number' && typeof y === 'number' ? x - y : String(x).localeCompare(String(y), undefined, { numeric: true });
|
|
1643
|
+
return sort.desc ? -c : c;
|
|
1644
|
+
});
|
|
1645
|
+
}, [filtered, sort, columns]);
|
|
1646
|
+
|
|
1647
|
+
return (
|
|
1648
|
+
<PanelFrame
|
|
1649
|
+
title={panel.title || 'Jobs'}
|
|
1650
|
+
kind="compare"
|
|
1651
|
+
actions={actions}
|
|
1652
|
+
onSettings={() => setOpen(true)}
|
|
1653
|
+
settingsTitle="Pick the metrics, the arguments and their formatting"
|
|
1654
|
+
info={<>
|
|
1655
|
+
{results.some((r) => r.isFetching) && <Spinner size="xs" />}
|
|
1656
|
+
<Text>{filtering ? `${filtered.length} of ` : ''}{rows.length} {jobs ? 'jobs' : 'files'}</Text>
|
|
1657
|
+
{truncated && <Text>first {ROW_LIMIT} rows only</Text>}
|
|
1658
|
+
<Button size="2xs" variant={showFilters ? 'subtle' : 'ghost'} onClick={() => setShowFilters((s) => !s)}
|
|
1659
|
+
title={showFilters ? 'Hide the filters' : 'Filter the rows'} aria-pressed={showFilters}>
|
|
1660
|
+
<LuFilter />
|
|
1661
|
+
</Button>
|
|
1662
|
+
{filtering && (
|
|
1663
|
+
<Button size="2xs" variant="ghost" onClick={() => setFilters({})} title="Clear the filters"><LuFilterX /></Button>
|
|
1664
|
+
)}
|
|
1665
|
+
</>}
|
|
1666
|
+
>
|
|
1667
|
+
{error && (
|
|
1668
|
+
<Alert.Root status="error" mb={2}><Alert.Indicator /><Alert.Description>{error.message}</Alert.Description></Alert.Root>
|
|
1669
|
+
)}
|
|
1670
|
+
<Box overflowX="auto" maxH="560px" overflowY="auto">
|
|
1671
|
+
<Table.Root size="sm" variant="line" stickyHeader>
|
|
1672
|
+
<Table.Header>
|
|
1673
|
+
<Table.Row>
|
|
1674
|
+
{columns.map((c) => (
|
|
1675
|
+
<Table.ColumnHeader
|
|
1676
|
+
key={c.key}
|
|
1677
|
+
textAlign={c.end ? 'end' : undefined}
|
|
1678
|
+
cursor="pointer"
|
|
1679
|
+
title={`${c.help}: click to sort`}
|
|
1680
|
+
onClick={() => setSort((s) => (s?.col === c.key ? (s.desc ? null : { col: c.key, desc: true }) : { col: c.key, desc: false }))}
|
|
1681
|
+
whiteSpace="nowrap"
|
|
1682
|
+
>
|
|
1683
|
+
{c.label}{sort?.col === c.key ? (sort.desc ? ' ↓' : ' ↑') : ''}
|
|
1684
|
+
</Table.ColumnHeader>
|
|
1685
|
+
))}
|
|
1686
|
+
</Table.Row>
|
|
1687
|
+
{showFilters && (
|
|
1688
|
+
<Table.Row>
|
|
1689
|
+
{columns.map((c) => (
|
|
1690
|
+
<Table.ColumnHeader key={c.key} py={1} px={1} fontWeight="normal">
|
|
1691
|
+
<Input
|
|
1692
|
+
size="2xs"
|
|
1693
|
+
minW="60px"
|
|
1694
|
+
fontFamily="mono"
|
|
1695
|
+
textAlign={c.end ? 'end' : undefined}
|
|
1696
|
+
value={filters[c.key] ?? ''}
|
|
1697
|
+
placeholder={c.end || c.key.startsWith('a:') ? '>0, 1..5' : 'filter'}
|
|
1698
|
+
title="contains a text (!text: does not); on numbers: >0.9, <=3, =64, !=0, 1..5"
|
|
1699
|
+
onChange={(e) => setFilters((f) => ({ ...f, [c.key]: e.target.value }))}
|
|
1700
|
+
/>
|
|
1701
|
+
</Table.ColumnHeader>
|
|
1702
|
+
))}
|
|
1703
|
+
</Table.Row>
|
|
1704
|
+
)}
|
|
1705
|
+
</Table.Header>
|
|
1706
|
+
<Table.Body>
|
|
1707
|
+
{sorted.map((r) => (
|
|
1708
|
+
<Table.Row key={r.key}>
|
|
1709
|
+
{columns.map((c) => (
|
|
1710
|
+
<Table.Cell
|
|
1711
|
+
key={c.key}
|
|
1712
|
+
fontSize="xs"
|
|
1713
|
+
whiteSpace="nowrap"
|
|
1714
|
+
textAlign={c.end ? 'end' : undefined}
|
|
1715
|
+
fontFamily={c.end ? 'mono' : undefined}
|
|
1716
|
+
{...(c.cellProps?.(r) ?? {})}
|
|
1717
|
+
>
|
|
1718
|
+
{c.cell(r)}
|
|
1719
|
+
</Table.Cell>
|
|
1720
|
+
))}
|
|
1721
|
+
</Table.Row>
|
|
1722
|
+
))}
|
|
1723
|
+
</Table.Body>
|
|
1724
|
+
</Table.Root>
|
|
1725
|
+
</Box>
|
|
1726
|
+
{!metrics.length && (
|
|
1727
|
+
<HStack gap={3} mt={2}>
|
|
1728
|
+
<Text fontSize="sm" color="var(--color-text-muted)">No metric picked.</Text>
|
|
1729
|
+
<Button size="xs" variant="outline" onClick={() => setOpen(true)}><LuSettings /> Configure</Button>
|
|
1730
|
+
</HStack>
|
|
1731
|
+
)}
|
|
1732
|
+
{open && (
|
|
1733
|
+
<CompareEditor
|
|
1734
|
+
files={files}
|
|
1735
|
+
panel={panel}
|
|
1736
|
+
onClose={() => setOpen(false)}
|
|
1737
|
+
onApply={(next) => { setOpen(false); actions.onChange(next); }}
|
|
1738
|
+
/>
|
|
1739
|
+
)}
|
|
1740
|
+
</PanelFrame>
|
|
1741
|
+
);
|
|
1742
|
+
};
|
|
1743
|
+
|
|
1744
|
+
/** A metric of the editor: its rules' values are the text typed */
|
|
1745
|
+
type EditMetric = Omit<CompareMetric, 'rules'> & { rules: { op: CompareRuleOp; value: string; color: CompareRuleColor }[] };
|
|
1746
|
+
|
|
1747
|
+
/** The metrics, arguments and conditional formatting of a compare block (its gear) */
|
|
1748
|
+
const CompareEditor: React.FC<{
|
|
1749
|
+
files: JobData['files'];
|
|
1750
|
+
panel: Extract<OverviewBlock, { kind: 'compare' }>;
|
|
1751
|
+
onClose: () => void;
|
|
1752
|
+
onApply: (panel: OverviewBlock) => void;
|
|
1753
|
+
}> = ({ files, panel, onClose, onApply }) => {
|
|
1754
|
+
const [title, setTitle] = useState(panel.title ?? '');
|
|
1755
|
+
const [metrics, setMetrics] = useState<EditMetric[]>(
|
|
1756
|
+
(panel.metrics ?? []).map((m) => ({ ...m, rules: (m.rules ?? []).map((r) => ({ ...r, value: String(r.value) })) })),
|
|
1757
|
+
);
|
|
1758
|
+
const [args, setArgs] = useState((panel.args ?? []).join(', '));
|
|
1759
|
+
const events = useMemo(
|
|
1760
|
+
() => [...new Set(files.flatMap((f) => (f.events || []).filter((e) => e.role === 'metric').map((e) => e.event)))],
|
|
1761
|
+
[files],
|
|
1762
|
+
);
|
|
1763
|
+
const numberFields = (event: string) => mergeFields(files, event).filter((f) => f.type === 'number').map((f) => f.name);
|
|
1764
|
+
const set = (i: number, patch: Partial<EditMetric>) => setMetrics((list) => list.map((m, k) => (k === i ? { ...m, ...patch } : m)));
|
|
1765
|
+
const setRule = (i: number, j: number, patch: Partial<EditMetric['rules'][number]>) =>
|
|
1766
|
+
set(i, { rules: metrics[i].rules.map((r, k) => (k === j ? { ...r, ...patch } : r)) });
|
|
1767
|
+
const add = () => {
|
|
1768
|
+
const event = events[0] ?? '';
|
|
1769
|
+
setMetrics((list) => [...list, { event, field: numberFields(event)[0] ?? '', stat: 'last', rules: [] }]);
|
|
1770
|
+
};
|
|
1771
|
+
const apply = () => {
|
|
1772
|
+
const names = args.split(',').map((a) => a.trim()).filter(Boolean);
|
|
1773
|
+
onApply({
|
|
1774
|
+
kind: 'compare',
|
|
1775
|
+
...(title ? { title } : {}),
|
|
1776
|
+
metrics: metrics.filter((m) => m.field).map(({ title: t, scale, rules, ...rest }): CompareMetric => {
|
|
1777
|
+
const kept = rules
|
|
1778
|
+
.filter((r) => r.value.trim() !== '' && Number.isFinite(Number(r.value)))
|
|
1779
|
+
.map((r) => ({ ...r, value: Number(r.value) }));
|
|
1780
|
+
return { ...rest, ...(t ? { title: t } : {}), ...(scale ? { scale } : {}), ...(kept.length ? { rules: kept } : {}) };
|
|
1781
|
+
}),
|
|
1782
|
+
...(names.length ? { args: names } : {}),
|
|
1783
|
+
});
|
|
1784
|
+
};
|
|
1785
|
+
const select = (value: string, options: string[], onChange: (v: string) => void, w = '150px', label?: (o: string) => string) => (
|
|
1786
|
+
<NativeSelect.Root size="xs" w={w}>
|
|
1787
|
+
<NativeSelect.Field value={value} onChange={(e) => onChange(e.target.value)}>
|
|
1788
|
+
{[...new Set([value, ...options])].map((o) => <option key={o} value={o}>{label ? label(o) : o || '(records)'}</option>)}
|
|
1789
|
+
</NativeSelect.Field>
|
|
1790
|
+
</NativeSelect.Root>
|
|
1791
|
+
);
|
|
1792
|
+
const scaleLabel = (o: string) => (o === 'higher' ? 'scale: higher is better' : o === 'lower' ? 'scale: lower is better' : 'no color scale');
|
|
1793
|
+
return (
|
|
1794
|
+
<Dialog.Root open onOpenChange={(e) => !e.open && onClose()} size="xl">
|
|
1795
|
+
<Dialog.Backdrop />
|
|
1796
|
+
<Dialog.Positioner>
|
|
1797
|
+
<Dialog.Content bg="var(--color-bg-card)" color="var(--color-text)">
|
|
1798
|
+
<Dialog.Header><Dialog.Title>Compare the jobs</Dialog.Title></Dialog.Header>
|
|
1799
|
+
<Dialog.Body>
|
|
1800
|
+
<VStack align="stretch" gap={3} fontSize="sm">
|
|
1801
|
+
<HStack gap={2}>
|
|
1802
|
+
<Text w="90px">Title</Text>
|
|
1803
|
+
<Input size="xs" value={title} placeholder="Jobs" onChange={(e) => setTitle(e.target.value)} />
|
|
1804
|
+
</HStack>
|
|
1805
|
+
<HStack gap={2} align="start">
|
|
1806
|
+
<Text w="90px">Arguments</Text>
|
|
1807
|
+
<VStack align="stretch" flex={1} gap={1}>
|
|
1808
|
+
<Input size="xs" fontFamily="mono" value={args} placeholder="the ones that differ between the jobs"
|
|
1809
|
+
onChange={(e) => setArgs(e.target.value)} />
|
|
1810
|
+
<Text fontSize="xs" color="var(--color-text-muted)">
|
|
1811
|
+
comma separated names (LR, BATCH_SIZE); empty: the script's ones that differ (the BUJANG_* ones are
|
|
1812
|
+
the id, job and step columns)
|
|
1813
|
+
</Text>
|
|
1814
|
+
</VStack>
|
|
1815
|
+
</HStack>
|
|
1816
|
+
<Text fontWeight="semibold">Metrics</Text>
|
|
1817
|
+
{metrics.map((m, i) => (
|
|
1818
|
+
<VStack key={i} align="stretch" gap={1} p={2} border="1px solid" borderColor="var(--color-border)" borderRadius="md">
|
|
1819
|
+
<HStack gap={2} wrap="wrap">
|
|
1820
|
+
{select(m.stat ?? 'last', COMPARE_STATS, (v) => set(i, { stat: v as CompareStat }), '90px')}
|
|
1821
|
+
{select(m.field, numberFields(m.event), (v) => set(i, { field: v }))}
|
|
1822
|
+
<Text color="var(--color-text-muted)">of</Text>
|
|
1823
|
+
{select(m.event, events, (v) => set(i, { event: v, field: numberFields(v)[0] ?? '' }))}
|
|
1824
|
+
<Input size="xs" w="130px" placeholder="column title" value={m.title ?? ''} onChange={(e) => set(i, { title: e.target.value })} />
|
|
1825
|
+
<Button size="2xs" variant="ghost" onClick={() => setMetrics((list) => without(list, i))} title="Remove"><LuX /></Button>
|
|
1826
|
+
</HStack>
|
|
1827
|
+
<HStack gap={2} wrap="wrap">
|
|
1828
|
+
<Text fontSize="xs" color="var(--color-text-muted)" w="70px">Format</Text>
|
|
1829
|
+
{select(m.scale ?? '', ['', 'higher', 'lower'], (v) => set(i, { scale: (v || undefined) as CompareScale | undefined }), '190px', scaleLabel)}
|
|
1830
|
+
<Button size="2xs" variant="outline" disabled={m.rules.length >= 10}
|
|
1831
|
+
onClick={() => set(i, { rules: [...m.rules, { op: '>', value: '', color: 'good' }] })}>
|
|
1832
|
+
<LuPlus /> Rule
|
|
1833
|
+
</Button>
|
|
1834
|
+
</HStack>
|
|
1835
|
+
{m.rules.map((r, j) => (
|
|
1836
|
+
<HStack key={j} gap={2} pl="78px">
|
|
1837
|
+
<Text fontSize="xs" color="var(--color-text-muted)">value</Text>
|
|
1838
|
+
{select(r.op, COMPARE_OPS, (v) => setRule(i, j, { op: v as CompareRuleOp }), '70px')}
|
|
1839
|
+
<Input size="xs" w="100px" fontFamily="mono" value={r.value} placeholder="number"
|
|
1840
|
+
onChange={(e) => setRule(i, j, { value: e.target.value })} />
|
|
1841
|
+
{select(r.color, COMPARE_COLORS, (v) => setRule(i, j, { color: v as CompareRuleColor }), '90px')}
|
|
1842
|
+
<Box w="14px" h="14px" borderRadius="sm" style={{ background: tint(RULE_COLORS[r.color], 60) }} />
|
|
1843
|
+
<Button size="2xs" variant="ghost" title="Remove the rule"
|
|
1844
|
+
onClick={() => set(i, { rules: without(m.rules, j) })}><LuX /></Button>
|
|
1845
|
+
</HStack>
|
|
1846
|
+
))}
|
|
1847
|
+
</VStack>
|
|
1848
|
+
))}
|
|
1849
|
+
<Button size="xs" variant="outline" alignSelf="start" onClick={add} disabled={!events.length}><LuPlus /> Metric</Button>
|
|
1850
|
+
<Text fontSize="xs" color="var(--color-text-muted)">
|
|
1851
|
+
The first rule a value matches colors its cell; else the color scale does, from red to green (the best value in bold).
|
|
1852
|
+
</Text>
|
|
1853
|
+
</VStack>
|
|
1854
|
+
</Dialog.Body>
|
|
1855
|
+
<Dialog.Footer>
|
|
1856
|
+
<Button size="sm" variant="ghost" onClick={onClose}>Cancel</Button>
|
|
1857
|
+
<Button size="sm" colorPalette="blue" onClick={apply}>Apply</Button>
|
|
1858
|
+
</Dialog.Footer>
|
|
1859
|
+
</Dialog.Content>
|
|
1860
|
+
</Dialog.Positioner>
|
|
1861
|
+
</Dialog.Root>
|
|
1862
|
+
);
|
|
1863
|
+
};
|