Skip to content

Commit babc721

Browse files
committed
Add generic table and populate with reactionsteps from tocomo
1 parent ad9c096 commit babc721

4 files changed

Lines changed: 26 additions & 25 deletions

File tree

backend/src/acidwatch_api/models/datamodel.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ class TextResult(BaseModel):
4444
data: str
4545

4646

47-
AnyPanel: TypeAlias = JsonResult | TextResult | ReactionPathsResult
47+
class TableResult(BaseModel):
48+
type: Literal["table"] = "table"
49+
label: str | None = None
50+
data: Any
51+
52+
53+
AnyPanel: TypeAlias = JsonResult | TextResult | ReactionPathsResult | TableResult
4854

4955

5056
class ModelInfo(BaseModel):
@@ -63,16 +69,6 @@ class ModelInfo(BaseModel):
6369
parameters: dict[str, Any]
6470

6571

66-
class InitFinalDiff(BaseModel):
67-
initial: Dict[str, float]
68-
final: Dict[str, float]
69-
change: Dict[str, float]
70-
71-
72-
class Results(BaseModel):
73-
initfinaldiff: InitFinalDiff
74-
75-
7672
class CommonPaths(BaseModel):
7773
paths: Optional[Dict[str, Optional[str]]] = Field(default_factory=dict)
7874
k: Optional[Dict[str, Optional[str]]] = Field(default_factory=dict)
@@ -97,13 +93,6 @@ class ChartData(BaseModel):
9793
variance_minus: Dict[str, float]
9894

9995

100-
class SimulationResults(BaseModel):
101-
results: Results
102-
analysis: Optional[Analysis] = None
103-
chart_data: ChartData
104-
table_data: Optional[Any] = None
105-
106-
10796
class SimulationRequest(BaseModel):
10897
model_config = ConfigDict(
10998
alias_generator=to_camel,

backend/src/acidwatch_api/models/tocomo.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from __future__ import annotations
2-
32
from acidwatch_api.models.base import BaseAdapter, RunResult
4-
from acidwatch_api.models.datamodel import InitFinalDiff
53
from fastapi import APIRouter
6-
74
from acidwatch_api.configuration import SETTINGS
85

96
router = APIRouter()
@@ -52,7 +49,9 @@ async def run(self) -> RunResult:
5249
timeout=60.0,
5350
)
5451
res.raise_for_status()
52+
result = res.json()
5553

56-
data = InitFinalDiff.model_validate(res.json())
57-
58-
return {name.upper(): value for name, value in data.final.items()}
54+
return (
55+
{key.upper(): value for key, value in result["final"].items()},
56+
{"data": result["steps"], "label": "Reaction Steps", "type": "table"},
57+
)

frontend/src/dto/SimulationResults.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ interface ReactionPathsPanel {
1919
stats: any;
2020
}
2121

22-
export type Panel = TextPanel | JsonPanel | ReactionPathsPanel;
22+
interface TablePanel {
23+
type: "table";
24+
label?: string;
25+
data: Record<string, any>[];
26+
}
27+
28+
export type Panel = TextPanel | JsonPanel | ReactionPathsPanel | TablePanel;
2329
export interface SimulationResults {
2430
modelInput: ModelInput;
2531
finalConcentrations: { [key: string]: number };

frontend/src/pages/Results.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getSimulationResults } from "../api/api";
1010
import { MassBalanceError } from "../components/MassBalanceError";
1111
import { extractPlotData } from "../functions/Formatting";
1212
import BarChart from "../components/BarChart";
13+
import GenericTable from "../components/GenericTable";
1314

1415
interface ResultsProps {
1516
simulationResults?: SimulationResults;
@@ -28,6 +29,9 @@ function getPanelName(panel: Panel): string {
2829
case "reaction_paths":
2930
return "Reactions";
3031

32+
case "table":
33+
return panel.label ?? "Table data";
34+
3135
default:
3236
return "(Unknown panel)";
3337
}
@@ -44,6 +48,9 @@ function getPanelContent(panel: Panel): React.ReactElement {
4448
case "reaction_paths":
4549
return <Reactions commonPaths={panel.common_paths} reactions={panel.stats} />;
4650

51+
case "table":
52+
return <GenericTable data={panel.data} />;
53+
4754
default:
4855
return <Typography color="red">Unknown panel type</Typography>;
4956
}

0 commit comments

Comments
 (0)