Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Jan 2, 2024
1 parent ebb4359 commit 4782410
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { ActualVsScenarioImpactTableRowsValues } from 'modules/impact/dto/respon
import { ImpactTableCSVReport } from 'modules/impact/reports/types';

/**
* @description Handles the building of the object, for each row that it will be parsed to CSV
* @description Handles the building of the DTO for the CSV report
*/

export class CsvDataBuilder {
export class ImpactReportDtoBuilder {
csvData: ImpactTableCSVReport;
currentNodeName: string;
yearKey: string;
Expand Down Expand Up @@ -72,7 +72,7 @@ export class CsvDataBuilder {
this.yearKey = year.toString();
}

setProjectedYear(): void {
setYearAsProjected(): void {
this.yearKey = this.yearKey.concat(' (projected)');
}

Expand Down
33 changes: 17 additions & 16 deletions api/src/modules/impact/reports/impact-report.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ImpactTableToCSVInput,
} from 'modules/impact/reports/types';
import { Injectable } from '@nestjs/common';
import { CsvDataBuilder } from 'modules/impact/reports/csv-data.builder';
import { ImpactReportDtoBuilder } from 'modules/impact/reports/impact-report-dto.builder';
import { ScenarioVsScenarioImpactTableRowsValues } from 'modules/impact/dto/response-scenario-scenario.dto';
import { ActualVsScenarioImpactTableRowsValues } from 'modules/impact/dto/response-actual-scenario.dto';

Expand Down Expand Up @@ -43,36 +43,37 @@ export class ImpactReportDataParser {
groupBy: GROUP_BY_VALUES,
unit: string,
accumulator: ImpactTableCSVReport[],
parentName?: string | null,
parentNodeName?: string | null,
): void {
const parsedDataBuilder: CsvDataBuilder = new CsvDataBuilder();
parsedDataBuilder.setIndicatorWithUnit(indicatorName, unit);
parsedDataBuilder.setGroupingAndNodeName(groupBy, node.name, parentName);
const reportDtoBuilder: ImpactReportDtoBuilder =
new ImpactReportDtoBuilder();
reportDtoBuilder.setIndicatorWithUnit(indicatorName, unit);
reportDtoBuilder.setGroupingAndNodeName(groupBy, node.name, parentNodeName);
node.values.forEach((valuesOfNode: AnyImpactTableRowsValues) => {
parsedDataBuilder.setBaseYearKey(valuesOfNode.year);
if (parsedDataBuilder.isYearProjected(valuesOfNode)) {
parsedDataBuilder.setProjectedYear();
reportDtoBuilder.setBaseYearKey(valuesOfNode.year);
if (reportDtoBuilder.isYearProjected(valuesOfNode)) {
reportDtoBuilder.setYearAsProjected();
}
if (parsedDataBuilder.isScenarioVsScenario(valuesOfNode)) {
parsedDataBuilder.setScenarioVsScenarioValues(
if (reportDtoBuilder.isScenarioVsScenario(valuesOfNode)) {
reportDtoBuilder.setScenarioVsScenarioValues(
valuesOfNode as ScenarioVsScenarioImpactTableRowsValues,
);
}
if (parsedDataBuilder.isActualVsScenario(valuesOfNode)) {
parsedDataBuilder.setActualVsScenarioValues(
if (reportDtoBuilder.isActualVsScenario(valuesOfNode)) {
reportDtoBuilder.setActualVsScenarioValues(
valuesOfNode as ActualVsScenarioImpactTableRowsValues,
);
}
if (parsedDataBuilder.isOnlyActualData(valuesOfNode)) {
parsedDataBuilder.setActualDataValues(
if (reportDtoBuilder.isOnlyActualData(valuesOfNode)) {
reportDtoBuilder.setActualDataValues(
valuesOfNode as ImpactTableRowsValues,
);
}
});
accumulator.push(parsedDataBuilder.build());
accumulator.push(reportDtoBuilder.build());

if (node.children && node.children.length) {
const currentNodeName: string = parsedDataBuilder.getCurrentNodeName();
const currentNodeName: string = reportDtoBuilder.getCurrentNodeName();
node.children.forEach((children: AnyImpactTableRows) => {
this.parseNode(
children,
Expand Down

0 comments on commit 4782410

Please sign in to comment.