Skip to content

Commit 93303d5

Browse files
authored
Make use of Literal in back-end schema for vfp type (#875)
1 parent afccefb commit 93303d5

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1+
from enum import StrEnum
2+
from typing import Literal
3+
14
from pydantic import BaseModel
25

36
from primary.services.sumo_access.vfp_types import THP, WFR, GFR, ALQ, FlowRateType, UnitType, TabType
47

58

6-
class VfpProdTable(BaseModel):
7-
isProdTable: bool = True
9+
class VfpType(StrEnum):
10+
PROD = "PROD"
11+
INJ = "INJ"
12+
13+
14+
class VfpTableBase(BaseModel):
15+
vfpType: Literal[VfpType.INJ, VfpType.PROD]
816
tableNumber: int
917
datum: float
10-
thpType: THP
11-
wfrType: WFR
12-
gfrType: GFR
13-
alqType: ALQ
1418
flowRateType: FlowRateType
1519
unitType: UnitType
1620
tabType: TabType
1721
thpValues: list[float]
18-
wfrValues: list[float]
19-
gfrValues: list[float]
20-
alqValues: list[float]
2122
flowRateValues: list[float]
2223
bhpValues: list[float]
2324
flowRateUnit: str
2425
thpUnit: str
26+
bhpUnit: str
27+
28+
29+
class VfpProdTable(VfpTableBase):
30+
vfpType: Literal[VfpType.PROD] = VfpType.PROD
31+
thpType: THP
32+
wfrType: WFR
33+
gfrType: GFR
34+
alqType: ALQ
35+
wfrValues: list[float]
36+
gfrValues: list[float]
37+
alqValues: list[float]
2538
wfrUnit: str
2639
gfrUnit: str
2740
alqUnit: str
28-
bhpUnit: str
2941

3042

31-
class VfpInjTable(BaseModel):
32-
isInjTable: bool = True
33-
tableNumber: int
34-
datum: float
35-
flowRateType: FlowRateType
36-
unitType: UnitType
37-
tabType: TabType
38-
thpValues: list[float]
39-
flowRateValues: list[float]
40-
bhpValues: list[float]
41-
flowRateUnit: str
42-
thpUnit: str
43-
bhpUnit: str
43+
class VfpInjTable(VfpTableBase):
44+
vfpType: Literal[VfpType.INJ] = VfpType.INJ

frontend/src/api/autogen/types.gen.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ export type VectorStatisticSensitivityData_api = {
890890
};
891891

892892
export type VfpInjTable_api = {
893-
isInjTable: boolean;
893+
vfpType: "INJ";
894894
tableNumber: number;
895895
datum: number;
896896
flowRateType: FlowRateType_api;
@@ -905,28 +905,28 @@ export type VfpInjTable_api = {
905905
};
906906

907907
export type VfpProdTable_api = {
908-
isProdTable: boolean;
908+
vfpType: "PROD";
909909
tableNumber: number;
910910
datum: number;
911-
thpType: Thp_api;
912-
wfrType: Wfr_api;
913-
gfrType: Gfr_api;
914-
alqType: Alq_api;
915911
flowRateType: FlowRateType_api;
916912
unitType: UnitType_api;
917913
tabType: TabType_api;
918914
thpValues: Array<number>;
919-
wfrValues: Array<number>;
920-
gfrValues: Array<number>;
921-
alqValues: Array<number>;
922915
flowRateValues: Array<number>;
923916
bhpValues: Array<number>;
924917
flowRateUnit: string;
925918
thpUnit: string;
919+
bhpUnit: string;
920+
thpType: Thp_api;
921+
wfrType: Wfr_api;
922+
gfrType: Gfr_api;
923+
alqType: Alq_api;
924+
wfrValues: Array<number>;
925+
gfrValues: Array<number>;
926+
alqValues: Array<number>;
926927
wfrUnit: string;
927928
gfrUnit: string;
928929
alqUnit: string;
929-
bhpUnit: string;
930930
};
931931

932932
export enum Wfr_api {

frontend/src/modules/Vfp/utils/vfpDataAccessor.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Alq_api, FlowRateType_api, Gfr_api, VfpInjTable_api, VfpProdTable_api, Wfr_api } from "@api";
22

3-
import { isProdTable } from "./vfpTableClassifier";
3+
import { isInjTable, isProdTable } from "./vfpTableClassifier";
44

55
import { VfpParam, VfpType } from "../types";
66

@@ -16,7 +16,7 @@ export class VfpDataAccessor {
1616
}
1717

1818
isInjTable(): boolean {
19-
return !isProdTable(this._vfpTable);
19+
return isInjTable(this._vfpTable);
2020
}
2121

2222
getTableNumber(): number {
@@ -65,7 +65,7 @@ export class VfpDataAccessor {
6565
if (vfpParam === VfpParam.THP) {
6666
return this._vfpTable.thpValues;
6767
}
68-
if ("isProdTable" in this._vfpTable) {
68+
if (isProdTable(this._vfpTable)) {
6969
if (vfpParam === VfpParam.WFR) {
7070
return this._vfpTable.wfrValues;
7171
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { VfpProdTable_api, VfpInjTable_api } from "@api";
1+
import { VfpInjTable_api, VfpProdTable_api } from "@api";
22

33
export function isProdTable(vfpTable: VfpProdTable_api | VfpInjTable_api): vfpTable is VfpProdTable_api {
4-
return "isProdTable" in vfpTable
5-
}
4+
return vfpTable.vfpType === "PROD";
5+
}
6+
7+
export function isInjTable(vfpTable: VfpProdTable_api | VfpInjTable_api): vfpTable is VfpInjTable_api {
8+
return vfpTable.vfpType === "INJ";
9+
}

0 commit comments

Comments
 (0)