diff --git a/backend_py/primary/primary/routers/vfp/schemas.py b/backend_py/primary/primary/routers/vfp/schemas.py index cc9d92e29..ef9b45413 100644 --- a/backend_py/primary/primary/routers/vfp/schemas.py +++ b/backend_py/primary/primary/routers/vfp/schemas.py @@ -1,43 +1,44 @@ +from enum import StrEnum +from typing import Literal + from pydantic import BaseModel from primary.services.sumo_access.vfp_types import THP, WFR, GFR, ALQ, FlowRateType, UnitType, TabType -class VfpProdTable(BaseModel): - isProdTable: bool = True +class VfpType(StrEnum): + PROD = "PROD" + INJ = "INJ" + + +class VfpTableBase(BaseModel): + vfpType: Literal[VfpType.INJ, VfpType.PROD] tableNumber: int datum: float - thpType: THP - wfrType: WFR - gfrType: GFR - alqType: ALQ flowRateType: FlowRateType unitType: UnitType tabType: TabType thpValues: list[float] - wfrValues: list[float] - gfrValues: list[float] - alqValues: list[float] flowRateValues: list[float] bhpValues: list[float] flowRateUnit: str thpUnit: str + bhpUnit: str + + +class VfpProdTable(VfpTableBase): + vfpType: Literal[VfpType.PROD] = VfpType.PROD + thpType: THP + wfrType: WFR + gfrType: GFR + alqType: ALQ + wfrValues: list[float] + gfrValues: list[float] + alqValues: list[float] wfrUnit: str gfrUnit: str alqUnit: str - bhpUnit: str -class VfpInjTable(BaseModel): - isInjTable: bool = True - tableNumber: int - datum: float - flowRateType: FlowRateType - unitType: UnitType - tabType: TabType - thpValues: list[float] - flowRateValues: list[float] - bhpValues: list[float] - flowRateUnit: str - thpUnit: str - bhpUnit: str +class VfpInjTable(VfpTableBase): + vfpType: Literal[VfpType.INJ] = VfpType.INJ diff --git a/frontend/src/api/autogen/types.gen.ts b/frontend/src/api/autogen/types.gen.ts index 770bd8fe7..7c8f31b8a 100644 --- a/frontend/src/api/autogen/types.gen.ts +++ b/frontend/src/api/autogen/types.gen.ts @@ -890,7 +890,7 @@ export type VectorStatisticSensitivityData_api = { }; export type VfpInjTable_api = { - isInjTable: boolean; + vfpType: "INJ"; tableNumber: number; datum: number; flowRateType: FlowRateType_api; @@ -905,28 +905,28 @@ export type VfpInjTable_api = { }; export type VfpProdTable_api = { - isProdTable: boolean; + vfpType: "PROD"; tableNumber: number; datum: number; - thpType: Thp_api; - wfrType: Wfr_api; - gfrType: Gfr_api; - alqType: Alq_api; flowRateType: FlowRateType_api; unitType: UnitType_api; tabType: TabType_api; thpValues: Array; - wfrValues: Array; - gfrValues: Array; - alqValues: Array; flowRateValues: Array; bhpValues: Array; flowRateUnit: string; thpUnit: string; + bhpUnit: string; + thpType: Thp_api; + wfrType: Wfr_api; + gfrType: Gfr_api; + alqType: Alq_api; + wfrValues: Array; + gfrValues: Array; + alqValues: Array; wfrUnit: string; gfrUnit: string; alqUnit: string; - bhpUnit: string; }; export enum Wfr_api { diff --git a/frontend/src/modules/Vfp/utils/vfpDataAccessor.ts b/frontend/src/modules/Vfp/utils/vfpDataAccessor.ts index cb84a5c58..70b2f7728 100644 --- a/frontend/src/modules/Vfp/utils/vfpDataAccessor.ts +++ b/frontend/src/modules/Vfp/utils/vfpDataAccessor.ts @@ -1,6 +1,6 @@ import { Alq_api, FlowRateType_api, Gfr_api, VfpInjTable_api, VfpProdTable_api, Wfr_api } from "@api"; -import { isProdTable } from "./vfpTableClassifier"; +import { isInjTable, isProdTable } from "./vfpTableClassifier"; import { VfpParam, VfpType } from "../types"; @@ -16,7 +16,7 @@ export class VfpDataAccessor { } isInjTable(): boolean { - return !isProdTable(this._vfpTable); + return isInjTable(this._vfpTable); } getTableNumber(): number { @@ -65,7 +65,7 @@ export class VfpDataAccessor { if (vfpParam === VfpParam.THP) { return this._vfpTable.thpValues; } - if ("isProdTable" in this._vfpTable) { + if (isProdTable(this._vfpTable)) { if (vfpParam === VfpParam.WFR) { return this._vfpTable.wfrValues; } diff --git a/frontend/src/modules/Vfp/utils/vfpTableClassifier.ts b/frontend/src/modules/Vfp/utils/vfpTableClassifier.ts index b13518db1..b44fe3883 100644 --- a/frontend/src/modules/Vfp/utils/vfpTableClassifier.ts +++ b/frontend/src/modules/Vfp/utils/vfpTableClassifier.ts @@ -1,5 +1,9 @@ -import { VfpProdTable_api, VfpInjTable_api } from "@api"; +import { VfpInjTable_api, VfpProdTable_api } from "@api"; export function isProdTable(vfpTable: VfpProdTable_api | VfpInjTable_api): vfpTable is VfpProdTable_api { - return "isProdTable" in vfpTable -} \ No newline at end of file + return vfpTable.vfpType === "PROD"; +} + +export function isInjTable(vfpTable: VfpProdTable_api | VfpInjTable_api): vfpTable is VfpInjTable_api { + return vfpTable.vfpType === "INJ"; +}