Identify alert multiples

pull/48/head
Mason10198 2 years ago
parent b815572738
commit 1c85371c8c

@ -153,4 +153,5 @@ SWP_144.wav: Tailmessage Disabled
SWP_145.wav: CourtesyTone Enabled SWP_145.wav: CourtesyTone Enabled
SWP_146.wav: CourtesyTone Disabled SWP_146.wav: CourtesyTone Disabled
SWP_147.wav: All Clear Message SWP_147.wav: All Clear Message
SWP_148.wav: Updated Weather Information Message SWP_148.wav: Updated Weather Information Message
SWP_149.wav: With Multiples

@ -41,6 +41,7 @@ import contextlib
import math import math
import sys import sys
import itertools import itertools
import random
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
from dateutil import parser from dateutil import parser
from pydub import AudioSegment from pydub import AudioSegment
@ -279,9 +280,6 @@ LOGGER.addHandler(F_HANDLER)
# Get the "CountyCodes" from the config # Get the "CountyCodes" from the config
COUNTY_CODES_CONFIG = config.get("Alerting", {}).get("CountyCodes", []) COUNTY_CODES_CONFIG = config.get("Alerting", {}).get("CountyCodes", [])
# Log the obtained COUNTY_CODES_CONFIG for debugging
LOGGER.debug(f"COUNTY_CODES_CONFIG: {COUNTY_CODES_CONFIG}")
# Initialize COUNTY_CODES and COUNTY_WAVS # Initialize COUNTY_CODES and COUNTY_WAVS
COUNTY_CODES = [] COUNTY_CODES = []
COUNTY_WAVS = [] COUNTY_WAVS = []
@ -309,9 +307,6 @@ else:
COUNTY_CODES = [] COUNTY_CODES = []
COUNTY_WAVS = [] COUNTY_WAVS = []
# Log the final COUNTY_CODES and COUNTY_WAVS for debugging
LOGGER.debug(f"COUNTY_CODES: {COUNTY_CODES}, COUNTY_WAVS: {COUNTY_WAVS}")
# Log some debugging information # Log some debugging information
LOGGER.debug("Base directory: %s", BASE_DIR) LOGGER.debug("Base directory: %s", BASE_DIR)
LOGGER.debug("Temporary directory: %s", TMP_DIR) LOGGER.debug("Temporary directory: %s", TMP_DIR)
@ -399,22 +394,27 @@ def get_alerts(countyCodes):
countyCodes countyCodes
) # Create an iterator that returns elements from the iterable in a cyclic manner ) # Create an iterator that returns elements from the iterable in a cyclic manner
counter = 0
for i, event in enumerate(injected_alerts): for i, event in enumerate(injected_alerts):
last_word = event.split()[-1] last_word = event.split()[-1]
severity = severity_mapping_words.get(last_word, 0) severity = severity_mapping_words.get(last_word, 0)
description = "This alert was manually injected as a test." description = "This alert was manually injected as a test."
end_time_utc = current_time + timedelta(hours=1)
county_data = [ county_data = []
{ for j in range(
"county_code": next(county_codes_cycle), i + 1
"severity": severity, ): # Here we increase the number of county codes for each alert
"description": description, end_time_utc = current_time + timedelta(hours=counter + 1)
"end_time_utc": end_time_utc.strftime("%Y-%m-%dT%H:%M:%S.%fZ"), county_data.append(
} {
for _ in range( "county_code": next(county_codes_cycle),
i + 1 "severity": severity,
) # Here we increase the number of county codes for each alert "description": description,
] # Create a list of dictionaries "end_time_utc": end_time_utc.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
}
)
counter += 1 # Increase counter here
alerts[event] = county_data # Add the list of dictionaries to the alert alerts[event] = county_data # Add the list of dictionaries to the alert
# We limit the number of alerts to the maximum defined constant. # We limit the number of alerts to the maximum defined constant.
@ -696,6 +696,8 @@ def say_alerts(alerts):
) in alerts.items(): # Now we loop over both alert name and its associated counties ) in alerts.items(): # Now we loop over both alert name and its associated counties
if alert in filtered_alerts: if alert in filtered_alerts:
try: try:
descriptions = [county["description"] for county in counties]
end_times = [county["end_time_utc"] for county in counties]
index = ALERT_STRINGS.index(alert) index = ALERT_STRINGS.index(alert)
audio_file = AudioSegment.from_wav( audio_file = AudioSegment.from_wav(
os.path.join( os.path.join(
@ -708,6 +710,17 @@ def say_alerts(alerts):
alert, alert,
ALERT_INDEXES[index], ALERT_INDEXES[index],
) )
if len(set(descriptions)) > 1 or len(set(end_times)) > 1:
LOGGER.debug(
"sayAlert: Found multiple unique instances of the alert %s",
alert,
)
multiples_sound = AudioSegment.from_wav(
os.path.join(SOUNDS_PATH, "ALERTS", "SWP_149.wav")
)
combined_sound += (
AudioSegment.silent(duration=200) + multiples_sound
)
alert_count += 1 alert_count += 1
# Add county names if they exist # Add county names if they exist
@ -906,6 +919,18 @@ def build_tailmessage(alerts):
ALERT_INDEXES[index], ALERT_INDEXES[index],
) )
descriptions = [county["description"] for county in counties]
end_times = [county["end_time_utc"] for county in counties]
if len(set(descriptions)) > 1 or len(set(end_times)) > 1:
LOGGER.debug(
"buildTailMessage: Found multiple unique instances of the alert %s",
alert,
)
multiples_sound = AudioSegment.from_wav(
os.path.join(SOUNDS_PATH, "ALERTS", "SWP_149.wav")
)
combined_sound += AudioSegment.silent(duration=200) + multiples_sound
# Add county names if they exist # Add county names if they exist
if county_identifiers: if county_identifiers:
for county in counties: for county in counties:

Loading…
Cancel
Save

Powered by TurnKey Linux.