74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { createHash } from "node:crypto";
|
|
import { createDefaultExternalCsvConfiguration } from "../src/external-model/csv/external-csv-contracts.js";
|
|
import {
|
|
parseExternalCsv,
|
|
serializeExternalCsv,
|
|
} from "../src/external-model/csv/external-csv-transport.js";
|
|
|
|
const filePath = resolve(
|
|
process.argv[2] ?? "docs/spec/ELT Stromkreisnummernvergabe-Check_DIV.csv"
|
|
);
|
|
const source = readFileSync(filePath);
|
|
const configuration = createDefaultExternalCsvConfiguration({
|
|
ifcGuid: "IfcGUID",
|
|
roomNumber: "MEP-Raum: Nummer",
|
|
roomName: "MEP-Raum: Name",
|
|
familyAndType: "Familie und Typ",
|
|
selectionMarker: "CAx_Auswahlkenner",
|
|
circuitIdentifier: "kbp_Stromkreisnummer",
|
|
power: "kbp-E-Elektrische Leistung",
|
|
quantity: null,
|
|
});
|
|
configuration.additionalSourceMappings = [
|
|
{ sourceColumn: "CAx_Anmerkung", targetField: "sourceRemark" },
|
|
{ sourceColumn: "kbp-E-Spannung", targetField: "sourceVoltage" },
|
|
{ sourceColumn: "kbp-E-Stromstärke", targetField: "sourceCurrent" },
|
|
{ sourceColumn: "kbp-E-Versorgung von ELT", targetField: "sourceElectricalSupply" },
|
|
{ sourceColumn: "kbp-E-Versorgung von MSR/GLT", targetField: "sourceControlSupply" },
|
|
];
|
|
|
|
const document = parseExternalCsv(source, configuration);
|
|
const counts = Object.fromEntries(
|
|
["metadata", "header", "passthrough", "object", "suspect-object"].map(
|
|
(classification) => [
|
|
classification,
|
|
document.rows.filter((row) => row.classification === classification).length,
|
|
]
|
|
)
|
|
);
|
|
const nonEmptyPassthroughRows = document.rows.filter(
|
|
(row) =>
|
|
row.classification === "passthrough" &&
|
|
row.cells.some((cell) => cell.value !== "")
|
|
).length;
|
|
const serialized = serializeExternalCsv(document);
|
|
|
|
assert.equal(counts.object, 897, "Expected 897 object rows.");
|
|
assert.equal(nonEmptyPassthroughRows, 211, "Expected 211 non-empty passthrough rows.");
|
|
assert.equal(counts["suspect-object"], 0, "Expected no suspect object rows.");
|
|
assert.equal(
|
|
Buffer.compare(Buffer.from(serialized), source),
|
|
0,
|
|
"Expected a byte-identical CSV round-trip."
|
|
);
|
|
|
|
const sha256 = createHash("sha256").update(source).digest("hex");
|
|
process.stdout.write(
|
|
`${JSON.stringify(
|
|
{
|
|
file: filePath,
|
|
bytes: source.length,
|
|
sha256,
|
|
dialect: document.dialect,
|
|
rows: counts,
|
|
nonEmptyPassthroughRows,
|
|
roundTripByteIdentical: true,
|
|
},
|
|
null,
|
|
2
|
|
)}\n`
|
|
);
|