diff --git a/AGENTS.md b/AGENTS.md index 8312d55..9ef5b87 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -52,7 +52,8 @@ See `docs/current-architecture.md` for the complete module and request flow. - Device rows inside a circuit do not have their own equipment identifiers. - Protection and cable data belong to the circuit, not to individual devices. - Device-level values include quantity, power per unit, simultaneity factor, cosPhi, room data, cost group and category. -- Circuit total power is the sum of all device rows in that circuit. +- Circuit total power is the sum of all device rows in that circuit plus the + read-only loads of logically linked downstream boards on that feeder circuit. - Existing equipment identifiers must never be changed automatically. - Renumbering is always an explicit user action. @@ -284,16 +285,19 @@ not change the project revision or undo/redo stacks. Restoring a server-stored snapshot verifies its checksum and the current-state hash, replaces supported project data atomically and records a new `restore` revision with a complete inverse command. Restore can therefore be undone and redone after a restart. -Current snapshot schema version 8 additionally stores the optional net room -area `rooms[].areaM2` (see `docs/building-structure.md`); versions 1 to 7 are -upgraded with `areaM2 = null`. Version 7 stores the project buildings and +Current snapshot schema version 9 additionally stores +`feedingDistributionBoardId` and `feedingCircuitId` on distribution boards; +versions 1 to 8 are upgraded with both references set to `null`. Version 8 +stores the optional net room area `rooms[].areaM2` (see +`docs/building-structure.md`); versions 1 to 7 are upgraded with +`areaM2 = null`. Version 7 stores the project buildings and `floors[].buildingId`; versions 1 to 6 are upgraded with no buildings and `buildingId = null`. Version 6 stores the distribution-board info fields `boardNumber`, `location`, `fedFrom` and `remark` and the project cover fields `siteAddress`, `workStage`, `projectLead` and `projectEditor`; all older supported versions are upgraded with `null` for these fields. -Stored named and automatic snapshots of every supported version (1 to 8) +Stored named and automatic snapshots of every supported version (1 to 9) remain restorable; they are upgraded while parsing. Version 5 stores the manual quantity share of every CircuitDeviceRow. Version 4 snapshots are upgraded with `manualQuantity = quantity`; they already contain the complete confirmed @@ -309,7 +313,7 @@ project graph. Project-wide Revit CSV configuration uses `external-csv-configuration.update`. Its complete expected/target snapshot is persisted through the shared project-command transaction, so create, update, -delete, Undo and Redo are revision-safe. Snapshot schema 5-8, restore and portable +delete, Undo and Redo are revision-safe. Snapshot schema 5-9, restore and portable project duplication preserve the configuration; duplication remaps its internal id and project link. The project page exposes the Revit CSV modal. It edits the complete @@ -323,7 +327,7 @@ immutable import batches with original bytes plus the classified cell matrix, normalized source-room mappings and external objects unique by `(sourceId, ifcGuid)`. Source values, planning values and overrides are separate. The general external-model repository is read-only; runtime writes belong only -to typed command adapters. Snapshot/restore and portable project transfer schema versions 5-8 +to typed command adapters. Snapshot/restore and portable project transfer schema versions 5-9 capture the complete external state and remap every internal UUID and link while preserving IFCGUIDs, source values, original bytes and the classified matrix. Import batches additionally store the monotonic project CSV configuration @@ -463,22 +467,34 @@ snapshot contains the group, optional component protections, complete circuits, circuit protections and all device-row link/override metadata. Delete re-captures and compares the subtree before cascading; restore preserves every UUID in foreign-key-safe order. -The circuit-tree read model exposes fixed `headerComponents`, group-owned +The project-wide circuit-tree read model exposes fixed `headerComponents`, group-owned `components`, `footerComponents`, optional group category/number and optional one-to-one protection DTOs for circuits and group components. These are the only supported circuit-protection source; no flat compatibility fields remain. +It resolves logical board feeds once for the complete project and adds each +downstream board's demand after its own board simultaneity factor to the chosen +feeding circuit as a read-only virtual row. Recursive chains and several boards +on one circuit are supported. A board-only link affects hierarchy but adds no +load until a feeding circuit is selected. Distribution-board floor assignment and a project-enabled supply type use `distribution-board.update`; both values are snapshot/export fields and one persistent undo step. -The same command (still schema version 1, additively extended) carries the +The same command uses schema version 2 for the logical +`feedingDistributionBoardId` and optional matching `feedingCircuitId` together +with the existing fields. Version-1 history commands remain executable and do +not change logical feed references. The command rejects self-links, cycles and +circuits from another board. The board info-card fields `boardNumber`, `location`, `fedFrom` and `remark` (migration `0007`). They are nullable, trimmed planner values; the PUT route only includes submitted info fields in the command and its inverse. An empty board with info values is no longer an unchanged setup, so history deletion of it is rejected like a changed simultaneity factor. Populated-subtree commands stored before these fields existed are normalized to `null` values -(`normalizeDistributionBoardSubtreeSnapshot`). `fedFrom` is deliberately free -text: the logical link to the feeding board/circuit is an open design decision. +(`normalizeDistributionBoardSubtreeSnapshot`). `fedFrom` remains free text for +external feeds and notes; project-board feeds use the two UUID references. +Deleting a referenced board or feeding circuit is blocked in every direct, +subtree and history-only removal path. Board copies retain their incoming feed, +and project duplication remaps both references. These fields are intended to be prefillable from Revit parameters later, but only through the Phase 14 rules (preview, explicit confirmation, no silent overwrite). @@ -521,9 +537,10 @@ Required operations: `` so it repeats on printed pages. PDF export uses the browser print dialog; page size, margins and "Seite x von y" come from injected named `@page` rules (`lb-portrait`, `lb-landscape`). -- The board hierarchy and "Σ inkl. unterlagert" in the overview are - PRELIMINARY (text match of `fedFrom` against board number/name, plain sum, - no upstream simultaneity factor). Replace this once the feed link is modeled. +- The board hierarchy follows logical board ids. The overview shows power + before board GZF and demand including linked downstream boards; it does not + add a second cumulative column. Board plans render downstream-board loads as + read-only rows. `fedFrom` groups only external root feeds. - Colors/fonts follow the kbp corporate design (`--pd-*` variables in `print-document.css`). Empty cover values are shown as "[ergänzen]"; the Planstände editor column shows the project's current @@ -701,9 +718,9 @@ for the early-phase power balance by DIN 276 cost group (see - full electrical sizing - multi-user/PostgreSQL operation - supported production deployment -- logical feed link between distribution boards (`fedFrom` stays free text - until the project owner decides whether it references a board, a feeding - circuit or both) and the resulting hierarchical power summation +- second/replacement board feeds, including changeover semantics for SV/SiBe +- Revit prefill proposals for logical board feeds through the Phase 14 preview + and explicit-confirmation workflow Do not implement these while working on an unrelated phase. diff --git a/docs/circuit-list-editor-api.md b/docs/circuit-list-editor-api.md index c9cd2b7..a8173f5 100644 --- a/docs/circuit-list-editor-api.md +++ b/docs/circuit-list-editor-api.md @@ -67,10 +67,13 @@ Prüfsumme; Ersetzen übernimmt die Grobbilanzen atomar und mit Undo/Redo, Duplizieren vergibt neue IDs. Transferformat 1 bleibt ohne Grobbilanzen importierbar. -Das aktuelle Projekt-Snapshot-Schema 8 enthält außerdem die optionale -Netto-Raumfläche `rooms[].areaM2`. Snapshot-Versionen 1–7 werden dafür mit +Das aktuelle Projekt-Snapshot-Schema 9 enthält die logischen Einspeisungsverweise +der Verteilungen; Versionen 1–8 werden mit leeren Verweisen hochgestuft. Schema 8 +enthält außerdem die optionale Netto-Raumfläche `rooms[].areaM2`. +Snapshot-Versionen 1–7 werden dafür mit `areaM2 = null` hochgestuft. Restore, Export und Import erhalten vorhandene -Flächen; eine eigene Transferformat-Version ist nicht nötig, weil Format 2 den +Flächen und Einspeisungsverweise; beim Duplizieren werden Board- und Circuit-IDs +neu zugeordnet. Eine eigene Transferformat-Version ist nicht nötig, weil Format 2 den versionierten Projektsnapshot einbettet. The public dispatcher supports the Circuit and CircuitDeviceRow commands @@ -254,23 +257,30 @@ commands. Endpoints, payloads and calculation rules: `docs/estimate-balance.md`. - stale revisions return `409 PROJECT_REVISION_CONFLICT` - `PUT /projects/:projectId/distribution-boards/:distributionBoardId` - body: - `{ "floorId": null, "supplyType": "AV", "simultaneityFactor": 1, "expectedRevision": 13 }` + `{ "floorId": null, "supplyType": "AV", "simultaneityFactor": 1, "feedingDistributionBoardId": "board_hv", "feedingCircuitId": "circuit_out", "expectedRevision": 13 }` - optional info-card fields: `boardNumber` (max. 50), `location`, `fedFrom` (max. 200 each) and `remark` (max. 2000); strings are trimmed and an empty string is stored as `null` - - executes `distribution-board.update`; all submitted values, including the + - `feedingDistributionBoardId` and `feedingCircuitId` are optional nullable + fields. A feeding circuit requires a feeding board and must belong to it; + self-links and cycles are rejected. A board-only link creates hierarchy + without assigning its load to an upstream circuit. + - executes `distribution-board.update` schema version 2; all submitted values, including the submitted info fields, are restored together by persistent Undo/Redo - - `fedFrom` is free text until the logical feed link is modeled + - `fedFrom` remains free text for external feeds such as HAK, metering, + transformer or generator and for supplementary notes - `POST /projects/:projectId/distribution-boards/:distributionBoardId/copy` - body: `{ "name": "UV-02 Kopie", "expectedRevision": 14 }` - duplicates the complete distribution-board subtree with new owning UUIDs - while preserving project-device and room links + while preserving project-device, room and incoming feeding links - response includes the new `distributionBoard`, its `circuitList`, the revision and current history state - `DELETE /projects/:projectId/distribution-boards/:distributionBoardId` - body: `{ "expectedRevision": 15 }` - removes the complete, exactly captured distribution-board subtree in one transaction + - rejects deletion while another board references this board or one of its + circuits as a feeder; circuit and populated-group deletion use the same guard - response includes `distributionBoardId`, the revision and current history state - Copy and deletion use `distribution-board.insert-subtree` and @@ -327,12 +337,17 @@ commands. Endpoints, payloads and calculation rules: `docs/estimate-balance.md`. ### Tree Endpoint +- `GET /projects/:projectId/circuit-trees` + - returns all circuit trees for one project from one project-wide read and is + used by the print view and feeding-board selection - `GET /projects/:projectId/circuit-lists/:circuitListId/tree` - Purpose: returns fixed header components, grouped sections with optional protection components, complete circuit/device-row blocks and auxiliary footer components. Circuit and component protection devices use their separate one-to-one DTOs. Calculated row, circuit, section and board totals - remain included. + remain included. Circuit totals contain the demand of linked downstream + boards. `downstreamBoardLoads` exposes those contributions as read-only rows; + `feedingReference` resolves the current board/circuit labels by id. Response sketch: diff --git a/docs/circuit-list-editor-known-limitations.md b/docs/circuit-list-editor-known-limitations.md index 78bb44e..fdc463a 100644 --- a/docs/circuit-list-editor-known-limitations.md +++ b/docs/circuit-list-editor-known-limitations.md @@ -33,10 +33,13 @@ - Protection and cable values are planner-owned manual selections. The later sizing/warning engine does not yet validate them against load, length or voltage-drop rules. -- Distribution-board `fedFrom` is free text. The print overview derives its - supply structure and "Σ inkl. unterlagert" only from exact text matches with - board numbers/names and adds values without an upstream simultaneity factor - (see `docs/print-view.md`). +- One logical incoming feed per distribution board is supported. A second or + replacement feed with changeover semantics (for example SV/SiBe) is still a + follow-up. `fedFrom` remains the free-text field for external sources and + supplementary notes. Revit does not yet propose logical feed links. +- A logical link without a selected feeding circuit appears in the hierarchy, + but deliberately contributes no load to an upstream circuit until the planner + selects that circuit (see `docs/print-view.md`). - The print view uses a kbp corporate design derived from logo and presentation material. Snapshots do not record an editor, so the cover's Planstände list shows the project's current editor for every entry. On screen, long diff --git a/docs/current-architecture.md b/docs/current-architecture.md index 332b6a9..920002d 100644 --- a/docs/current-architecture.md +++ b/docs/current-architecture.md @@ -468,8 +468,22 @@ Derselbe Befehl versioniert die Felder der Verteiler-Infokarte (`boardNumber`, `location`, `fedFrom`, `remark`, Migration `0007`). Die Infokarte liegt im Bearbeiten-Dialog der Verteilung; die Werte sind lokale Planungswerte und sollen später über den Revit-Abgleich nur nach Vorschau und -ausdrücklicher Bestätigung vorbelegt werden. `fedFrom` ist vorerst Freitext. -Snapshot-Schema 8 enthält zusätzlich die optionale Netto-Raumfläche +ausdrücklicher Bestätigung vorbelegt werden. `fedFrom` bleibt Freitext für +externe Einspeisungen und Hinweise. +`distribution-board.update` verwendet Schema-Version 2 für die optionalen +logischen Verweise `feedingDistributionBoardId` und `feedingCircuitId`. +Version-1-Befehle aus der Historie bleiben ausführbar und verändern diese +Verweise nicht. Der speisende Stromkreis muss zur speisenden Verteilung gehören; +Selbstverweise und Zyklen werden abgelehnt. Löschbefehle für referenzierte +Verteilungen und Stromkreise, einschließlich Unterbaum- und Undo-Pfaden, werden +vor der Datenbankänderung fachlich gesperrt. +Die projektweite Circuit-Tree-Projektion berechnet rekursiv die Lasten aller +Verteilungen. Die Leistung einer Unterverteilung nach ihrem eigenen +Verteiler-GZF wird als virtuelle, schreibgeschützte Zeile genau dem gewählten +Abgang zugerechnet. Eine Verknüpfung ohne Stromkreis bildet nur die Hierarchie. +Snapshot-Schema 9 enthält die beiden Einspeisungsverweise; Versionen 1–8 werden +mit `null` hochgestuft. Restore und Projektduplizierung erhalten beziehungsweise +remappen die Verweise. Snapshot-Schema 8 enthält zusätzlich die optionale Netto-Raumfläche `rooms[].areaM2`; Versionen 1–7 werden dafür mit `null` hochgestuft. Snapshot-Schema 7 enthält die Gebäude und die Gebäudezuordnung der Etagen; ältere Versionen werden ohne Gebäude hochgestuft. @@ -580,7 +594,7 @@ Oberfläche: `/projects/:projectId/grobbilanz`. Details: `toLowerCase()` gegen das vollständige Register der Stromkreisliste und wird von jedem Anlage-/Umbenennungspfad für Stromkreise und Verteilerkomponenten aufgerufen, auch dort, wo zuvor kein Vorab-Check existierte. Snapshot- und - Transfer-Integration verwenden aktuell Snapshot-Schema 8. Persistente + Transfer-Integration verwenden aktuell Snapshot-Schema 9. Persistente Insert/Delete/Update-Commands für veränderliche Verteilerkomponenten, Gruppen einschließlich befüllter Unterbäume sowie vollständige Gruppensortierung sind integriert. Der Editor zeigt die geschützte Struktur diff --git a/docs/print-view.md b/docs/print-view.md index eba91ed..a843030 100644 --- a/docs/print-view.md +++ b/docs/print-view.md @@ -5,8 +5,9 @@ Die Aktionen für Büroangaben und Logo speichern dagegen globale Einstellungen. Projekt- und Verteilerangaben werden in den jeweiligen Bearbeitungsdialogen über Projektbefehle mit Undo/Redo gepflegt. -Beim Laden werden die Projektrevisionen aller Stromkreislisten und ein -abschließend erneut gelesener Projektstand verglichen. Ändert sich das Projekt +Beim Laden werden alle Stromkreislisten in einer projektweiten Abfrage gelesen; +deren Projektrevision und ein abschließend erneut gelesener Projektstand werden +verglichen. Ändert sich das Projekt währenddessen, wird statt eines gemischten Datenstands eine Aufforderung zum Neuladen angezeigt. Eine bereits geladene Seitenansicht aktualisiert sich nicht automatisch bei späteren Änderungen in einem anderen Tab. @@ -31,12 +32,14 @@ automatisch bei späteren Änderungen in einem anderen Tab. erscheinen als orangefarbenes „[ergänzen]“. 2. **Verteilerübersicht (quer)** – Versorgungsstruktur und Tabelle je Verteiler mit Stromkreisanzahl, Pinst (Anzahl × Leistung je - Stück), PGeräte (mit Geräte-GZF), Verteiler-GZF, - Pgl, IB und „Σ inkl. unterlagert“. + Stück, nur lokale Geräte), Leistung vor Verteiler-GZF einschließlich + gespeister Unterverteilungen, Verteiler-GZF, Pgl einschließlich + Unterverteilungen und IB. Die Hierarchie folgt den logischen IDs. 3. **Verteilerpläne (quer, je Verteiler)** – Titelleiste mit Verteilernummer, Bezeichnung, Örtlichkeit, Netzart, „Gespeist von“ und Pgl; darunter Kopfkomponenten, Gruppen, Stromkreise - (mehrzeilige mit Sammelzeile und eingerückten Gerätezeilen), + (mehrzeilige mit Sammelzeile, eingerückten Gerätezeilen und + schreibgeschützten Unterverteilungszeilen), Gruppensummen und Verteilersumme. Fehlende Kabelangaben sind als „offen“ markiert. Die Titelleiste steht im Tabellenkopf und wiederholt sich beim Drucken auf Folgeseiten. @@ -46,19 +49,25 @@ Seitenformat, Ränder und „Seite x von y“ kommen beim Drucken aus benannten einfügt. Die Bildschirmansicht zeigt Blätter in Papiergröße; die exakte Seitenaufteilung langer Verteilerpläne entsteht erst beim Drucken. -## Vorläufige Punkte +## Berechnung und offene Punkte -- **Einspeisung / Hierarchie:** `fedFrom` ist Freitext. Die Übersicht ordnet - einen Verteiler nur dann unter, wenn der Text eindeutig der Nummer oder - Bezeichnung eines anderen Verteilers entspricht (ohne Beachtung von - Groß-/Kleinschreibung und äußeren Leerzeichen). Mehrdeutige Treffer bleiben - ohne Zuordnung; „Σ inkl. unterlagert“ ist - eine einfache Summe ohne übergeordneten GZF. Die fachliche Verknüpfung - (Verteiler und/oder speisender Stromkreis) und die Summierungslogik sind - offen. -- **IB** ist ein symmetrischer Drehstromwert - S / (√3 · U3~) mit S aus P / cos φ je Gerätezeile - (fehlendes cos φ = 1) und Verteiler-GZF. +- **Einspeisung / Hierarchie:** `feedingDistributionBoardId` bestimmt die + Hierarchie. Ist zusätzlich `feedingCircuitId` gesetzt, fließt die Leistung + der Unterverteilung nach deren eigenem Verteiler-GZF als virtuelle Last in + genau diesen Abgang ein. Ketten werden rekursiv berechnet; mehrere + Unterverteilungen an einem Abgang sind erlaubt. Ohne Abgang bleibt es bei der + Hierarchie ohne Leistungsaufschlag. `fedFrom` bezeichnet nur externe Quellen + oder ergänzende Hinweise. +- **Keine Doppelzählung:** Die Abgangs- und Verteilersummen enthalten die + Unterverteilungsleistung bereits. Deshalb gibt es keine zusätzliche Spalte + „Σ inkl. unterlagert“. Die Summenzeile verwendet für hierarchische Leistungen + nur Wurzelverteilungen; Pinst summiert weiterhin die lokalen Geräte. +- **IB:** S entsteht aus Σ(P / cos φ) für Geräte und den wirksamen + cos φ der Unterverteilungen, jeweils mit dem fachlich zugehörigen GZF. Bei + einem 1-phasigen speisenden Abgang gilt I = S / U1~, sonst + I = S / (√3 · U3~). Für externe oder nur bis zur Verteilung + bekannte Einspeisungen bleibt die bisherige Darstellung als symmetrischer + Drehstromwert bestehen. - **Corporate Design:** Farben (`--pd-*` in `src/frontend/print/print-document.css`) und Schrift (Arial) sind aus Logo und kbp-Präsentationsmaterial abgeleitet und werden durch die offizielle @@ -118,10 +127,11 @@ ihren Wert. ## Bestehende Datenbanken -Vor dem Anwenden der additiven Migrationen `0007` und `0008` eine verifizierte +Vor dem Anwenden der additiven Migrationen einschließlich `0012` eine verifizierte Datenbanksicherung mit `npm run db:backup` erstellen. Die neuen Projekt- und Verteilerfelder bleiben bei bestehenden Datensätzen zunächst leer (`null`). -Snapshot-Schema 6 enthält beide Feldgruppen; die unterstützten Versionen 1–5 -werden beim Lesen hochgestuft. Restore und Projektkopie erhalten die neuen -Angaben. Globale Büroangaben und Logo gehören zur Datenbanksicherung, nicht +Snapshot-Schema 9 enthält zusätzlich die logischen Einspeisungsverweise; die +unterstützten Versionen 1–8 werden mit leeren Verweisen hochgestuft. Restore und +Projektkopie erhalten beziehungsweise remappen die neuen Angaben. Globale +Büroangaben und Logo gehören zur Datenbanksicherung, nicht zum logischen Projektsnapshot oder Projekttransfer. diff --git a/docs/spec/08-current-product-backlog.md b/docs/spec/08-current-product-backlog.md index d31eecc..c0a2720 100644 --- a/docs/spec/08-current-product-backlog.md +++ b/docs/spec/08-current-product-backlog.md @@ -149,9 +149,10 @@ The pre-release cleanup established the following compatibility boundary: - [x] Rough power balance for LPH 2/3 by cost group, including the comparison with the detailed balance and the explicit copy of one row as a ProjectDevice. +- [x] Logical distribution-board feed link with an optional feeding circuit, + recursive load rollup and deletion guards (#3). -Open follow-ups (Gitea issues): logical feed link between distribution boards -(#3), bill of quantities export (#5), area-based loads in W/m² for +Open follow-ups (Gitea issues): bill of quantities export (#5), area-based loads in W/m² for ProjectDevices and device rows (#20). ## Recommended Sequence diff --git a/src/app/projects/[projectId]/print/page.tsx b/src/app/projects/[projectId]/print/page.tsx index dcbe7b2..7762875 100644 --- a/src/app/projects/[projectId]/print/page.tsx +++ b/src/app/projects/[projectId]/print/page.tsx @@ -7,10 +7,9 @@ import "../../../../frontend/print/print-document.css"; import { deleteDocumentLogo, documentLogoUrl, - getCircuitTree, + getProjectCircuitTrees, getDocumentBranding, getProject, - listCircuitLists, listDistributionBoards, listFloors, listProjectSnapshots, @@ -31,7 +30,7 @@ import { import { PrintDocument } from "../../../../frontend/print/print-document"; import { assertPrintRevisionConsistency, - buildPreliminaryBoardHierarchy, + buildBoardHierarchy, summarizePrintBoard, type PrintBoardSummary, } from "../../../../frontend/print/print-document-model"; @@ -89,17 +88,20 @@ export default function ProjectPrintPage() { } let cancelled = false; async function load() { - const [project, boards, circuitLists, floors, snapshots, branding] = + const [project, boards, projectTrees, floors, snapshots, branding] = await Promise.all([ getProject(projectId), listDistributionBoards(projectId), - listCircuitLists(projectId), + getProjectCircuitTrees(projectId), listFloors(projectId), listProjectSnapshots(projectId), getDocumentBranding(), ]); const floorNameById = new Map(floors.map((floor) => [floor.id, floor.name])); - const summaries = await Promise.all( + const treeByBoardId = new Map( + projectTrees.trees.map((tree) => [tree.distributionBoardId, tree]) + ); + const summaries = [...boards] .sort( (left, right) => @@ -107,20 +109,17 @@ export default function ProjectPrintPage() { boardSortCollator.compare(left.name, right.name) ) .flatMap((board) => { - const circuitList = circuitLists.find( - (list) => list.distributionBoardId === board.id - ); - return circuitList ? [{ board, circuitList }] : []; + const tree = treeByBoardId.get(board.id); + return tree ? [{ board, tree }] : []; }) - .map(async ({ board, circuitList }) => + .map(({ board, tree }) => summarizePrintBoard({ board, - circuitListId: circuitList.id, - tree: await getCircuitTree(projectId, circuitList.id), + circuitListId: tree.circuitListId, + tree, floorName: board.floorId ? floorNameById.get(board.floorId) ?? null : null, }) - ) - ); + ); const finalProject = await getProject(projectId); assertPrintRevisionConsistency(project.currentRevision, summaries, finalProject.currentRevision); if (cancelled) { @@ -148,7 +147,7 @@ export default function ProjectPrintPage() { }, [projectId]); const entries = useMemo( - () => (data ? buildPreliminaryBoardHierarchy(data.summaries) : []), + () => (data ? buildBoardHierarchy(data.summaries) : []), [data] ); const stand = useMemo( diff --git a/src/frontend/print/print-document-model.ts b/src/frontend/print/print-document-model.ts index abe08fe..d3e4724 100644 --- a/src/frontend/print/print-document-model.ts +++ b/src/frontend/print/print-document-model.ts @@ -19,14 +19,14 @@ export interface PrintBoardSummary { circuitCount: number; /** Σ quantity × power per unit, without any simultaneity factor. */ installedPowerKw: number; - /** Σ row totals, i.e. with the device-row simultaneity factors. */ - devicePowerKw: number; + /** Device-row demand plus downstream-board demand before this board's GZF. */ + powerBeforeBoardSimultaneityKw: number; simultaneityFactor: number; - /** Device power with the board simultaneity factor applied. */ + /** Total active power with this board's simultaneity factor applied. */ demandPowerKw: number; /** - * Symmetrical three-phase design current from the apparent power - * S = Σ(row total / cos φ) × board GZF. A missing cos φ counts as 1. + * Design current from the apparent power including downstream boards. + * The selected feeder circuit determines whether one or three phases apply. */ designCurrentA: number; } @@ -46,8 +46,13 @@ export function summarizePrintBoard(input: { circuitCount += 1; for (const row of circuit.deviceRows) { installedPowerKw += row.quantity * row.powerPerUnit; - apparentPowerKva += row.rowTotalPower / (row.cosPhi || 1); } + apparentPowerKva += + circuit.circuitApparentPower ?? + circuit.deviceRows.reduce( + (sum, row) => sum + row.rowTotalPower / (row.cosPhi || 1), + 0 + ); } } const simultaneityFactor = tree.distributionBoardSimultaneityFactor; @@ -55,12 +60,13 @@ export function summarizePrintBoard(input: { ...input, circuitCount, installedPowerKw, - devicePowerKw: tree.distributionBoardTotalPower, + powerBeforeBoardSimultaneityKw: tree.distributionBoardTotalPower, simultaneityFactor, demandPowerKw: tree.distributionBoardTotalPowerWithSimultaneityFactor, - designCurrentA: - (apparentPowerKva * simultaneityFactor * 1000) / - (Math.sqrt(3) * tree.threePhaseVoltageV), + designCurrentA: calculateDesignCurrent( + apparentPowerKva * simultaneityFactor, + tree + ), }; } @@ -68,8 +74,6 @@ export interface PrintBoardHierarchyEntry { summary: PrintBoardSummary; depth: number; parentBoardId: string | null; - /** Own demand plus the plain sum of all resolved downstream boards. */ - cumulatedDemandPowerKw: number; } export function assertPrintRevisionConsistency( @@ -82,31 +86,21 @@ export function assertPrintRevisionConsistency( } } -/** - * PRELIMINARY: `fedFrom` is free text until the logical feed link is - * decided. A board is shown below another board only when its `fedFrom` - * text equals that board's number or name (case-insensitive). The - * cumulated value is a plain sum without an upstream simultaneity factor. - * Unresolved texts and cycles keep a board at the top level. - */ -export function buildPreliminaryBoardHierarchy( +export function buildBoardHierarchy( summaries: PrintBoardSummary[] ): PrintBoardHierarchyEntry[] { - const normalize = (value: string | null) => - value?.trim().toLocaleLowerCase("de") || null; + const summaryById = new Map( + summaries.map((summary) => [summary.board.id, summary]) + ); const parentById = new Map(); for (const summary of summaries) { - const fedFrom = normalize(summary.board.fedFrom); - const candidates = fedFrom - ? summaries.filter( - (candidate) => - candidate !== summary && - (normalize(candidate.board.boardNumber) === fedFrom || - normalize(candidate.board.name) === fedFrom) - ) - : []; - const parent = candidates.length === 1 ? candidates[0] : undefined; - parentById.set(summary.board.id, parent?.board.id ?? null); + const parentId = summary.board.feedingDistributionBoardId; + parentById.set( + summary.board.id, + parentId && parentId !== summary.board.id && summaryById.has(parentId) + ? parentId + : null + ); } for (const summary of summaries) { const visited = new Set([summary.board.id]); @@ -125,20 +119,12 @@ export function buildPreliminaryBoardHierarchy( summaries.filter( (summary) => parentById.get(summary.board.id) === boardId ); - const cumulated = (summary: PrintBoardSummary): number => - summary.demandPowerKw + - childrenOf(summary.board.id).reduce( - (sum, child) => sum + cumulated(child), - 0 - ); - const entries: PrintBoardHierarchyEntry[] = []; const walk = (summary: PrintBoardSummary, depth: number) => { entries.push({ summary, depth, parentBoardId: parentById.get(summary.board.id) ?? null, - cumulatedDemandPowerKw: cumulated(summary), }); childrenOf(summary.board.id).forEach((child) => walk(child, depth + 1)); }; @@ -146,6 +132,25 @@ export function buildPreliminaryBoardHierarchy( return entries; } +export function formatFeedingReference(summary: PrintBoardSummary): string { + const reference = summary.tree.feedingReference; + if (!reference) return summary.board.fedFrom ?? "–"; + return `${ + reference.distributionBoardNumber ?? reference.distributionBoardName + }${reference.circuitEquipmentIdentifier ?? ""}`; +} + +function calculateDesignCurrent( + apparentPowerKva: number, + tree: CircuitTreeResponseDto +) { + const category = tree.feedingReference?.circuitCategory; + return category === "lighting" || category === "single_phase" + ? (apparentPowerKva * 1000) / tree.singlePhaseVoltageV + : (apparentPowerKva * 1000) / + (Math.sqrt(3) * tree.threePhaseVoltageV); +} + const kilowattFormat = new Intl.NumberFormat("de-DE", { minimumFractionDigits: 2, maximumFractionDigits: 2, diff --git a/src/frontend/print/print-document.tsx b/src/frontend/print/print-document.tsx index c39b4ba..5a0152b 100644 --- a/src/frontend/print/print-document.tsx +++ b/src/frontend/print/print-document.tsx @@ -13,6 +13,7 @@ import { formatCircuitCable, formatCurrent, formatFactor, + formatFeedingReference, formatKilowatt, formatProtectionDevice, formatUnitPower, @@ -269,8 +270,8 @@ function OverviewSheet({ stand: string; }) { const roots = entries.filter((entry) => entry.parentBoardId === null); - // Top-level boards whose "fed from" text names no other board are grouped - // below that text as an external feed (e.g. "HAK / Zähleranlage"). + // Root boards may still carry an external feed description such as + // "HAK / Zähleranlage"; logical board links determine the actual tree. const feedGroups = new Map(); for (const root of roots) { const feed = root.summary.board.fedFrom ?? ""; @@ -320,11 +321,10 @@ function OverviewSheet({ Nr.BezeichnungÖrtlichkeitEtageNetzGespeist von SK Pinst
[kW] - PGeräte
[kW] + P vor Vert.-GZF
[kW] GZF
Vert. - Pgl
[kW] + Pgl inkl. UV
[kW] IB
[A] - Σ inkl.
unterlagert [kW] @@ -340,41 +340,45 @@ function OverviewSheet({ {board.location ?? "–"} {entry.summary.floorName ?? "–"} {board.supplyType ?? "–"} - {board.fedFrom ?? "–"} + {formatFeedingReference(entry.summary)} {entry.summary.circuitCount} {formatKilowatt(entry.summary.installedPowerKw)} - {formatKilowatt(entry.summary.devicePowerKw)} + {formatKilowatt(entry.summary.powerBeforeBoardSimultaneityKw)} {formatFactor(entry.summary.simultaneityFactor)} {formatKilowatt(entry.summary.demandPowerKw)} {formatCurrent(entry.summary.designCurrentA)} - {formatKilowatt(entry.cumulatedDemandPowerKw)} ); })} - Summe aller Verteiler (ohne übergeordneten GZF) + Summe der Einspeisungen {formatKilowatt(sum((entry) => entry.summary.installedPowerKw))} - {formatKilowatt(sum((entry) => entry.summary.devicePowerKw))} - - {formatKilowatt(sum((entry) => entry.summary.demandPowerKw))} + {formatKilowatt(sum((entry) => + entry.parentBoardId === null + ? entry.summary.powerBeforeBoardSimultaneityKw + : 0 + ))} + {formatKilowatt(sum((entry) => + entry.parentBoardId === null ? entry.summary.demandPowerKw : 0 + ))}

- Vorläufig: „Gespeist von“ ist noch ein Freitextfeld. Struktur und - „Σ inkl. unterlagert“ werden nur über eindeutig passende Verteilernummern bzw. - -bezeichnungen zugeordnet und einfach addiert (kein übergeordneter GZF). - Mehrdeutige Angaben bleiben ohne Zuordnung. Die fachliche - Verknüpfung und Summierung folgt. + Die Struktur folgt den logischen Verknüpfungen. Eine Unterverteilung + wird im gewählten Abgang mit ihrer Leistung nach eigenem + Verteiler-GZF berücksichtigt. Ohne gewählten Abgang erscheint sie + nur in der Hierarchie.

- Pinst = Anzahl × Leistung je Stück · PGeräte = mit Geräte-GZF · - Pgl = mit Verteiler-GZF · IB = S / (√3 · {project.threePhaseVoltageV} V), - S aus cos φ je Gerätezeile + Pinst = lokale Geräte ohne GZF · P vor Vert.-GZF = + Geräte-GZF einschließlich gespeister Unterverteilungen · Pgl = + zusätzlich mit Verteiler-GZF · IB aus S und der Phasenart + des speisenden Abgangs

@@ -404,6 +408,7 @@ function ComponentRow({ component }: { component: CircuitTreeComponentDto }) { function CircuitRows({ circuit }: { circuit: CircuitTreeCircuitDto }) { const rows = circuit.deviceRows; + const downstreamBoards = circuit.downstreamBoardLoads ?? []; const circuitCells = ( <> {formatProtectionDevice(circuit.protectionDevice) ?? } @@ -414,7 +419,7 @@ function CircuitRows({ circuit }: { circuit: CircuitTreeCircuitDto }) { {circuit.remark ?? ""} ); - if (rows.length === 0) { + if (rows.length === 0 && downstreamBoards.length === 0) { return ( {circuit.equipmentIdentifier} @@ -426,7 +431,7 @@ function CircuitRows({ circuit }: { circuit: CircuitTreeCircuitDto }) { ); } - if (rows.length === 1) { + if (rows.length === 1 && downstreamBoards.length === 0) { const row = rows[0]; const title = circuit.displayName ?? row.displayName; return ( @@ -468,6 +473,16 @@ function CircuitRows({ circuit }: { circuit: CircuitTreeCircuitDto }) { ))} + {downstreamBoards.map((load) => ( + + + Unterverteilung {load.boardNumber ?? load.name} + – + + {formatKilowatt(load.activePowerKw)} + Automatisch aus der verknüpften Verteilung + + ))} ); } @@ -501,7 +516,7 @@ function BoardPlanSheet({ rows={[ ["Örtlichkeit", [board.location, summary.floorName].filter(Boolean).join(" · ") || "–"], ["Netzart", board.supplyType ?? "–"], - ["Gespeist von", board.fedFrom ?? "–"], + ["Gespeist von", formatFeedingReference(summary)], [ <>Pgl, <> @@ -542,7 +557,7 @@ function BoardPlanSheet({ Summe Verteiler (Pinst {formatKilowatt(summary.installedPowerKw)} kW) - {formatKilowatt(summary.devicePowerKw)} + {formatKilowatt(summary.powerBeforeBoardSimultaneityKw)} diff --git a/tests/print-document-model.test.ts b/tests/print-document-model.test.ts index 80a5200..ba91c3e 100644 --- a/tests/print-document-model.test.ts +++ b/tests/print-document-model.test.ts @@ -2,7 +2,8 @@ import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { assertPrintRevisionConsistency, - buildPreliminaryBoardHierarchy, + buildBoardHierarchy, + formatFeedingReference, formatCircuitCable, formatProtectionDevice, summarizePrintBoard, @@ -27,6 +28,8 @@ function board( location: null, fedFrom: null, remark: null, + feedingDistributionBoardId: null, + feedingCircuitId: null, ...info, }; } @@ -52,6 +55,8 @@ function tree( const total = deviceRows.reduce((sum, row) => sum + row.rowTotalPower, 0); return { circuitListId: "list", + distributionBoardId: "board", + distributionBoardName: "Board", currentRevision: 1, singlePhaseVoltageV: 230, threePhaseVoltageV: 400, @@ -79,7 +84,13 @@ function tree( sortOrder: 1, isReserve: false, circuitTotalPower: total, + circuitApparentPower: deviceRows.reduce( + (sum, row) => sum + row.rowTotalPower / (row.cosPhi || 1), + 0 + ), + circuitCosPhi: 1, deviceRows, + downstreamBoardLoads: [], }, ], }, @@ -117,16 +128,15 @@ describe("print document model", () => { assert.equal(formatCircuitCable(circuit), null); }); - it("does not guess a parent when feed text matches more than one board", () => { + it("does not derive hierarchy from the external free text", () => { const summaries = [ summary("a", { boardNumber: "HV" }, 2), summary("b", { name: "HV" }, 3), summary("uv", { fedFrom: " hv " }, 1), ]; for (const ordered of [summaries, [...summaries].reverse()]) { - const entries = buildPreliminaryBoardHierarchy(ordered); + const entries = buildBoardHierarchy(ordered); assert.ok(entries.every((entry) => entry.parentBoardId === null)); - assert.equal(entries.reduce((sum, entry) => sum + entry.cumulatedDemandPowerKw, 0), 6); } }); @@ -145,17 +155,39 @@ describe("print document model", () => { }); assert.equal(result.circuitCount, 1); assert.equal(result.installedPowerKw, 14); - assert.equal(result.devicePowerKw, 10); + assert.equal(result.powerBeforeBoardSimultaneityKw, 10); assert.equal(result.demandPowerKw, 5); // S = (4 / 0.8 + 6 / 1) × 0.5 = 5.5 kVA → I = 5500 / (√3 · 400) assert.ok(Math.abs(result.designCurrentA - 5500 / (Math.sqrt(3) * 400)) < 1e-9); }); - it("nests boards by matching free-text feed and sums downstream demand", () => { - const entries = buildPreliminaryBoardHierarchy([ + it("uses the selected one-phase feeder circuit for the design current", () => { + const inputTree = tree([ + { quantity: 1, powerPerUnit: 2.3, simultaneityFactor: 1, cosPhi: 1 }, + ]); + inputTree.feedingReference = { + distributionBoardId: "hv", + circuitListId: "hv-list", + distributionBoardName: "Hauptverteilung", + distributionBoardNumber: "NSHV", + circuitId: "out", + circuitEquipmentIdentifier: "-2F1.1", + circuitCategory: "single_phase", + }; + const result = summarizePrintBoard({ + board: board("uv"), + circuitListId: "uv", + floorName: null, + tree: inputTree, + }); + assert.ok(Math.abs(result.designCurrentA - 10) < 1e-9); + }); + + it("nests boards by their logical feeding references", () => { + const entries = buildBoardHierarchy([ summary("hv", { boardNumber: "HV 0.1", fedFrom: "HAK" }, 10), - summary("uv-a", { boardNumber: "UV 1.1", fedFrom: " hv 0.1 " }, 4), - summary("uv-b", { boardNumber: "UV 1.2", fedFrom: "UV 1.1" }, 2), + summary("uv-a", { boardNumber: "UV 1.1", feedingDistributionBoardId: "hv" }, 4), + summary("uv-b", { boardNumber: "UV 1.2", feedingDistributionBoardId: "uv-a" }, 2), summary("uv-c", { name: "UV-C", fedFrom: "unbekannt" }, 1), ]); assert.deepEqual( @@ -163,28 +195,37 @@ describe("print document model", () => { entry.summary.board.id, entry.depth, entry.parentBoardId, - entry.cumulatedDemandPowerKw, ]), [ - ["hv", 0, null, 16], - ["uv-a", 1, "hv", 6], - ["uv-b", 2, "uv-a", 2], - ["uv-c", 0, null, 1], + ["hv", 0, null], + ["uv-a", 1, "hv"], + ["uv-b", 2, "uv-a"], + ["uv-c", 0, null], ] ); }); - it("keeps boards with cyclic feed texts at the top level", () => { - const entries = buildPreliminaryBoardHierarchy([ - summary("a", { boardNumber: "A", fedFrom: "B" }, 1), - summary("b", { boardNumber: "B", fedFrom: "A" }, 1), + it("keeps malformed cyclic logical links visible at the top level", () => { + const entries = buildBoardHierarchy([ + summary("a", { boardNumber: "A", feedingDistributionBoardId: "b" }, 1), + summary("b", { boardNumber: "B", feedingDistributionBoardId: "a" }, 1), ]); assert.equal(entries.length, 2); assert.ok(entries.some((entry) => entry.parentBoardId === null)); - assert.equal( - entries.reduce((sum, entry) => sum + (entry.depth === 0 ? entry.cumulatedDemandPowerKw : 0), 0), - 2 - ); + }); + + it("formats the resolved feeding board and circuit instead of free text", () => { + const value = summary("uv", { fedFrom: "Alttext" }, 1); + value.tree.feedingReference = { + distributionBoardId: "hv", + circuitListId: "hv-list", + distributionBoardName: "Hauptverteilung", + distributionBoardNumber: "NSHV", + circuitId: "out", + circuitEquipmentIdentifier: "-3F1.1", + circuitCategory: "three_phase", + }; + assert.equal(formatFeedingReference(value), "NSHV-3F1.1"); }); it("formats protection devices for the plan table", () => {