Further alert implementation #17

This commit is contained in:
Ian Renton
2025-10-06 21:06:54 +01:00
parent e0675a01f0
commit 6ee4fe288a
14 changed files with 171 additions and 67 deletions

View File

@@ -1,7 +1,9 @@
import hashlib
import json
from dataclasses import dataclass
from datetime import datetime
import copy
import pytz
from core.constants import DXCC_FLAGS
@@ -14,7 +16,7 @@ from core.utils import infer_continent_from_callsign, \
@dataclass
class Alert:
# Unique identifier for the alert
id: int = None
id: str = None
# Callsign of the operator that has been alertted
dx_call: str = None
# Name of the operator that has been alertted
@@ -103,8 +105,15 @@ class Alert:
if self.dx_call and not self.dx_name:
self.dx_name = infer_name_from_callsign(self.dx_call)
# Always create an ID based on a hashcode
self.id = hash(str(self))
# Always create an ID based on a hash of every parameter *except* received_time. This is used as the index
# to a map, which as a byproduct avoids us having multiple duplicate copies of the object that are identical
# apart from that they were retrieved from the API at different times. Note that the simple Python hash()
# function includes a seed randomly generated at runtime; this is therefore not consistent between runs. But we
# use diskcache to store our data between runs, so we use SHA256 which does not include this random element.
self_copy = copy.deepcopy(self)
self_copy.received_time = 0
self_copy.received_time_iso = ""
self.id = hashlib.sha256(str(self_copy).encode("utf-8")).hexdigest()
# JSON serialise
def to_json(self):

View File

@@ -1,3 +1,5 @@
import copy
import hashlib
import json
from dataclasses import dataclass
from datetime import datetime
@@ -16,7 +18,7 @@ from core.utils import infer_mode_type_from_mode, infer_band_from_freq, infer_co
@dataclass
class Spot:
# Unique identifier for the spot
id: int = None
id: str = None
# Callsign of the operator that has been spotted
dx_call: str = None
# Callsign of the operator that has spotted them
@@ -207,8 +209,15 @@ class Spot:
# is likely at home.
self.location_good = self.location_source == "SPOT" or (self.location_source == "QRZ" and not "/" in self.dx_call)
# Always create an ID based on a hashcode
self.id = hash(str(self))
# Always create an ID based on a hash of every parameter *except* received_time. This is used as the index
# to a map, which as a byproduct avoids us having multiple duplicate copies of the object that are identical
# apart from that they were retrieved from the API at different times. Note that the simple Python hash()
# function includes a seed randomly generated at runtime; this is therefore not consistent between runs. But we
# use diskcache to store our data between runs, so we use SHA256 which does not include this random element.
self_copy = copy.deepcopy(self)
self_copy.received_time = 0
self_copy.received_time_iso = ""
self.id = hashlib.sha256(str(self_copy).encode("utf-8")).hexdigest()
# JSON serialise
def to_json(self):