Skip to content

Commit

Permalink
Merge pull request #1500 from rodekruis/feat.email-warning-date-trigger
Browse files Browse the repository at this point in the history
AB#27286 warning date trigger event
  • Loading branch information
gulfaraz authored Jul 8, 2024
2 parents 29ef92c + 30d045b commit b159916
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@ export class NotificationDataPerEventDto {
triggerStatusLabel: TriggerStatusLabelEnum;
eventName: string;
disasterSpecificCopy: DisasterSpecificCopy;

/**
* The day that the event starts.
*/
firstLeadTime: LeadTime;

/**
* The day that the event triggers. This could be different from firstLeadTimeString.
* For example, a flood could transition from a warning (a chance of a small flood)
* to an EAP trigger (a larger chance of a bigger flood).
*/
firstTriggerLeadTime: LeadTime;

firstLeadTimeString: string;
firstTriggerLeadTimeString: string;

triggeredAreas: TriggeredArea[];

/**
* The number of areas where the event triggers.
*/
nrOfTriggeredAreas: number;
startDateDisasterString: string;

totalAffectedOfIndicator: number;
mapImage?: Buffer;
issuedDate: Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,23 +305,40 @@ export class EmailTemplateService {
return emailContent.dataPerEvent
.map((event) => {
const data = {
// Event details
eventName: event.eventName,
hazard: emailContent.disasterTypeLabel,
triggerStatusLabel: event.triggerStatusLabel,
eventName: event.eventName,
nrOfTriggeredAreas: event.nrOfTriggeredAreas,
expectedTriggerDate: event.firstLeadTime,
issuedDate: this.dateObjectToDateTimeString(
event.issuedDate,
emailContent.country.countryCodeISO3,
),
startDateEventString: event.startDateDisasterString,
timezone:
CountryTimeZoneMapping[emailContent.country.countryCodeISO3],

// Lead time details
firstLeadTimeString: event.firstLeadTimeString,
firstTriggerLeadTimeString: event.firstTriggerLeadTimeString,
firstLeadTimeQuantity: event.firstLeadTime.replace('-', ' '),
firstTriggerLeadTimeQuantity: event.firstTriggerLeadTime
? event.firstTriggerLeadTime.replace('-', ' ')
: '',

// Area details
nrOfTriggeredAreas: event.nrOfTriggeredAreas,
defaultAdminAreaLabel:
emailContent.defaultAdminAreaLabel.plural.toLocaleLowerCase(),

// Indicator details
indicatorLabel: emailContent.indicatorMetadata.label,
totalAffectedOfIndicator: event.totalAffectedOfIndicator,
indicatorUnit: emailContent.indicatorMetadata.unit,
timezone:
CountryTimeZoneMapping[emailContent.country.countryCodeISO3],
totalAffected: this.getTotalAffectedHtml(
event,
emailContent.indicatorMetadata.label.toLowerCase(),
),

// EAP details
triangleIcon: this.getTriangleIcon(
event.eapAlertClass?.key,
event.triggerStatusLabel,
Expand All @@ -339,10 +356,6 @@ export class EmailTemplateService {
event.triggerStatusLabel,
emailContent.linkEapSop,
),
totalAffected: this.getTotalAffectedHtml(
event,
emailContent.indicatorMetadata.label.toLowerCase(),
),
};

const templateFileName = 'body-event.html';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@
<%= hazard %> <%= eventName %>
<span class="body-text-break"></span>
</span>
<% if (firstTriggerLeadTimeString) { %>
<span class="body-text body-text-normal">
<%= hazard %> expected to start on <%= firstLeadTimeString %>, <%=
firstLeadTimeQuantity %>s from now.
<span class="body-text-break"></span>
</span>
<span class="body-text body-text-bold"> <%= disasterIssuedLabel %>: </span>
<span class="body-text body-text-normal">
expected to reach threshold on <%= firstTriggerLeadTimeString %>, <%=
firstTriggerLeadTimeQuantity %>s from now.
<span class="body-text-break"></span>
</span>
<% } else { %>
<span class="body-text body-text-bold"> <%= disasterIssuedLabel %>: </span>
<span class="body-text body-text-normal">
<%= startDateEventString %>, <%= leadTime %>s from now.
expected on <%= firstLeadTimeString %>, <%= firstLeadTimeQuantity %>s from
now.
<span class="body-text-break"></span>
</span>
<% } %>
<span class="body-text body-text-bold">
Expected exposed <%= defaultAdminAreaLabel %>:
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class NotificationContentService {
event,
);
data.firstLeadTime = event.firstLeadTime;
data.firstTriggerLeadTime = event.firstTriggerLeadTime;
data.triggeredAreas = await this.getSortedTriggeredAreas(
country,
disasterType,
Expand All @@ -179,11 +180,17 @@ export class NotificationContentService {
);
// This looks weird, but as far as I understand the startDate of the event is the day it was first issued
data.issuedDate = new Date(event.startDate);
data.startDateDisasterString = await this.getFirstLeadTimeString(
data.firstLeadTimeString = await this.getFirstLeadTimeString(
event,
event.countryCodeISO3,
disasterType,
);
data.firstTriggerLeadTimeString = await this.getFirstTriggerLeadTimeString(
event,
event.countryCodeISO3,
disasterType,
);

data.totalAffectedOfIndicator = this.getTotalAffectedPerEvent(
data.triggeredAreas,
);
Expand Down Expand Up @@ -290,16 +297,48 @@ export class NotificationContentService {
countryCodeISO3: string,
disasterType: DisasterType,
date?: Date,
) {
): Promise<string> {
return this.getEventTimeString(
event.firstLeadTime,
countryCodeISO3,
disasterType,
date,
);
}

public async getFirstTriggerLeadTimeString(
event: EventSummaryCountry,
countryCodeISO3: string,
disasterType: DisasterType,
date?: Date,
): Promise<string> {
if (event.firstTriggerLeadTime) {
return this.getEventTimeString(
event.firstTriggerLeadTime,
countryCodeISO3,
disasterType,
date,
);
} else {
return null;
}
}

private async getEventTimeString(
leadTime: LeadTime,
countryCodeISO3: string,
disasterType: DisasterType,
date?: Date,
): Promise<string> {
const startDateFirstEvent = await this.getFirstLeadTimeDate(
Number(event.firstLeadTime.split('-')[0]),
event.firstLeadTime.split('-')[1],
Number(leadTime.split('-')[0]),
leadTime.split('-')[1],
countryCodeISO3,
disasterType,
date,
);
const startTimeFirstEvent = await this.getLeadTimeTimestamp(
event.firstLeadTime,
leadTime,
countryCodeISO3,
disasterType,
);
Expand Down

0 comments on commit b159916

Please sign in to comment.