Skip to content

Commit

Permalink
tulletall
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend29 committed Jan 30, 2024
1 parent 2b6f475 commit 72d4e40
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,54 @@ import { useCallback, useEffect, useState } from "react";
//@ts-ignore
import { FunctionBreakdownMetric } from "forma-embedded-view-sdk/dist/internal/areaMetrics";

let csvHeader = "data:text/csv;charset=utf-8,Metric name;Value";
const line = "1;2;3;4;5;6";
let csvHeader = "data:text/csv;charset=utf-8,Metric name;Total Value";
let gfa = "GFA";
let buildingCoverage = "Building Coverage";
let siteArea = "Site Area";
let unitCount = "Number of units";

export function App() {
const [metrics, setMetrics] = useState<any>();
useEffect(() => {
Forma.areaMetrics.calculate({}).then((theMetrics) => {
console.log("theMetrics", theMetrics);
setMetrics(theMetrics);
siteArea = siteArea + ";" + theMetrics.builtInMetrics.siteArea.value;
unitCount = unitCount + ";" + theMetrics.unitStatistics.count.value;
const totalGfa =
theMetrics.builtInMetrics.grossFloorArea.functionBreakdown.reduce(
(totalGfa, { value }) => {
if (value === "UNABLE_TO_CALCULATE") return totalGfa;
return value + totalGfa;
},
0,
);
gfa = gfa + ";" + totalGfa;
buildingCoverage =
buildingCoverage +
";" +
theMetrics.builtInMetrics.buildingCoverage.value;
theMetrics.builtInMetrics.grossFloorArea.functionBreakdown.forEach(
({ functionName }) => {
csvHeader = csvHeader + ";" + (functionName || "Unamed function");
({ functionName, value }) => {
csvHeader = csvHeader + ";" + (functionName || "Unnamed function");
gfa = gfa + ";" + value;
},
);
});
}, []);

const onClick = useCallback(() => {
const csvUri = encodeURI(csvHeader + "\r\n" + line);
const csvUri = encodeURI(
csvHeader +
"\r\n" +
gfa +
"\r\n" +
buildingCoverage +
"\r\n" +
siteArea +
"\r\n" +
unitCount,
);
window.open(csvUri);
}, [metrics]);

Expand Down

0 comments on commit 72d4e40

Please sign in to comment.