Skip to content

Commit

Permalink
#2004 - refactor for codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
Brajesh Kumar authored and Brajesh Kumar committed Oct 9, 2023
1 parent 1ffdeb8 commit 268c56f
Showing 1 changed file with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,21 @@ export class EducationalMaterialComponent implements OnInit {

this.records.forEach((m) => {
const { materialType, materialAmount } = m;
const label = materialType?.label;

if (materialType.label) {
const label = materialType.label;

if (!summary.has(label)) {
summary.set(label, { count: 0, sum: 0 });
}

const labelData = summary.get(label);
labelData.count++;
labelData.sum += materialAmount;
if (label) {
summary.set(label, (summary.get(label) || { count: 0, sum: 0 }));
summary.get(label)!.count++;
summary.get(label)!.sum += materialAmount;
}
});

const summaryArray: string[] = Array.from(summary.entries()).map(
([label, labelData]) => `${label}: ${labelData.sum}`
);

const avgSummaryArray: string[] = Array.from(summary.entries()).map(
([label, labelData]) => {
const avg = parseFloat((labelData.sum / labelData.count).toFixed(2));
average.set(label, avg);
return `${label}: ${avg}`;
}
);
const summaryArray = Array.from(summary.entries(), ([label, { sum }]) => `${label}: ${sum}`);
const avgSummaryArray = Array.from(summary.entries(), ([label, { count, sum }]) => {
const avg = parseFloat((sum / count).toFixed(2));
average.set(label, avg);
return `${label}: ${avg}`;
});

this.summary = summaryArray.join(", ");
this.avgSummary = avgSummaryArray.join(", ");
Expand Down

0 comments on commit 268c56f

Please sign in to comment.