Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-clusters): improve cell number values accuracy by using rounding instead of truncating #2087

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading