Support de-dupe and comment filtering for spots. Closes #45

This commit is contained in:
Ian Renton
2025-10-19 10:18:01 +01:00
parent 760077b081
commit 772d9f4341
2 changed files with 56 additions and 0 deletions

View File

@@ -137,6 +137,9 @@ class WebServer:
# in seconds UTC.
# We can also filter by source, sig, band, mode, dx_continent and de_continent. Each of these accepts a single
# value or a comma-separated list.
# We can filter by comments, accepting a single string, where the API will only return spots where the comment
# contains the provided value (case-insensitive).
# We can "de-dupe" spots, so only the latest spot will be sent for each callsign.
# We can provide a "limit" number as well. Spots are always returned newest-first; "limit" limits to only the
# most recent X spots.
spot_ids = list(self.spots.iterkeys())
@@ -179,6 +182,22 @@ class WebServer:
case "de_continent":
deconts = query.get(k).split(",")
spots = [s for s in spots if s.de_continent and s.de_continent in deconts]
case "comment_includes":
comment_includes = query.get(k).strip()
spots = [s for s in spots if s.comment and comment_includes.upper() in s.comment.upper()]
case "dedupe":
# Ensure only the latest spot of each callsign is present in the list. This relies on the list being
# in reverse time order, so if any future change allows re-ordering the list, that should be done
# *after* this.
dedupe = query.get(k).upper() == "TRUE"
if dedupe:
spots_temp = []
already_seen = []
for s in spots:
if s.dx_call not in already_seen:
spots_temp.append(s)
already_seen.append(s.dx_call)
spots = spots_temp
# If we have a "limit" parameter, we apply that last, regardless of where it appeared in the list of keys.
if "limit" in query.keys():
spots = spots[:int(query.get("limit"))]

View File

@@ -76,6 +76,12 @@ paths:
- WWBOTA
- GMA
- HEMA
- WCA
- MOTA
- SiOTA
- ARLHS
- ILLW
- ZLOTA
- name: band
in: query
description: "Limit the spots to only ones from one or more bands. To select more than one band, supply a comma-separated list."
@@ -168,6 +174,19 @@ paths:
- AF
- OC
- AN
- name: dedupe
in: query
description: "\"De-duplicate\" the spots, returning only the latest spot for any given callsign."
required: false
schema:
type: boolean
default: false
- name: comment_includes
in: query
description: "Return only spots where the comment includes the provided string (case-insensitive)."
required: false
schema:
type: string
responses:
'200':
description: Success
@@ -241,6 +260,12 @@ paths:
- WWBOTA
- GMA
- HEMA
- WCA
- MOTA
- SiOTA
- ARLHS
- ILLW
- ZLOTA
- name: dx_continent
in: query
description: "Limit the alerts to only ones where the DX (the operator being spotted) is on the given continent(s). To select more than one continent, supply a comma-separated list."
@@ -667,6 +692,12 @@ components:
- WWBOTA
- GMA
- HEMA
- WCA
- MOTA
- SiOTA
- ARLHS
- ILLW
- ZLOTA
example: POTA
sig_refs:
type: array
@@ -812,6 +843,12 @@ components:
- WWBOTA
- GMA
- HEMA
- WCA
- MOTA
- SiOTA
- ARLHS
- ILLW
- ZLOTA
example: POTA
sig_refs:
type: array