Compare commits
2 Commits
88148e04e1
...
7d5aa34a6e
Author | SHA1 | Date | |
---|---|---|---|
7d5aa34a6e | |||
2349ca8056 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -152,3 +152,4 @@ cython_debug/
|
|||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
*.csv
|
||||
|
|
91
pota_search.py
Normal file
91
pota_search.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
import csv
|
||||
import sys
|
||||
import dataclasses
|
||||
import thefuzz.fuzz, thefuzz.process
|
||||
import typing
|
||||
import itertools
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Park:
|
||||
reference: str
|
||||
name: str
|
||||
location: typing.List[str]
|
||||
latitude: float
|
||||
longitude: float
|
||||
grid: str
|
||||
attempts: int
|
||||
activations: int
|
||||
qsos: int
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class ParkDatabase:
|
||||
parks: typing.List[Park]
|
||||
|
||||
def __post_init__(self):
|
||||
self.parks_dict = {park.reference: park for park in self.parks}
|
||||
|
||||
def search_name(self, string):
|
||||
return [
|
||||
self.parks_dict[i[0].split("|")[0]]
|
||||
for i in thefuzz.process.extract(
|
||||
string,
|
||||
[park.reference + "|" + park.name for park in self.parks],
|
||||
scorer=thefuzz.fuzz.partial_ratio,
|
||||
)
|
||||
]
|
||||
|
||||
def filter_location(self, location):
|
||||
location = location.upper()
|
||||
return ParkDatabase(
|
||||
[
|
||||
park
|
||||
for park in self.parks
|
||||
if (location in park.location)
|
||||
or (
|
||||
location
|
||||
in [
|
||||
park_location.split("-")[0]
|
||||
for park_location in park.location
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
def get_locations(self):
|
||||
return _uniq(itertools.chain(*[park.location for park in self.parks]))
|
||||
|
||||
def get_expanded_locations(self):
|
||||
return _uniq(_expand_locations(self.get_locations()))
|
||||
|
||||
|
||||
def _uniq(data):
|
||||
return sorted(set(data))
|
||||
|
||||
|
||||
def _expand_location(code):
|
||||
return code, code.split("-")[0]
|
||||
|
||||
|
||||
def _expand_locations(codes):
|
||||
return itertools.chain(*[_expand_location(code) for code in codes])
|
||||
|
||||
|
||||
def load_csv(f):
|
||||
return ParkDatabase(
|
||||
[
|
||||
Park(
|
||||
park["reference"],
|
||||
park["name"],
|
||||
park["locationDesc"].split(","),
|
||||
float(park["latitude"]),
|
||||
float(park["longitude"]),
|
||||
park["grid"],
|
||||
int(park["attempts"]),
|
||||
int(park["activations"]),
|
||||
int(park["qsos"]),
|
||||
)
|
||||
for park in csv.DictReader(f)
|
||||
]
|
||||
)
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
thefuzz[speedup]
|
||||
blessed
|
Loading…
Reference in New Issue
Block a user