Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFNEWS-2389 - Dashboard count corrections #2073

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ export class FireCauseWidget implements AfterViewInit {
: 'BC';

Promise.all([
this.publishedIncidentService
.fetchStatistics(currentFireYear() - 1, fireCentre)
.toPromise(),
this.publishedIncidentService
.fetchStatistics(currentFireYear(), fireCentre)
.toPromise(),
])
.then(([stats]) => {
.then(([previousYearStats, stats]) => {
// counts by cause code
const currentYearHuman =
stats.reduce(
Expand All @@ -53,6 +56,12 @@ export class FireCauseWidget implements AfterViewInit {
0,
) || 0;

const previousYearHuman =
previousYearStats.reduce(
(n, { activeHumanCausedFires }) => n + activeHumanCausedFires,
0,
) || 0;

const currentYearNatural =
stats.reduce(
(n, { activeNaturalCausedFires }) => n + activeNaturalCausedFires,
Expand All @@ -65,6 +74,12 @@ export class FireCauseWidget implements AfterViewInit {
0,
) || 0;

const previousYearNatural =
previousYearStats.reduce(
(n, { activeNaturalCausedFires }) => n + activeNaturalCausedFires,
0,
) || 0;

const currentYearUnknown =
stats.reduce(
(n, { activeUnknownCausedFires }) => n + activeUnknownCausedFires,
Expand All @@ -77,25 +92,42 @@ export class FireCauseWidget implements AfterViewInit {
0,
) || 0;

const previousYearUnknown =
previousYearStats.reduce(
(n, { activeUnknownCausedFires }) => n + activeUnknownCausedFires,
0,
) || 0;

const totalCurrentYear =
currentYearHuman + currentYearNatural + currentYearUnknown;
const totalOut = humanOut + naturalOut + unknownOut;
const totalPreviousYear =
previousYearHuman + previousYearNatural + previousYearUnknown;

const currentYearOut = humanOut + naturalOut + unknownOut;

const totalFires =
totalCurrentYear +
Number(this.yearly ? totalOut : 0);
Number(this.yearly ? 0 : totalPreviousYear) +
Number(this.yearly ? currentYearOut : 0);

// If this is a yearly totals sum, then we need to include outfires
this.lightningFires =
currentYearNatural +
Number(this.yearly ? 0 : previousYearNatural) +
(this.yearly ? naturalOut : 0);
this.lightningFiresPct =
Math.round((this.lightningFires / totalFires) * 100) || 0;

this.humanFires =
currentYearHuman + (this.yearly ? humanOut : 0);
currentYearHuman +
Number(this.yearly ? 0 : previousYearHuman) +
(this.yearly ? humanOut : 0);
this.humanFiresPct =
Math.round((this.humanFires / totalFires) * 100) || 0;

this.unknownFires =
currentYearUnknown +
Number(this.yearly ? 0 : previousYearUnknown) +
(this.yearly ? unknownOut : 0);
this.unknownFiresPct =
Math.round((this.unknownFires / totalFires) * 100) || 0;
Expand Down
Loading
Loading