Skip to content

Commit

Permalink
fix(ui-clusters): improve cell number values accuracy by using roundi…
Browse files Browse the repository at this point in the history
…ng instead of truncating

columns modified:
* 'Enabled / Installed (MW)' in Thermals and Renewables
* 'Nominal Capacity (MW)' in Renewables
* 'Injection capacity from stock to the network (MW)' in Storages
* 'Withdrawal (MW)' in Storages
* 'Efficiency (%)' in Storages
* 'Initial level (%)' in Storages
  • Loading branch information
skamril committed Jul 10, 2024
1 parent a2ac082 commit 3d441e6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
addClusterCapacity,
capacityAggregationFn,
getClustersWithCapacityTotals,
toCapacityString,
} from "../common/clustersUtils";
import { TRow } from "../../../../../../common/GroupedDataTable/types";
import BooleanCell from "../../../../../../common/GroupedDataTable/cellRenderers/BooleanCell";
Expand Down Expand Up @@ -80,29 +81,26 @@ function Renewables() {
columnHelper.accessor("nominalCapacity", {
header: "Nominal Capacity (MW)",
size: 220,
Cell: ({ cell }) => Math.floor(cell.getValue()),
}),
columnHelper.accessor("installedCapacity", {
header: "Enabled / Installed (MW)",
size: 220,
aggregationFn: capacityAggregationFn(),
AggregatedCell: ({ cell }) => (
<Box sx={{ color: "info.main", fontWeight: "bold" }}>
{cell.getValue() ?? ""}
</Box>
),
Cell: ({ row }) => (
<>
{Math.floor(row.original.enabledCapacity)} /{" "}
{Math.floor(row.original.installedCapacity)}
</>
),
Footer: () => (
<Box color="warning.main">
{totalEnabledCapacity} / {totalInstalledCapacity}
</Box>
),
Cell: ({ cell }) => cell.getValue().toFixed(1),
}),
columnHelper.accessor(
(row) => toCapacityString(row.enabledCapacity, row.installedCapacity),
{
header: "Enabled / Installed (MW)",
size: 220,
aggregationFn: capacityAggregationFn(),
AggregatedCell: ({ cell }) => (
<Box sx={{ color: "info.main", fontWeight: "bold" }}>
{cell.getValue()}
</Box>
),
Footer: () => (
<Box color="warning.main">
{toCapacityString(totalEnabledCapacity, totalInstalledCapacity)}
</Box>
),
},
),
];
}, [totals]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ function Storages() {
aggregationFn: "sum",
AggregatedCell: ({ cell }) => (
<Box sx={{ color: "info.main", fontWeight: "bold" }}>
{Math.floor(cell.getValue())}
{Math.round(cell.getValue())}
</Box>
),
Cell: ({ cell }) => Math.floor(cell.getValue()),
Cell: ({ cell }) => Math.round(cell.getValue()),
Footer: () => (
<Box color="warning.main">
{Math.floor(totalInjectionNominalCapacity)}
{Math.round(totalInjectionNominalCapacity)}
</Box>
),
}),
Expand All @@ -96,13 +96,13 @@ function Storages() {
aggregationFn: "sum",
AggregatedCell: ({ cell }) => (
<Box sx={{ color: "info.main", fontWeight: "bold" }}>
{Math.floor(cell.getValue())}
{Math.round(cell.getValue())}
</Box>
),
Cell: ({ cell }) => Math.floor(cell.getValue()),
Cell: ({ cell }) => Math.round(cell.getValue()),
Footer: () => (
<Box color="warning.main">
{Math.floor(totalWithdrawalNominalCapacity)}
{Math.round(totalWithdrawalNominalCapacity)}
</Box>
),
}),
Expand All @@ -123,12 +123,12 @@ function Storages() {
columnHelper.accessor("efficiency", {
header: t("study.modelization.storages.efficiency"),
size: 50,
Cell: ({ cell }) => `${Math.floor(cell.getValue() * 100)}`,
Cell: ({ cell }) => `${Math.round(cell.getValue() * 100)}`,
}),
columnHelper.accessor("initialLevel", {
header: t("study.modelization.storages.initialLevel"),
size: 50,
Cell: ({ cell }) => `${Math.floor(cell.getValue() * 100)}`,
Cell: ({ cell }) => `${Math.round(cell.getValue() * 100)}`,
}),
columnHelper.accessor("initialLevelOptim", {
header: t("study.modelization.storages.initialLevelOptim"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
addClusterCapacity,
capacityAggregationFn,
getClustersWithCapacityTotals,
toCapacityString,
} from "../common/clustersUtils";
import { TRow } from "../../../../../../common/GroupedDataTable/types";
import BooleanCell from "../../../../../../common/GroupedDataTable/cellRenderers/BooleanCell";
Expand Down Expand Up @@ -84,27 +85,24 @@ function Thermal() {
size: 220,
Cell: ({ cell }) => cell.getValue().toFixed(1),
}),
columnHelper.accessor("installedCapacity", {
header: "Enabled / Installed (MW)",
size: 220,
aggregationFn: capacityAggregationFn(),
AggregatedCell: ({ cell }) => (
<Box sx={{ color: "info.main", fontWeight: "bold" }}>
{cell.getValue() ?? ""}
</Box>
),
Cell: ({ row }) => (
<>
{Math.floor(row.original.enabledCapacity)} /{" "}
{Math.floor(row.original.installedCapacity)}
</>
),
Footer: () => (
<Box color="warning.main">
{totalEnabledCapacity} / {totalInstalledCapacity}
</Box>
),
}),
columnHelper.accessor(
(row) => toCapacityString(row.enabledCapacity, row.installedCapacity),
{
header: "Enabled / Installed (MW)",
size: 220,
aggregationFn: capacityAggregationFn(),
AggregatedCell: ({ cell }) => (
<Box sx={{ color: "info.main", fontWeight: "bold" }}>
{cell.getValue()}
</Box>
),
Footer: () => (
<Box color="warning.main">
{toCapacityString(totalEnabledCapacity, totalInstalledCapacity)}
</Box>
),
},
),
columnHelper.accessor("marketBidCost", {
header: "Market Bid (€/MWh)",
size: 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { MRT_AggregationFn } from "material-react-table";
import { ThermalClusterWithCapacity } from "../Thermal/utils";
import { RenewableClusterWithCapacity } from "../Renewables/utils";

export function toCapacityString(
enabledCapacity: number,
installedCapacity: number,
) {
return `${Math.round(enabledCapacity)} / ${Math.round(installedCapacity)}`;
}

/**
* Custom aggregation function summing the values of each row,
* to display enabled and installed capacity in the same cell. This function is
Expand Down Expand Up @@ -29,9 +36,7 @@ export const capacityAggregationFn = <
{ enabledCapacitySum: 0, installedCapacitySum: 0 },
);

return `${Math.floor(enabledCapacitySum)} / ${Math.floor(
installedCapacitySum,
)}`;
return toCapacityString(enabledCapacitySum, installedCapacitySum);
};
};

Expand Down

0 comments on commit 3d441e6

Please sign in to comment.