Skip to content

Commit

Permalink
Region filter adjustments.
Browse files Browse the repository at this point in the history
Regions now stored by the back end and returned to the front end.
This allows it to be manipulated easier. Also allows the regions to
exists for all current spots even if filtered out.

Fies #47
  • Loading branch information
cwhelchel committed Jan 20, 2025
1 parent 0861231 commit e45ee6d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/@types/Spots.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export interface SpotRow {
loc_total: number,
is_qrt: boolean,
act_cmts: string,
cw_wpm: number
cw_wpm: number,
spot_source: string
};
9 changes: 9 additions & 0 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,15 @@ def import_park_data(self) -> str:

return self._response(
True, "Park data imported successfully", persist=True)

def get_seen_regions(self) -> str:
'''
Gets a sorted list of distinct regions (POTA) and associations (SOTA)
that are in the current set of spots.
'''
x = self.db.seen_regions
# logging.debug(f"return seen regions: {x}")
return self._response(True, '', seen_regions=x)

def _do_update(self):
'''
Expand Down
6 changes: 4 additions & 2 deletions src/components/FilterBar/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const FilterBar = (props: IFilterBarPros) => {
const [mode, setMode] = React.useState('');
const [band, setBand] = React.useState('');
const [region, setRegion] = React.useState('');
const [location, setLocation] = React.useState('');
const [loc, setLocation] = React.useState('');
const [sig, setSig] = React.useState('');
const [qrt, setQrt] = React.useState(true);
const [hunted, setHunted] = React.useState(false);
Expand Down Expand Up @@ -129,6 +129,8 @@ export const FilterBar = (props: IFilterBarPros) => {
onlyNew: false
};
setData(next);

location.reload();
};

function handleQrtSwitch(event: any, checked: boolean): void {
Expand Down Expand Up @@ -327,7 +329,7 @@ export const FilterBar = (props: IFilterBarPros) => {
<Select
labelId="location-lbl"
id="location"
value={location}
value={loc}
variant='standard'
sx={{ minWidth: 100 }}
onChange={handleLocationChange}
Expand Down
33 changes: 23 additions & 10 deletions src/components/SpotViewer/SpotViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import SpotTimeCell from './SpotTime';
import { SpotComments } from '../../@types/SpotComments';
import { getSummitInfo } from '../../pota';
import { Summit } from '../../@types/Summit';
import { checkApiResponse } from '../../util';

// https://mui.com/material-ui/react-table/

Expand Down Expand Up @@ -165,23 +166,35 @@ export default function SpotViewer() {

// when [spots] are set, update regions
React.useEffect(() => {
// parse the current spots and pull out the region specifier from each
// location
// the backend will parse out the regions for pota and sota (US, CA, W7)
// and we will just set the available regions directly in the context.
// however, we still parse the current spots and pull out the
// location specifier (US-GA, CA-ON) for POTA spots only

if (contextData.locationFilter === "")
contextData.locations = [];

spots.map((spot) => {
let region = spot.locationDesc.substring(0, 2);
if (!contextData.regions.includes(region))
contextData.regions.push(region);
if (window.pywebview === undefined) {
return;
}

let location = spot.locationDesc.substring(0, 5);
if (!contextData.locations.includes(location))
contextData.locations.push(location);
const p = window.pywebview.api.get_seen_regions();
p.then((x: string) => {
let json = checkApiResponse(x, contextData, setData);
if (json.success) {
contextData.regions = json.seen_regions;
setData(contextData);
}
});

spots.map((spot) => {
if (spot.spot_source == 'POTA') {
let location = spot.locationDesc.substring(0, 5);
if (!contextData.locations.includes(location))
contextData.locations.push(location);
}
});
contextData.locations.sort();
setData(contextData);
}, [spots]);

async function getOtherOps(spotId: number): Promise<string> {
Expand Down
12 changes: 12 additions & 0 deletions src/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(self):
self._sq.delete_all_spots()
self._iq.init_config()

self.seen_regions = []
self.band_filter = Bands.NOBAND
self.region_filter = None
self.location_filter = None
Expand Down Expand Up @@ -175,6 +176,8 @@ def update_all_spots(self, spots_json, sota_spots):

# self._sq.insert_test_spot() # testing code

regions = list[str]()

for s in spots_json:
to_add: Spot = schema.load(s, session=self.session)
to_add.spot_source = 'POTA'
Expand All @@ -189,6 +192,7 @@ def update_all_spots(self, spots_json, sota_spots):
x, y = self._lq.get_location_hunts(to_add.locationDesc)
to_add.loc_hunts = x
to_add.loc_total = y
regions.append(to_add.locationDesc[0:2])

to_add.is_qrt = False

Expand All @@ -207,6 +211,9 @@ def update_all_spots(self, spots_json, sota_spots):
sota_to_add = Spot()
sota_to_add.init_from_sota(sota)

# this is sota association code
regions.append(sota_to_add.locationDesc)

statement = sa.select(Spot) \
.filter_by(activator=sota['activatorCallsign']) \
.filter_by(spot_source='SOTA') \
Expand All @@ -227,6 +234,11 @@ def update_all_spots(self, spots_json, sota_spots):

self.session.commit()

# set regions list to be used by filter front end
regions = list(set(regions))
regions.sort()
self.seen_regions = regions

def update_spot(self, spot_id: int, call: str, ref: str):
logging.info(f"doing single spot update {spot_id}")
to_mod: Spot = self.spots.get_spot(spot_id)
Expand Down

0 comments on commit e45ee6d

Please sign in to comment.