-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.server.ts
95 lines (87 loc) · 2.52 KB
/
index.server.ts
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
import type { ICatalog } from "@i-vresse/wb-core/dist/types";
import easy from "./haddock3.easy.json?raw";
import expert from "./haddock3.expert.json?raw";
import guru from "./haddock3.guru.json?raw";
import type { ExpertiseLevel } from "~/drizzle/schema.server";
import { prepareCatalog } from "@i-vresse/wb-core/dist/catalog.js";
// Load catalogs during startup
const catalogs = loadCatalogs();
export function getCatalog(level: ExpertiseLevel) {
if (!(level in catalogs)) {
throw new Error(`No catalog found for level ${level}`);
}
return catalogs[level];
}
function loadCatalog(catalog: ICatalog) {
catalog.examples = {};
return hideExecutionParameters(alwaysPlotMatrix(prepareCatalog(catalog)));
}
function loadCatalogs() {
return {
easy: loadCatalog(JSON.parse(easy) as unknown as ICatalog),
expert: loadCatalog(JSON.parse(expert) as unknown as ICatalog),
guru: loadCatalog(JSON.parse(guru) as unknown as ICatalog),
} as const;
}
function alwaysPlotMatrix(catalog: ICatalog) {
for (const nodes of Object.values(catalog.nodes)) {
if (
nodes.schema.properties &&
nodes.schema.properties.plot_matrix &&
typeof nodes.schema.properties.plot_matrix === "object"
) {
nodes.schema.properties.plot_matrix.default = true;
}
}
return catalog;
}
function hideExecutionParameters(catalog: ICatalog) {
const executionParameters = [
"run_dir",
"mode",
"ncores",
"max_cpus",
"batch_type",
"queue",
"queue_limit",
"concat",
"cns_exec",
"self_contained",
// Not really execution parameters, but we want to hide them as well
"postprocess",
"clean",
"offline",
"debug",
];
const globalProps = catalog.global.schema.properties!;
for (const param of executionParameters) {
const prop = globalProps[param];
if (typeof prop === "boolean" || prop === undefined || prop === null) {
continue;
}
prop.description = undefined;
}
const uiSchema = Object.fromEntries(
executionParameters.map((param) => [
param,
{
"ui:widget": "hidden",
},
]),
);
catalog.global.uiSchema = {
...catalog.global.uiSchema,
...uiSchema,
};
return catalog;
}
export function getCatalogForBuilder(catalogLevel: ExpertiseLevel) {
const catalog = structuredClone(getCatalog(catalogLevel));
// Make run_dir optional
if (catalog.global.schema.required) {
catalog.global.schema.required = catalog.global.schema.required?.filter(
(prop) => prop !== "run_dir",
);
}
return catalog;
}