forked from jappel/leistungsbilanz-ts
Remove legacy consumer API
This commit is contained in:
parent
04c299e3f2
commit
3fbf3ac622
30 changed files with 76 additions and 1089 deletions
|
|
@ -1,36 +0,0 @@
|
|||
import type { CreateConsumerInput } from "../../shared/validation/consumer.schemas.js";
|
||||
|
||||
type ProjectDeviceForLinking = {
|
||||
displayName: string;
|
||||
category: string | null;
|
||||
quantity: number;
|
||||
installedPowerPerUnitKw: number;
|
||||
demandFactor: number;
|
||||
phaseCount: number | null;
|
||||
powerFactor: number | null;
|
||||
note: string | null;
|
||||
};
|
||||
|
||||
export function applyLinkedProjectDeviceValues(
|
||||
input: CreateConsumerInput,
|
||||
projectDevice: ProjectDeviceForLinking | null
|
||||
): CreateConsumerInput {
|
||||
if (!input.projectDeviceId || !input.isLinkedToDevice || !projectDevice) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return {
|
||||
...input,
|
||||
name: projectDevice.displayName,
|
||||
category: projectDevice.category ?? undefined,
|
||||
quantity: projectDevice.quantity,
|
||||
installedPowerPerUnitKw: projectDevice.installedPowerPerUnitKw,
|
||||
demandFactor: projectDevice.demandFactor,
|
||||
phaseCount:
|
||||
projectDevice.phaseCount === 1 || projectDevice.phaseCount === 3
|
||||
? (projectDevice.phaseCount as 1 | 3)
|
||||
: undefined,
|
||||
powerFactor: projectDevice.powerFactor ?? undefined,
|
||||
note: projectDevice.note ?? undefined,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import { CircuitRepository } from "../../db/repositories/circuit.repository.js";
|
||||
import { CircuitListRepository } from "../../db/repositories/circuit-list.repository.js";
|
||||
import { CircuitSectionRepository } from "../../db/repositories/circuit-section.repository.js";
|
||||
import { ConsumerRepository } from "../../db/repositories/consumer.repository.js";
|
||||
import {
|
||||
LegacyConsumerMigrationRepository,
|
||||
type LegacyMigrationCircuitPersistenceInput,
|
||||
|
|
@ -14,7 +13,11 @@ import {
|
|||
normalizeCircuitNumber,
|
||||
} from "./legacy-consumer-migration-planner.js";
|
||||
|
||||
type LegacyConsumerRow = Awaited<ReturnType<ConsumerRepository["listByCircuitList"]>>[number];
|
||||
type LegacyConsumerRow = Awaited<
|
||||
ReturnType<
|
||||
LegacyConsumerMigrationRepository["listSourceConsumersByCircuitList"]
|
||||
>
|
||||
>[number];
|
||||
|
||||
function parseEquipmentSequence(equipmentIdentifier: string, prefix: string): number | null {
|
||||
if (!equipmentIdentifier.startsWith(prefix)) {
|
||||
|
|
@ -32,7 +35,6 @@ export class LegacyConsumerMigrationService {
|
|||
private readonly circuitListRepository = new CircuitListRepository();
|
||||
private readonly sectionRepository = new CircuitSectionRepository();
|
||||
private readonly circuitRepository = new CircuitRepository();
|
||||
private readonly consumerRepository = new ConsumerRepository();
|
||||
private readonly roomRepository = new RoomRepository();
|
||||
|
||||
constructor(
|
||||
|
|
@ -60,7 +62,10 @@ export class LegacyConsumerMigrationService {
|
|||
existingCircuits.map((circuit) => circuit.equipmentIdentifier.toUpperCase())
|
||||
);
|
||||
|
||||
const legacyConsumers = await this.consumerRepository.listByCircuitList(circuitListId);
|
||||
const legacyConsumers =
|
||||
await this.migrationRepository.listSourceConsumersByCircuitList(
|
||||
circuitListId
|
||||
);
|
||||
const rooms = await this.roomRepository.listByProject(projectId);
|
||||
const roomById = new Map(rooms.map((room) => [room.id, room]));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
import {
|
||||
calculateCurrentA,
|
||||
calculateDemandPowerKw,
|
||||
calculateInstalledPowerKw,
|
||||
} from "../calculations/power-calculation.js";
|
||||
import type { Consumer } from "../models/consumer.model.js";
|
||||
|
||||
export interface ConsumerWithCalculatedValues extends Consumer {
|
||||
installedPowerKw: number;
|
||||
demandPowerKw: number;
|
||||
effectiveVoltageV?: number;
|
||||
currentA?: number;
|
||||
}
|
||||
|
||||
export interface ProjectVoltageDefaults {
|
||||
singlePhaseVoltageV: number;
|
||||
threePhaseVoltageV: number;
|
||||
}
|
||||
|
||||
export class PowerBalanceService {
|
||||
enrichConsumer(
|
||||
consumer: Consumer,
|
||||
projectVoltageDefaults?: ProjectVoltageDefaults
|
||||
): ConsumerWithCalculatedValues {
|
||||
const installedPowerKw = calculateInstalledPowerKw({
|
||||
quantity: consumer.quantity,
|
||||
installedPowerPerUnitKw: consumer.installedPowerPerUnitKw,
|
||||
demandFactor: consumer.demandFactor,
|
||||
});
|
||||
const demandPowerKw = calculateDemandPowerKw({
|
||||
quantity: consumer.quantity,
|
||||
installedPowerPerUnitKw: consumer.installedPowerPerUnitKw,
|
||||
demandFactor: consumer.demandFactor,
|
||||
});
|
||||
|
||||
const effectiveVoltageV =
|
||||
consumer.voltageV ??
|
||||
(consumer.phaseCount === 1
|
||||
? projectVoltageDefaults?.singlePhaseVoltageV
|
||||
: consumer.phaseCount === 3
|
||||
? projectVoltageDefaults?.threePhaseVoltageV
|
||||
: undefined);
|
||||
|
||||
let currentA: number | undefined;
|
||||
if (effectiveVoltageV && consumer.phaseCount && consumer.powerFactor) {
|
||||
currentA = calculateCurrentA({
|
||||
demandPowerKw,
|
||||
voltageV: effectiveVoltageV,
|
||||
phaseCount: consumer.phaseCount,
|
||||
powerFactor: consumer.powerFactor,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...consumer,
|
||||
installedPowerKw,
|
||||
demandPowerKw,
|
||||
effectiveVoltageV,
|
||||
currentA,
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue