forked from jappel/leistungsbilanz-ts
Derive device voltages from project settings
This commit is contained in:
parent
b1a11397b3
commit
084103bf54
39 changed files with 2696 additions and 76 deletions
35
src/domain/services/project-voltage.service.ts
Normal file
35
src/domain/services/project-voltage.service.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
export type ElectricalPhaseType = "single_phase" | "three_phase";
|
||||
|
||||
export interface ProjectVoltageSettings {
|
||||
singlePhaseVoltageV: number;
|
||||
threePhaseVoltageV: number;
|
||||
}
|
||||
|
||||
export function resolveProjectVoltage(
|
||||
phaseType: ElectricalPhaseType,
|
||||
settings: ProjectVoltageSettings
|
||||
) {
|
||||
return phaseType === "three_phase"
|
||||
? settings.threePhaseVoltageV
|
||||
: settings.singlePhaseVoltageV;
|
||||
}
|
||||
|
||||
export function resolveCircuitPhaseType(
|
||||
sectionKey: string,
|
||||
devicePhaseTypes: ReadonlyArray<string | null | undefined> = []
|
||||
): ElectricalPhaseType {
|
||||
if (sectionKey === "three_phase") {
|
||||
return "three_phase";
|
||||
}
|
||||
if (sectionKey === "lighting" || sectionKey === "single_phase") {
|
||||
return "single_phase";
|
||||
}
|
||||
const assignedPhaseTypes = devicePhaseTypes.filter(
|
||||
(phaseType): phaseType is ElectricalPhaseType =>
|
||||
phaseType === "single_phase" || phaseType === "three_phase"
|
||||
);
|
||||
return assignedPhaseTypes.length > 0 &&
|
||||
assignedPhaseTypes.every((phaseType) => phaseType === "three_phase")
|
||||
? "three_phase"
|
||||
: "single_phase";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue