Skip to content

Commit

Permalink
WFNEWS-2065 Remove previous year incident stats for this year's totals (
Browse files Browse the repository at this point in the history
  • Loading branch information
ssylver93 authored Apr 19, 2024
1 parent ea3f783 commit cb7bc38
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,17 @@ export class FireCauseWidget implements AfterViewInit {
: 'BC';

Promise.all([
this.publishedIncidentService
.fetchStatistics(currentFireYear() - 1, fireCentre)
.toPromise(),
this.publishedIncidentService
.fetchStatistics(currentFireYear(), fireCentre)
.toPromise(),
])
.then(([previousYearStats, stats]) => {
.then(([stats]) => {
// counts by cause code
const currentYearHuman =
stats.reduce(
(n, { activeHumanCausedFires }) => n + activeHumanCausedFires,
0,
) || 0;
const previousYearHuman =
previousYearStats.reduce(
(n, { activeHumanCausedFires }) => n + activeHumanCausedFires,
0,
) || 0;
const humanOut =
stats.reduce(
(n, { extinguishedHumanCausedFires }) =>
Expand All @@ -66,11 +58,6 @@ export class FireCauseWidget implements AfterViewInit {
(n, { activeNaturalCausedFires }) => n + activeNaturalCausedFires,
0,
) || 0;
const previousYearNatural =
previousYearStats.reduce(
(n, { activeNaturalCausedFires }) => n + activeNaturalCausedFires,
0,
) || 0;
const naturalOut =
stats.reduce(
(n, { extinguishedNaturalCausedFires }) =>
Expand All @@ -83,11 +70,6 @@ export class FireCauseWidget implements AfterViewInit {
(n, { activeUnknownCausedFires }) => n + activeUnknownCausedFires,
0,
) || 0;
const previousYearUnknown =
previousYearStats.reduce(
(n, { activeUnknownCausedFires }) => n + activeUnknownCausedFires,
0,
) || 0;
const unknownOut =
stats.reduce(
(n, { extinguishedUnknownCausedFires }) =>
Expand All @@ -97,28 +79,23 @@ export class FireCauseWidget implements AfterViewInit {

const totalCurrentYear =
currentYearHuman + currentYearNatural + currentYearUnknown;
const totalPreviousYear =
previousYearHuman + previousYearNatural + previousYearUnknown;
const totalOut = humanOut + naturalOut + unknownOut;
const totalFires =
totalCurrentYear +
totalPreviousYear +
Number(this.yearly ? totalOut : 0);

// If this is a yearly totals sum, then we need to include outfires
this.lightningFires =
currentYearNatural +
previousYearNatural +
(this.yearly ? naturalOut : 0);
this.lightningFiresPct =
Math.round((this.lightningFires / totalFires) * 100) || 0;
this.humanFires =
currentYearHuman + previousYearHuman + (this.yearly ? humanOut : 0);
currentYearHuman + (this.yearly ? humanOut : 0);
this.humanFiresPct =
Math.round((this.humanFires / totalFires) * 100) || 0;
this.unknownFires =
currentYearUnknown +
previousYearUnknown +
(this.yearly ? unknownOut : 0);
this.unknownFiresPct =
Math.round((this.unknownFires / totalFires) * 100) || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ export class FireCentreStatsWidget implements AfterViewInit {

ngAfterViewInit(): void {
Promise.all([
this.publishedIncidentService
.fetchStatistics(currentFireYear() - 1, null)
.toPromise(),
this.publishedIncidentService
.fetchStatistics(currentFireYear(), null)
.toPromise(),
])
.then(([previousYearStats, stats]) => {
.then(([stats]) => {
for (const fc of this.fireCentres) {
const currentYearActive =
stats
Expand All @@ -51,28 +48,10 @@ export class FireCentreStatsWidget implements AfterViewInit {
activeUnderControlFires,
0,
) || 0;
const previousYearActive =
previousYearStats
.filter((f) => f.fireCentre === fc.description)
.reduce(
(
n,
{
activeBeingHeldFires,
activeOutOfControlFires,
activeUnderControlFires,
},
) =>
n +
activeBeingHeldFires +
activeOutOfControlFires +
activeUnderControlFires,
0,
) || 0;

this.fireCentreTotals.push({
name: fc.description.replace(' Fire Centre', ''),
value: currentYearActive + previousYearActive,
value: currentYearActive,
});

this.fireCentreHectares.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,11 @@ export class FireTotalsWidget implements AfterViewInit {
activeUnderControlFires,
0,
) || 0;
const previousYearActive =
previousYearStats.reduce(
(
n,
{
activeBeingHeldFires,
activeOutOfControlFires,
activeUnderControlFires,
},
) =>
n +
activeBeingHeldFires +
activeOutOfControlFires +
activeUnderControlFires,
0,
) || 0;
const currentYearOut =
stats.reduce((n, { outFires }) => n + outFires, 0) || 0;

this.totalFires =
currentYearActive + previousYearActive + currentYearOut;
currentYearActive + currentYearOut;
this.outFires = currentYearOut;
this.hectaresBurned =
Math.round(
Expand Down

0 comments on commit cb7bc38

Please sign in to comment.