Compare commits
No commits in common. "7d5aa34a6e2378d82199f26652b8f5d5682b4cfd" and "88148e04e1496c20b23819cf36bdea7913995aba" have entirely different histories.
7d5aa34a6e
...
88148e04e1
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -152,4 +152,3 @@ cython_debug/
|
|||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
*.csv
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
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)
|
||||
]
|
||||
)
|
|
@ -1,2 +0,0 @@
|
|||
thefuzz[speedup]
|
||||
blessed
|
Loading…
Reference in New Issue
Block a user