Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Fix/modify values stats #201

Merged
merged 1 commit into from
Jun 3, 2021
Merged
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
11 changes: 9 additions & 2 deletions src/utils/statistics-util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/named
import { keyBy, mapValues, template } from "lodash";
import { keyBy, mapValues, round, template } from "lodash";
// eslint-disable-next-line import/named
import { compose } from "lodash/fp";

Expand All @@ -16,6 +16,8 @@ import {
StatisticsGroup,
} from "../types/statistic-types";

const KILO_TO_TONS = 0.001;

const findElementByLabel = (statistics: Statistic[], label: string) => {
return statistics.find((statistic) => statistic.label === label);
};
Expand Down Expand Up @@ -64,14 +66,19 @@ const formatAggregatedStatistic = (statistic: AggregatedStatisticConfig) => (
const formatInterpolateData = (data: Statistic[]): Record<string, number> =>
mapValues(keyBy(data, "label"), ({ value }) => value);

const kiloToTons = (elementToRounded: string): number => {
const roundedElement = +elementToRounded * KILO_TO_TONS;
return round(+roundedElement, 1);
};

const formatInterpolateStatistic = (statistic: InterpolateStatisticConfig) => (
data: Statistic[]
): RenderingStatisticConfig => {
return {
...extractCommonProps(statistic),
sublabel: template(statistic.sublabel || "")(formatInterpolateData(data)),
type: "raw",
value: template(statistic.value)(formatInterpolateData(data)),
value: kiloToTons(template(statistic.value)(formatInterpolateData(data))),
};
};
const formatSimpleStatistic = (statistic: SimpleStatisticConfig) => (
Expand Down