Skip to content

Commit

Permalink
fix: handle sticky actions in mock AB#14576
Browse files Browse the repository at this point in the history
  • Loading branch information
arsforza committed Aug 8, 2022
1 parent 8577967 commit 10685ba
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions services/API-service/src/scripts/scripts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class ScriptsService {
@InjectRepository(CountryEntity)
private readonly countryRepo: Repository<CountryEntity>;

private rainMonthsKey = 'rainMonths';

public constructor(
private adminAreaDynamicDataService: AdminAreaDynamicDataService,
private glofasStationService: GlofasStationService,
Expand Down Expand Up @@ -451,16 +453,17 @@ export class ScriptsService {
}

private useLeadTimeForMock(
forecastSeasons: any,
forecastSeasons,
leadTime: string,
leadTimeMonthFirstDay: Date,
currentUTCMonth: number,
currentYear: number,
) {
// If current month is one of the months in the seasons, always use '0-month' and return early ..

if (leadTime === LeadTime.month0) {
for (const season of forecastSeasons) {
for (const month of season) {
for (const season of Object.values(forecastSeasons)) {
for (const month of season[this.rainMonthsKey]) {
if (currentUTCMonth + 1 === month) {
return true;
}
Expand All @@ -469,7 +472,9 @@ export class ScriptsService {
}

// .. For other cases, continue to find the next forecast month
const forecastMonthNumbers = forecastSeasons.map(month => month[0]);
const forecastMonthNumbers = Object.values(forecastSeasons).map(
season => season[this.rainMonthsKey][0],
);
let forecastMonthNumber: number;
forecastMonthNumbers
.sort((a, b) => (a > b ? -1 : 1))
Expand Down Expand Up @@ -605,9 +610,10 @@ export class ScriptsService {
);
const month = leadTimeMonthFirstDay.getMonth() + 1;
let triggeredAreas = [];

for (const area of Object.keys(forecastSeasonAreas)) {
for (const season of forecastSeasonAreas[area]) {
const filteredSeason = season.filter(
for (const season of Object.values(forecastSeasonAreas[area])) {
const filteredSeason = season[this.rainMonthsKey].filter(
seasonMonth => seasonMonth >= currentUTCMonth + 1,
);
if (filteredSeason[0] === month) {
Expand Down

0 comments on commit 10685ba

Please sign in to comment.