[61] Raumprogramm: Soll/Ist-Vergleich mit Ampel, Summen und Export
Rechnung in Rust (core/room_program.rs, Abfrage programCompare): Zuordnung der gezeichneten Räume über den Namen (genaue Treffer vor Präfix, ohne Gross-/ Kleinschreibung und Nummern), Soll = Anzahl x Fläche, Ist, Differenz absolut und in %, Summen je Gruppe, je Flächenart und total, Ampel mit einstellbarer Toleranz (Projekt, Standard +-5 %). checkRoomProgram ist jetzt eine Fassade darüber (Standard-Toleranz damit 5 statt 10 %; Rust-Fassung ersetzt die TS- Rechnung). Tabelle im Raumprogramm-Bereich, Export CSV/PDF aus demselben Berichtsmodell wie die Flächentabelle (export/programReport.ts). Die Anordnung der Soll-Räume (programLayout, 4:3, Shelf-Packing) liegt im selben Rust-Modul und wird im nächsten Commit angebunden. Geprüft: cargo test core (8 neue Tests), vitest, Browser-Build mit Playwright. Nicht in der Tauri-App getestet. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
15 files changed
+1230
-36
No files matched your search
@@ -10,10 +10,11 @@
|
||||
// Rust-Kern auf dem Projekt-Dokument (`src-tauri/core/src/kennzahlen.rs`).
|
||||
|
||||
import type { ExtrudedSolid, Project } from "../model/types";
|
||||
import { polygonArea } from "../geometry/roomArea";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { FlatWriter } from "../geometry/coreFlat";
|
||||
import { documentFor } from "../core/document";
|
||||
import { compareRoomProgram } from "./roomProgram";
|
||||
import type { ProgramStatus } from "./roomProgram";
|
||||
|
||||
export interface LevelKennzahlen {
|
||||
levelId: string;
|
||||
@@ -44,8 +45,6 @@ export function solidVolume(s: ExtrudedSolid): number {
|
||||
return core().kz_solid_volume(new FlatWriter().pts(s.circle ? [] : s.points).done(), s.circle ? s.circle.r : Number.NaN, s.height, s.taper ?? 0);
|
||||
}
|
||||
|
||||
const finite = (n: number): number => (Number.isFinite(n) ? n : 0);
|
||||
|
||||
/**
|
||||
* Flächen je Geschoss (SIA 416), Gebäudevolumen, Ausnützungs- und Überbauungsziffer. Rechnet der
|
||||
* Kern auf dem Projekt-Dokument (`kennzahlen.rs`, [K4] S2).
|
||||
@@ -54,7 +53,7 @@ export function computeKennzahlen(project: Project): Kennzahlen {
|
||||
return documentFor(project).query<Kennzahlen>("kennzahlen");
|
||||
}
|
||||
|
||||
export type ProgramStatus = "ok" | "zu klein" | "zu gross" | "fehlt" | "zu wenige" | "zu viele";
|
||||
export type { ProgramStatus } from "./roomProgram";
|
||||
|
||||
export interface ProgramRowResult {
|
||||
name: string;
|
||||
@@ -72,31 +71,11 @@ export interface ProgramCheck {
|
||||
extra: Array<{ id: string; name: string; area: number }>;
|
||||
}
|
||||
|
||||
/** Toleranz der Flächenprüfung (relativ zur Soll-Fläche). */
|
||||
const AREA_TOL = 0.1;
|
||||
|
||||
const norm = (s: string) => s.trim().toLowerCase();
|
||||
|
||||
/** Prüft das Raumprogramm: Räume werden über den Namen (Präfix, ohne Gross-/Kleinschreibung) zugeordnet. */
|
||||
/** Prüft das Raumprogramm: Räume werden über den Namen zugeordnet. Rechnet der Kern (`room_program.rs`, Toleranz `Project.roomProgramTolerance`). */
|
||||
export function checkRoomProgram(project: Project): ProgramCheck {
|
||||
const rooms = (project.rooms ?? []).map((r) => ({ id: r.id, name: r.name, cat: r.siaCategory, area: finite(polygonArea(r.boundary)) }));
|
||||
const used = new Set<string>();
|
||||
const rows: ProgramRowResult[] = (project.roomProgram ?? []).map((row) => {
|
||||
const n = norm(row.name);
|
||||
// Leerer Name (Zeile im Editor noch unfertig) trifft nichts — „" wäre Präfix jedes Raums.
|
||||
const hits = rooms.filter((r) => n !== "" && !used.has(r.id) && norm(r.name).startsWith(n) && (!row.siaCategory || r.cat === row.siaCategory));
|
||||
hits.forEach((h) => used.add(h.id));
|
||||
const targetCount = Math.max(1, row.count ?? 1);
|
||||
const area = hits.reduce((s, h) => s + h.area, 0);
|
||||
const target = row.area * targetCount;
|
||||
let status: ProgramStatus;
|
||||
if (hits.length === 0) status = "fehlt";
|
||||
else if (hits.length < targetCount) status = "zu wenige";
|
||||
else if (hits.length > targetCount) status = "zu viele";
|
||||
else if (area < target * (1 - AREA_TOL)) status = "zu klein";
|
||||
else if (area > target * (1 + AREA_TOL)) status = "zu gross";
|
||||
else status = "ok";
|
||||
return { name: row.name, targetArea: row.area, targetCount, count: hits.length, area, status };
|
||||
});
|
||||
return { rows, extra: rooms.filter((r) => !used.has(r.id)).map((r) => ({ id: r.id, name: r.name, area: r.area })) };
|
||||
const c = compareRoomProgram(project);
|
||||
return {
|
||||
rows: c.rows.map((r) => ({ name: r.name, targetArea: r.targetArea, targetCount: r.targetCount, count: r.count, area: r.ist, status: r.status })),
|
||||
extra: c.extra,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
import { compareRoomProgram } from "./roomProgram";
|
||||
|
||||
const sq = (x: number, y: number, s: number) => [
|
||||
{ x, y }, { x: x + s, y }, { x: x + s, y: y + s }, { x, y: y + s },
|
||||
];
|
||||
const base = (sampleProject.rooms ?? [])[0]!;
|
||||
|
||||
const withProgram = (): Project => ({
|
||||
...sampleProject,
|
||||
rooms: [
|
||||
{ ...base, id: "r1", name: "Wohnen 1", boundary: sq(0, 0, 5) },
|
||||
{ ...base, id: "r2", name: "Bad", boundary: sq(10, 0, 2) },
|
||||
],
|
||||
roomProgram: [
|
||||
{ name: "Wohnen", area: 25, group: "Tag" },
|
||||
{ name: "Bad", area: 5, group: "Nacht" },
|
||||
{ name: "Zimmer", area: 12, count: 3, group: "Nacht" },
|
||||
],
|
||||
});
|
||||
|
||||
describe("compareRoomProgram", () => {
|
||||
it("Soll, Ist, Differenz, Ampel und Summen", () => {
|
||||
const c = compareRoomProgram(withProgram());
|
||||
expect(c.tolerance).toBe(0.05);
|
||||
expect(c.rows.map((r) => r.status)).toEqual(["ok", "zu klein", "fehlt"]);
|
||||
expect(c.rows[1].diff).toBeCloseTo(-1, 9);
|
||||
expect(c.rows[1].diffPct).toBeCloseTo(-0.2, 9);
|
||||
expect(c.rows.map((r) => r.light)).toEqual(["green", "red", "red"]);
|
||||
expect(c.total.soll).toBeCloseTo(25 + 5 + 36, 9);
|
||||
expect(c.total.ist).toBeCloseTo(29, 9);
|
||||
expect(c.groups.map((g) => g.key)).toEqual(["Tag", "Nacht"]);
|
||||
});
|
||||
it("Toleranz aus dem Projekt", () => {
|
||||
const c = compareRoomProgram({ ...withProgram(), roomProgramTolerance: 0.25 });
|
||||
expect(c.rows[1].status).toBe("ok");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,106 @@
|
||||
// Raumprogramm ([61]): Soll/Ist-Vergleich und Anordnung der Soll-Räume. Rechnet der Kern auf dem
|
||||
// Projekt-Dokument (`src-tauri/core/src/room_program.rs`; Zuordnung, Ampel und Packing stehen dort).
|
||||
// Diese Datei ist nur die typisierte Fassade.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
export type ProgramStatus = "ok" | "zu klein" | "zu gross" | "fehlt" | "zu wenige" | "zu viele";
|
||||
export type Light = "green" | "yellow" | "red" | "grey";
|
||||
|
||||
export interface CompareRow {
|
||||
/** Index der Programmzeile. */
|
||||
index: number;
|
||||
name: string;
|
||||
group: string | null;
|
||||
/** Flächenart (SIA-416-Kürzel). */
|
||||
kind: string | null;
|
||||
targetCount: number;
|
||||
/** Soll-Fläche je Raum (m²). */
|
||||
targetArea: number;
|
||||
/** Soll gesamt = Anzahl × Fläche. */
|
||||
soll: number;
|
||||
/** Zugeordnete Räume im Modell. */
|
||||
count: number;
|
||||
ist: number;
|
||||
diff: number;
|
||||
/** Differenz relativ zum Soll; `null` bei Soll 0. */
|
||||
diffPct: number | null;
|
||||
status: ProgramStatus;
|
||||
light: Light;
|
||||
}
|
||||
|
||||
export interface CompareSum {
|
||||
/** Gruppe bzw. Flächenart; leer = ohne Angabe. */
|
||||
key: string;
|
||||
rows: number;
|
||||
soll: number;
|
||||
ist: number;
|
||||
diff: number;
|
||||
diffPct: number | null;
|
||||
light: Light;
|
||||
}
|
||||
|
||||
export interface RoomProgramCompare {
|
||||
/** Toleranz als Anteil (0.05 = ±5 %). */
|
||||
tolerance: number;
|
||||
rows: CompareRow[];
|
||||
groups: CompareSum[];
|
||||
kinds: CompareSum[];
|
||||
total: CompareSum;
|
||||
/** Räume im Modell ohne Programmzeile. */
|
||||
extra: Array<{ id: string; name: string; area: number }>;
|
||||
extraArea: number;
|
||||
}
|
||||
|
||||
/** Standard-Toleranz der Ampel (Anteil der Soll-Fläche). */
|
||||
export const DEFAULT_PROGRAM_TOLERANCE = 0.05;
|
||||
|
||||
/** Soll/Ist-Vergleich des Raumprogramms mit den gezeichneten Räumen. */
|
||||
export function compareRoomProgram(project: Project): RoomProgramCompare {
|
||||
return documentFor(project).query<RoomProgramCompare>("programCompare");
|
||||
}
|
||||
|
||||
export interface LayoutOptions {
|
||||
/** Abstand zwischen den Rechtecken (m, Default 1). */
|
||||
gap?: number;
|
||||
/** Höhe des Titelbereichs je Gruppe (m, Default 1.6). */
|
||||
titleHeight?: number;
|
||||
}
|
||||
|
||||
export interface LayoutItem {
|
||||
row: number;
|
||||
copy: number;
|
||||
name: string;
|
||||
groupIndex: number;
|
||||
area: number;
|
||||
/** Linke untere Ecke, Breite (x) und Tiefe (y) in Metern. */
|
||||
x: number;
|
||||
y: number;
|
||||
w: number;
|
||||
d: number;
|
||||
}
|
||||
|
||||
export interface LayoutGroup {
|
||||
index: number;
|
||||
/** Leer = ohne Titel. */
|
||||
name: string;
|
||||
x: number;
|
||||
y: number;
|
||||
w: number;
|
||||
titleHeight: number;
|
||||
area: number;
|
||||
}
|
||||
|
||||
export interface RoomProgramLayout {
|
||||
items: LayoutItem[];
|
||||
groups: LayoutGroup[];
|
||||
width: number;
|
||||
height: number;
|
||||
skipped: number;
|
||||
}
|
||||
|
||||
/** Soll-Räume als Rechtecke 4 : 3 mit exakter Fläche, nach Gruppe geordnet und in Reihen gepackt. */
|
||||
export function layoutRoomProgram(project: Project, opts: LayoutOptions = {}): RoomProgramLayout {
|
||||
return documentFor(project).query<RoomProgramLayout>("programLayout", [], JSON.stringify(opts));
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import type { CoreOp } from "./ops";
|
||||
export type QueryName =
|
||||
| "kennzahlen"
|
||||
| "areaTable"
|
||||
| "programCompare"
|
||||
| "programLayout"
|
||||
| "ivhb"
|
||||
| "siteCheck"
|
||||
| "buildingFootprint"
|
||||
|
||||
@@ -24,8 +24,11 @@ export type { CoreOp } from "./ops";
|
||||
export type { Project, DrawingLevel } from "../model/types";
|
||||
export { computeKennzahlen, checkRoomProgram, solidVolume } from "../analysis/kennzahlen";
|
||||
export type { Kennzahlen, ProgramCheck } from "../analysis/kennzahlen";
|
||||
export { compareRoomProgram, layoutRoomProgram, DEFAULT_PROGRAM_TOLERANCE } from "../analysis/roomProgram";
|
||||
export type { RoomProgramCompare, RoomProgramLayout, CompareRow, CompareSum, Light, LayoutItem, LayoutGroup } from "../analysis/roomProgram";
|
||||
export { readSheetFile, suggestMapping, mapRows, importedRows, applyRoomProgram, cellNumber, cellText, detectHeaderRow, parseKind, PROGRAM_FIELDS } from "../io/roomProgramImport";
|
||||
export type { SheetData, SheetCell, Mapping, ColumnMap, ProgramField, ImportLine, ImportMode, SkipReason } from "../io/roomProgramImport";
|
||||
export { buildProgramReport } from "../export/programReport";
|
||||
export { computeAreaTable, computeIvhb } from "../analysis/areaTable";
|
||||
export type { AreaTable, AreaRow, Ivhb, IvhbOptions, AgfBasis } from "../analysis/areaTable";
|
||||
export { buildAreaReport, areaReportToCsv, parseAreaReportCsv, areaReportToSvg, buildAreaReportPdf } from "../export/areaReport";
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
import { areaReportToCsv, parseAreaReportCsv } from "./areaReport";
|
||||
import { buildProgramReport } from "./programReport";
|
||||
|
||||
const sq = (x: number, y: number, s: number) => [
|
||||
{ x, y }, { x: x + s, y }, { x: x + s, y: y + s }, { x, y: y + s },
|
||||
];
|
||||
const base = (sampleProject.rooms ?? [])[0]!;
|
||||
|
||||
const p: Project = {
|
||||
...sampleProject,
|
||||
name: "Test",
|
||||
rooms: [
|
||||
{ ...base, id: "r1", name: "Wohnen", boundary: sq(0, 0, 5) },
|
||||
{ ...base, id: "r2", name: "Bad", boundary: sq(10, 0, 2) },
|
||||
{ ...base, id: "r3", name: "Keller", boundary: sq(20, 0, 2) },
|
||||
],
|
||||
roomProgram: [
|
||||
{ name: "Wohnen", area: 25, group: "Tag", siaCategory: "HNF" },
|
||||
{ name: "Bad", area: 5, group: "Nacht", siaCategory: "HNF" },
|
||||
{ name: "Büro", area: 12, group: "Nacht" },
|
||||
],
|
||||
};
|
||||
|
||||
describe("buildProgramReport", () => {
|
||||
const r = buildProgramReport(p);
|
||||
it("Tabelle je Raum mit Total, Gruppen und Flächenarten", () => {
|
||||
expect(r.sections.map((s) => s.rows.length)).toEqual([4, 2, 2]);
|
||||
const total = r.sections[0].rows[3];
|
||||
expect(total.total).toBe(true);
|
||||
expect(total.cells[5]).toEqual({ n: 42, d: 2 });
|
||||
expect(total.cells[7]).toEqual({ n: 29, d: 2 });
|
||||
expect(r.notes.some((n) => n.includes("Keller") || n.includes("1"))).toBe(true);
|
||||
});
|
||||
it("CSV-Rundreise: Zahlen so wie ausgegeben", () => {
|
||||
const back = parseAreaReportCsv(areaReportToCsv(r));
|
||||
expect(back.sections).toHaveLength(3);
|
||||
expect(back.sections[0].rows[1][8]).toBe(-1); // Bad: 4 − 5
|
||||
expect(back.sections[0].rows[1][9]).toBe(-20); // −20.0 %
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
// Soll/Ist-Nachweis des Raumprogramms ([61]): derselbe Berichtsaufbau wie der Flächennachweis
|
||||
// (`areaReport.ts`), damit CSV, SVG und PDF dieselbe Quelle und denselben Seitenaufbau haben.
|
||||
// Die Zahlen rechnet der Kern (`analysis/roomProgram.ts`); hier nur die Beschriftung mit `t()`.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { compareRoomProgram } from "../analysis/roomProgram";
|
||||
import type { CompareSum, Light } from "../analysis/roomProgram";
|
||||
import type { AreaReport, Cell, ReportRow, ReportSection } from "./areaReport";
|
||||
|
||||
const num = (n: number | null, d: number): Cell => ({ n: n !== null && Number.isFinite(n) ? n : null, d });
|
||||
const pct = (p: number | null): Cell => num(p === null ? null : p * 100, 1);
|
||||
|
||||
const STATUS_KEY = {
|
||||
ok: "program.status.ok",
|
||||
"zu klein": "program.status.tooSmall",
|
||||
"zu gross": "program.status.tooLarge",
|
||||
fehlt: "program.status.missing",
|
||||
"zu wenige": "program.status.tooFew",
|
||||
"zu viele": "program.status.tooMany",
|
||||
} as const;
|
||||
|
||||
const lightText = (l: Light): string => t(`program.report.light.${l}`);
|
||||
|
||||
function sumRows(sums: CompareSum[], emptyLabel: string): ReportRow[] {
|
||||
return sums.map((s) => ({ cells: [s.key || emptyLabel, num(s.soll, 2), num(s.ist, 2), num(s.diff, 2), pct(s.diffPct), lightText(s.light)] }));
|
||||
}
|
||||
|
||||
/** Bericht „Raumprogramm Soll/Ist": Tabelle je Raum mit Total, Summen je Gruppe und je Flächenart. */
|
||||
export function buildProgramReport(project: Project): AreaReport {
|
||||
const c = compareRoomProgram(project);
|
||||
const sections: ReportSection[] = [];
|
||||
const rows: ReportRow[] = c.rows.map((r) => ({
|
||||
cells: [
|
||||
r.name,
|
||||
r.group ?? "",
|
||||
r.kind ?? "",
|
||||
num(r.targetCount, 0),
|
||||
num(r.targetArea, 2),
|
||||
num(r.soll, 2),
|
||||
num(r.count, 0),
|
||||
num(r.ist, 2),
|
||||
num(r.diff, 2),
|
||||
pct(r.diffPct),
|
||||
`${t(STATUS_KEY[r.status])} (${lightText(r.light)})`,
|
||||
],
|
||||
}));
|
||||
rows.push({ total: true, cells: [t("program.compare.total"), "", "", "", "", num(c.total.soll, 2), "", num(c.total.ist, 2), num(c.total.diff, 2), pct(c.total.diffPct), lightText(c.total.light)] });
|
||||
sections.push({
|
||||
heading: t("program.report.table"),
|
||||
columns: [
|
||||
t("program.compare.col.name"),
|
||||
t("program.field.group"),
|
||||
t("program.field.kind"),
|
||||
t("program.field.count"),
|
||||
t("program.field.area"),
|
||||
t("program.compare.col.soll"),
|
||||
t("program.compare.col.count"),
|
||||
t("program.compare.col.ist"),
|
||||
t("program.compare.col.diff"),
|
||||
t("program.compare.col.pct"),
|
||||
t("program.compare.col.status"),
|
||||
],
|
||||
widths: [3.2, 2.2, 1.4, 1.2, 1.6, 1.6, 1.2, 1.6, 1.6, 1.4, 3.4],
|
||||
rows,
|
||||
});
|
||||
const sumColumns = (first: string) => [first, t("program.compare.col.soll"), t("program.compare.col.ist"), t("program.compare.col.diff"), t("program.compare.col.pct"), t("program.compare.col.status")];
|
||||
const sumWidths = [4, 1.6, 1.6, 1.6, 1.4, 2.4];
|
||||
if (c.groups.some((g) => g.key !== "")) {
|
||||
sections.push({ heading: t("program.compare.groups"), columns: sumColumns(t("program.field.group")), widths: sumWidths, rows: sumRows(c.groups, t("program.compare.noGroup")) });
|
||||
}
|
||||
if (c.kinds.some((k) => k.key !== "")) {
|
||||
sections.push({ heading: t("program.compare.kinds"), columns: sumColumns(t("program.field.kind")), widths: sumWidths, rows: sumRows(c.kinds, t("program.compare.noKind")) });
|
||||
}
|
||||
const notes = [t("program.report.note.tolerance", { pct: (c.tolerance * 100).toFixed(0), pct2: (c.tolerance * 200).toFixed(0) })];
|
||||
if (c.kinds.some((k) => k.key !== "")) notes.push(t("program.report.note.sia"));
|
||||
if (c.extra.length > 0) notes.push(t("program.compare.extra", { n: c.extra.length, area: c.extraArea.toFixed(1) }));
|
||||
return { title: t("program.report.title"), projectName: project.name ?? "", sections, notes };
|
||||
}
|
||||
@@ -2028,6 +2028,37 @@ export const de = {
|
||||
"program.import.readFail": "Die Tabelle konnte nicht gelesen werden: {msg}",
|
||||
"program.import.empty": "Die Datei enthält keine Zellen.",
|
||||
"program.import.done": "{n} Programmzeilen importiert.",
|
||||
"program.compare.title": "Soll / Ist",
|
||||
"program.compare.col.name": "Raum",
|
||||
"program.compare.col.count": "Anz. Ist/Soll",
|
||||
"program.compare.col.soll": "Soll m²",
|
||||
"program.compare.col.ist": "Ist m²",
|
||||
"program.compare.col.diff": "Diff. m²",
|
||||
"program.compare.col.pct": "Diff. %",
|
||||
"program.compare.col.status": "Stand",
|
||||
"program.compare.groups": "Summe je Gruppe",
|
||||
"program.compare.kinds": "Summe je Flächenart",
|
||||
"program.compare.total": "Total",
|
||||
"program.compare.noGroup": "ohne Gruppe",
|
||||
"program.compare.noKind": "ohne Flächenart",
|
||||
"program.compare.extra": "Räume ohne Programmzeile: {n}, {area} m²",
|
||||
"program.compare.tolerance": "Toleranz ±",
|
||||
"program.compare.tolerance.hint": "Abweichung der Ist- von der Soll-Fläche: grün innerhalb der Toleranz, gelb bis zum Doppelten, darüber rot.",
|
||||
"program.compare.light.green": "innerhalb der Toleranz",
|
||||
"program.compare.light.yellow": "bis zur doppelten Toleranz",
|
||||
"program.compare.light.red": "ausserhalb der Toleranz",
|
||||
"program.compare.light.grey": "kein Soll",
|
||||
"program.compare.exportCsv": "CSV",
|
||||
"program.compare.exportPdf": "PDF",
|
||||
"program.compare.exportPdf.fail": "PDF konnte nicht erstellt werden.",
|
||||
"program.report.title": "Raumprogramm Soll/Ist",
|
||||
"program.report.table": "Soll/Ist je Raum [m²]",
|
||||
"program.report.note.tolerance": "Ampel: ok bis ±{pct} %, Warnung bis ±{pct2} %, darüber Abweichung. Zuordnung der Räume über den Namen.",
|
||||
"program.report.note.sia": "Flächenarten nach SIA 416.",
|
||||
"program.report.light.green": "ok",
|
||||
"program.report.light.yellow": "Warnung",
|
||||
"program.report.light.red": "Abweichung",
|
||||
"program.report.light.grey": "–",
|
||||
"sun.show": "Schatten im Grundriss zeigen",
|
||||
"sun.time": "Uhrzeit",
|
||||
"sun.equinox": "Tagundnachtgleiche",
|
||||
|
||||
@@ -1978,6 +1978,37 @@ export const en: Record<TranslationKey, string> = {
|
||||
"program.import.readFail": "The spreadsheet could not be read: {msg}",
|
||||
"program.import.empty": "The file contains no cells.",
|
||||
"program.import.done": "{n} program rows imported.",
|
||||
"program.compare.title": "Target / actual",
|
||||
"program.compare.col.name": "Room",
|
||||
"program.compare.col.count": "Count act./target",
|
||||
"program.compare.col.soll": "Target m²",
|
||||
"program.compare.col.ist": "Actual m²",
|
||||
"program.compare.col.diff": "Diff. m²",
|
||||
"program.compare.col.pct": "Diff. %",
|
||||
"program.compare.col.status": "Status",
|
||||
"program.compare.groups": "Totals per group",
|
||||
"program.compare.kinds": "Totals per area type",
|
||||
"program.compare.total": "Total",
|
||||
"program.compare.noGroup": "no group",
|
||||
"program.compare.noKind": "no area type",
|
||||
"program.compare.extra": "Rooms without a program row: {n}, {area} m²",
|
||||
"program.compare.tolerance": "Tolerance ±",
|
||||
"program.compare.tolerance.hint": "Deviation of actual from target area: green within the tolerance, yellow up to twice that, red beyond.",
|
||||
"program.compare.light.green": "within tolerance",
|
||||
"program.compare.light.yellow": "up to twice the tolerance",
|
||||
"program.compare.light.red": "outside tolerance",
|
||||
"program.compare.light.grey": "no target",
|
||||
"program.compare.exportCsv": "CSV",
|
||||
"program.compare.exportPdf": "PDF",
|
||||
"program.compare.exportPdf.fail": "Could not create the PDF.",
|
||||
"program.report.title": "Room program target/actual",
|
||||
"program.report.table": "Target/actual per room [m²]",
|
||||
"program.report.note.tolerance": "Traffic light: ok up to ±{pct} %, warning up to ±{pct2} %, beyond that deviation. Rooms are matched by name.",
|
||||
"program.report.note.sia": "Area types according to SIA 416.",
|
||||
"program.report.light.green": "ok",
|
||||
"program.report.light.yellow": "warning",
|
||||
"program.report.light.red": "deviation",
|
||||
"program.report.light.grey": "–",
|
||||
"sun.show": "Show shadows in plan",
|
||||
"sun.time": "Time of day",
|
||||
"sun.equinox": "Equinox",
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useStore } from "../state/appStore";
|
||||
import { checkRoomProgram, computeKennzahlen, polygonArea } from "../core";
|
||||
import type { Project, RoomProgramRow } from "../model/types";
|
||||
import { RoomProgramImportButton } from "../ui/RoomProgramImportDialog";
|
||||
import { ProgramCompareSection } from "./ProgramCompareSection";
|
||||
|
||||
type ProgramStatus = ReturnType<typeof checkRoomProgram>["rows"][number]["status"];
|
||||
|
||||
@@ -183,11 +184,7 @@ export function KennzahlenSection() {
|
||||
</button>
|
||||
<RoomProgramImportButton project={project} onApply={(fn) => setProject(fn)} notify={notify} />
|
||||
</div>
|
||||
{rows.length > 0 && prog.extra.length > 0 && (
|
||||
<div className="kz-extra" title={prog.extra.map((r) => r.name).join(", ")}>
|
||||
{t("program.extra", { n: prog.extra.length })}
|
||||
</div>
|
||||
)}
|
||||
{rows.length > 0 && <ProgramCompareSection statusLabel={programStatusLabel} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
// Soll/Ist-Vergleich des Raumprogramms und „Räume generieren" ([61]) im Flächenbilanz-Panel.
|
||||
//
|
||||
// • Tabelle: Soll (Anzahl × Fläche), Ist (aus den gezeichneten Räumen, Zuordnung über den Namen),
|
||||
// Differenz absolut und in %, Ampel; darunter Summen je Gruppe, je Flächenart und gesamt.
|
||||
// • Toleranz der Ampel (Standard ±5 %) liegt im Projekt (`roomProgramTolerance`).
|
||||
// • Export CSV/PDF aus demselben Berichtsmodell (`export/programReport.ts`).
|
||||
// Herleitung der Zahlen: `src-tauri/core/src/room_program.rs`.
|
||||
|
||||
import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
import { usePanelHost } from "./host";
|
||||
import { useStore } from "../state/appStore";
|
||||
import { areaReportToCsv, buildAreaReportPdf, buildProgramReport, compareRoomProgram, DEFAULT_PROGRAM_TOLERANCE } from "../core";
|
||||
import type { CompareRow, CompareSum, Light } from "../core";
|
||||
import type { Project } from "../model/types";
|
||||
import { downloadCsv } from "./downloadFile";
|
||||
|
||||
const fmt = (n: number, d = 1) => n.toLocaleString("de-CH", { minimumFractionDigits: d, maximumFractionDigits: d });
|
||||
/** Mit Vorzeichen; was auf die angezeigte Stelle zu 0 rundet, bleibt ohne Vorzeichen. */
|
||||
const signed = (n: number, d = 1) => (Math.abs(n) < 0.5 * 10 ** -d ? fmt(0, d) : (n > 0 ? "+" : "−") + fmt(Math.abs(n), d));
|
||||
|
||||
function Dot({ light }: { light: Light }) {
|
||||
return <span className={`pc-dot ${light}`} title={t(`program.compare.light.${light}` as TranslationKey)} role="img" aria-label={t(`program.compare.light.${light}` as TranslationKey)} />;
|
||||
}
|
||||
|
||||
function SumRow({ s, label, total }: { s: CompareSum; label: string; total?: boolean }) {
|
||||
return (
|
||||
<tr className={total ? "total" : ""}>
|
||||
<td colSpan={2}>
|
||||
<Dot light={s.light} /> {label}
|
||||
</td>
|
||||
<td className="num">{fmt(s.soll)}</td>
|
||||
<td className="num">{fmt(s.ist)}</td>
|
||||
<td className="num">{signed(s.diff)}</td>
|
||||
<td className="num">{s.diffPct === null ? "–" : signed(s.diffPct * 100)}</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
export function ProgramCompareSection({ statusLabel }: { statusLabel: (status: CompareRow["status"]) => string }) {
|
||||
const host = usePanelHost();
|
||||
const project = host.project;
|
||||
const setProject = useStore((s) => s.setProject);
|
||||
const notify = useStore((s) => s.notify);
|
||||
const c = compareRoomProgram(project);
|
||||
if (c.rows.length === 0) return null;
|
||||
const stem = `${project.name || "projekt"}-raumprogramm`;
|
||||
const hasGroups = c.groups.some((g) => g.key !== "");
|
||||
const hasKinds = c.kinds.some((k) => k.key !== "");
|
||||
|
||||
const setTolerance = (text: string) => {
|
||||
const v = Number(text.trim().replace(",", "."));
|
||||
setProject((p: Project) => {
|
||||
const { roomProgramTolerance: _old, ...rest } = p;
|
||||
return text.trim() !== "" && Number.isFinite(v) && v >= 0 && v <= 100 ? { ...rest, roomProgramTolerance: v / 100 } : rest;
|
||||
}, "roomProgramTolerance");
|
||||
};
|
||||
|
||||
const exportPdf = () => {
|
||||
try {
|
||||
buildAreaReportPdf(buildProgramReport(project)).save(`${stem}.pdf`);
|
||||
} catch {
|
||||
notify(t("program.compare.exportPdf.fail"));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="pc-section">
|
||||
<div className="balance-head">
|
||||
<span className="balance-section-label">{t("program.compare.title")}</span>
|
||||
<span className="area-actions">
|
||||
<button type="button" className="balance-export" onClick={() => downloadCsv(`${stem}.csv`, areaReportToCsv(buildProgramReport(project)))}>
|
||||
{t("program.compare.exportCsv")}
|
||||
</button>
|
||||
<button type="button" className="balance-export" onClick={exportPdf}>
|
||||
{t("program.compare.exportPdf")}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<label className="kz-parcel" title={t("program.compare.tolerance.hint")}>
|
||||
<span>{t("program.compare.tolerance")}</span>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step={1}
|
||||
className="kz-input kz-num"
|
||||
value={project.roomProgramTolerance !== undefined ? String(Math.round(project.roomProgramTolerance * 1000) / 10) : ""}
|
||||
placeholder={String(DEFAULT_PROGRAM_TOLERANCE * 100)}
|
||||
onChange={(e) => setTolerance(e.target.value)}
|
||||
/>
|
||||
<span>%</span>
|
||||
</label>
|
||||
|
||||
<div className="area-scroll">
|
||||
<table className="area-table pc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{t("program.compare.col.name")}</th>
|
||||
<th className="num" title={t("program.compare.col.count")}>{t("program.count")}</th>
|
||||
<th className="num">{t("program.compare.col.soll")}</th>
|
||||
<th className="num">{t("program.compare.col.ist")}</th>
|
||||
<th className="num">{t("program.compare.col.diff")}</th>
|
||||
<th className="num">{t("program.compare.col.pct")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{c.rows.map((r) => (
|
||||
<tr key={r.index} title={statusLabel(r.status)}>
|
||||
<td>
|
||||
<Dot light={r.light} /> {r.name || "–"}
|
||||
</td>
|
||||
<td className="num">
|
||||
{r.count}/{r.targetCount}
|
||||
</td>
|
||||
<td className="num">{fmt(r.soll)}</td>
|
||||
<td className="num">{fmt(r.ist)}</td>
|
||||
<td className="num">{signed(r.diff)}</td>
|
||||
<td className="num">{r.diffPct === null ? "–" : signed(r.diffPct * 100)}</td>
|
||||
</tr>
|
||||
))}
|
||||
{hasGroups && (
|
||||
<>
|
||||
<tr className="pc-sub">
|
||||
<td colSpan={6}>{t("program.compare.groups")}</td>
|
||||
</tr>
|
||||
{c.groups.map((g) => (
|
||||
<SumRow key={"g" + g.key} s={g} label={g.key || t("program.compare.noGroup")} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
{hasKinds && (
|
||||
<>
|
||||
<tr className="pc-sub">
|
||||
<td colSpan={6}>{t("program.compare.kinds")}</td>
|
||||
</tr>
|
||||
{c.kinds.map((k) => (
|
||||
<SumRow key={"k" + k.key} s={k} label={k.key || t("program.compare.noKind")} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
<SumRow s={c.total} label={t("program.compare.total")} total />
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{c.extra.length > 0 && <div className="kz-extra">{t("program.compare.extra", { n: c.extra.length, area: fmt(c.extraArea) })}</div>}
|
||||
{hasKinds && <div className="kz-extra">{t("program.report.note.sia")}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -8424,6 +8424,11 @@ body {
|
||||
}
|
||||
|
||||
/* Punktwolken-Import ([27]): Bericht im Dialog kompakt wie die übrigen Hinweise. */
|
||||
.pc-report {
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--ink-2);
|
||||
}
|
||||
|
||||
.bcf-vps {
|
||||
display: flex;
|
||||
@@ -8559,6 +8564,51 @@ body {
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
.pc-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.pc-table {
|
||||
font-size: 10px;
|
||||
}
|
||||
.pc-table td,
|
||||
.pc-table th {
|
||||
white-space: nowrap;
|
||||
padding: 2px 3px;
|
||||
}
|
||||
.pc-table td:first-child {
|
||||
max-width: 120px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.pc-table tr.pc-sub td {
|
||||
font-weight: 600;
|
||||
font-size: 10px;
|
||||
color: var(--ink-2);
|
||||
padding-top: 6px;
|
||||
}
|
||||
.pc-dot {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: var(--ink-2);
|
||||
vertical-align: middle;
|
||||
}
|
||||
.pc-dot.green {
|
||||
background: var(--ok, #2f8f4e);
|
||||
}
|
||||
.pc-dot.yellow {
|
||||
background: #e0a800;
|
||||
}
|
||||
.pc-dot.red {
|
||||
background: var(--danger, #c0392b);
|
||||
}
|
||||
.pc-dot.grey {
|
||||
background: var(--line, #999);
|
||||
}
|
||||
.rpi-dialog {
|
||||
width: min(880px, 94vw);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user