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

Commit

Permalink
fix(stats): modify ecologic values (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdilouraoui authored Jun 3, 2021
1 parent 00f2b69 commit 316b7ab
Showing 1 changed file with 9 additions and 2 deletions.
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

0 comments on commit 316b7ab

Please sign in to comment.