-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTables.tsx
More file actions
92 lines (87 loc) · 2.86 KB
/
Copy pathTables.tsx
File metadata and controls
92 lines (87 loc) · 2.86 KB
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
import { ExperimentResult } from "@/dto/ExperimentResult";
import { Unit } from "@/contexts/SettingsContext";
export function buildLabResultsTableData(labResults: ExperimentResult[], temperatureUnit?: Unit) {
const initialPrefix = "in-";
const finalPrefix = "out-";
const initialConcHeaders = Array.from(
new Set(labResults.flatMap((entry) => [...Object.keys(entry.initialConcentrations)]))
);
const finalConcHeaders = Array.from(
new Set(labResults.flatMap((entry) => [...Object.keys(entry.finalConcentrations)]))
);
const columns = [
{
columns: [
{
header: "Experiment",
id: "name",
accessorKey: "name",
size: 200,
},
{
header: "Time",
id: "time",
accessorKey: "time",
size: 65,
},
{
header: `Temperature (${temperatureUnit?.unit ?? "°C"})`,
id: "temperature",
accessorKey: "temperature",
size: 475,
},
{
header: "Pressure",
id: "pressure",
accessorKey: "pressure",
size: 65,
},
],
header: "Meta data",
},
{
columns: initialConcHeaders.map((header) => ({
accessorKey: initialPrefix + header,
header: header,
id: initialPrefix + header,
size: 65,
})),
header: "Input Concentrations",
},
{
columns: finalConcHeaders.map((header) => ({
accessorKey: finalPrefix + header,
header: header,
id: finalPrefix + header,
size: 65,
})),
header: "Output Concentrations",
},
];
const rows = labResults.map((entry) => ({
id: entry.name,
name: entry.name,
time: String(entry.time),
temperature:
entry.temperature === null
? null
: temperatureUnit?.unit === "°C"
? entry.temperature
: entry.temperature - 273,
pressure: entry.pressure,
...Object.fromEntries(
Object.entries(entry.initialConcentrations).map(([key, value]) => [
initialPrefix + key,
+Number(value).toPrecision(3),
])
),
...Object.fromEntries(
Object.entries(entry.finalConcentrations).map(([key, value]) => [
finalPrefix + key,
+Number(value).toPrecision(3),
])
),
meta: {},
}));
return { columns, rows };
}