Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/src/components/LabResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExperimentResult } from "@/dto/ExperimentResult";
import { Button, EdsProvider, Typography } from "@equinor/eds-core-react";
import { EdsDataGrid, Row } from "@equinor/eds-data-grid-react";
import { buildLabResultsTableData } from "@/functions/Tables";
import { useSettings } from "@/contexts/SettingsContext";

interface LabResultsTableProps {
labResults: ExperimentResult[];
Expand All @@ -15,7 +16,8 @@ const LabResultsTable: React.FC<LabResultsTableProps> = ({
selectedExperiments,
setSelectedExperiments,
}) => {
const { columns, rows } = buildLabResultsTableData(labResults);
const { temperature } = useSettings();
const { columns, rows } = buildLabResultsTableData(labResults, temperature);

const handleRowClick = (
row: Row<{
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/functions/Tables.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ExperimentResult } from "@/dto/ExperimentResult";
import { Unit } from "@/contexts/SettingsContext";

export function buildLabResultsTableData(labResults: ExperimentResult[]) {
export function buildLabResultsTableData(labResults: ExperimentResult[], temperatureUnit?: Unit) {
const initialPrefix = "in-";
const finalPrefix = "out-";

Expand All @@ -27,7 +28,7 @@ export function buildLabResultsTableData(labResults: ExperimentResult[]) {
size: 65,
},
{
header: "Temperature (°C)",
header: `Temperature (${temperatureUnit?.unit ?? "°C"})`,
id: "temperature",
accessorKey: "temperature",
size: 475,
Expand Down Expand Up @@ -65,7 +66,12 @@ export function buildLabResultsTableData(labResults: ExperimentResult[]) {
id: entry.name,
name: entry.name,
time: String(entry.time),
temperature: entry.temperature,
temperature:
entry.temperature === null
? null
: temperatureUnit?.unit === "°C"
? entry.temperature
: entry.temperature - 273,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that the only other possibility is Kelvin. It's currently true, but would lead to weird bugs when we add a different unit. We could maybe:

  1. Make frontend <-> backend comms always be in Kelvin, including oasis data.
  2. Change it so that it's always degrees Celsius.
  3. Add a "from celsius" conversion like exists with from kelvin conversion.
  4. Delete Kelvin and temperature toggle entirely? Maybe no one uses it and we should just do degrees Celsius always.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done to comply for the model runs, would be super nice if we could use the app setting from top bar for this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that is what Harald did, I check it now. Nice

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for number 4. Lets check with users and remove if not used. And then be consistent which unit we use

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go with 4 as well, I don't think any users are using kelvin..

pressure: entry.pressure,
...Object.fromEntries(
Object.entries(entry.initialConcentrations).map(([key, value]) => [
Expand Down
3 changes: 2 additions & 1 deletion frontend/tests/functions/Tables.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect } from "vitest";
import { buildLabResultsTableData } from "@/functions/Tables";
import { Unit } from "@/contexts/SettingsContext";
import type { ExperimentResult } from "@/dto/ExperimentResult";

describe("buildLabResultsTableData", () => {
Expand All @@ -15,7 +16,7 @@ describe("buildLabResultsTableData", () => {
},
];

const { columns, rows } = buildLabResultsTableData(labResults);
const { columns, rows } = buildLabResultsTableData(labResults, new Unit("celsius", "°C"));

expect(columns[0].header).toBe("Meta data");
expect(columns[0].columns).toEqual(
Expand Down
Loading