From 1c85371c8c332b5ee6a9cf08783c6cd21d1c331b Mon Sep 17 00:00:00 2001 From: Mason10198 <31994327+Mason10198@users.noreply.github.com> Date: Thu, 27 Jul 2023 13:43:52 -0500 Subject: [PATCH] Identify alert multiples --- SOUNDS/ALERTS/DICTIONARY.txt | 3 +- SkywarnPlus.py | 61 +++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/SOUNDS/ALERTS/DICTIONARY.txt b/SOUNDS/ALERTS/DICTIONARY.txt index 742091a..a8e2a1b 100644 --- a/SOUNDS/ALERTS/DICTIONARY.txt +++ b/SOUNDS/ALERTS/DICTIONARY.txt @@ -153,4 +153,5 @@ SWP_144.wav: Tailmessage Disabled SWP_145.wav: CourtesyTone Enabled SWP_146.wav: CourtesyTone Disabled SWP_147.wav: All Clear Message -SWP_148.wav: Updated Weather Information Message \ No newline at end of file +SWP_148.wav: Updated Weather Information Message +SWP_149.wav: With Multiples \ No newline at end of file diff --git a/SkywarnPlus.py b/SkywarnPlus.py index fe727b7..27227e6 100644 --- a/SkywarnPlus.py +++ b/SkywarnPlus.py @@ -41,6 +41,7 @@ import contextlib import math import sys import itertools +import random from datetime import datetime, timezone, timedelta from dateutil import parser from pydub import AudioSegment @@ -279,9 +280,6 @@ LOGGER.addHandler(F_HANDLER) # Get the "CountyCodes" from the config 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 COUNTY_CODES = [] COUNTY_WAVS = [] @@ -309,9 +307,6 @@ else: COUNTY_CODES = [] 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 LOGGER.debug("Base directory: %s", BASE_DIR) LOGGER.debug("Temporary directory: %s", TMP_DIR) @@ -399,22 +394,27 @@ def get_alerts(countyCodes): countyCodes ) # Create an iterator that returns elements from the iterable in a cyclic manner + counter = 0 for i, event in enumerate(injected_alerts): last_word = event.split()[-1] severity = severity_mapping_words.get(last_word, 0) description = "This alert was manually injected as a test." - end_time_utc = current_time + timedelta(hours=1) - county_data = [ - { - "county_code": next(county_codes_cycle), - "severity": severity, - "description": description, - "end_time_utc": end_time_utc.strftime("%Y-%m-%dT%H:%M:%S.%fZ"), - } - for _ in range( - i + 1 - ) # Here we increase the number of county codes for each alert - ] # Create a list of dictionaries + + county_data = [] + for j in range( + i + 1 + ): # Here we increase the number of county codes for each alert + end_time_utc = current_time + timedelta(hours=counter + 1) + county_data.append( + { + "county_code": next(county_codes_cycle), + "severity": severity, + "description": description, + "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 # 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 if alert in filtered_alerts: try: + descriptions = [county["description"] for county in counties] + end_times = [county["end_time_utc"] for county in counties] index = ALERT_STRINGS.index(alert) audio_file = AudioSegment.from_wav( os.path.join( @@ -708,6 +710,17 @@ def say_alerts(alerts): alert, 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 # Add county names if they exist @@ -906,6 +919,18 @@ def build_tailmessage(alerts): 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 if county_identifiers: for county in counties: