Skip to content

Commit

Permalink
Provider's improvements
Browse files Browse the repository at this point in the history
- create or update save_clusters document with min/max clusters
- new metar provider urls
- raise an exception if there is no provider info
  • Loading branch information
ysavary committed Jul 13, 2024
1 parent 181230f commit cd8004a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions admin_jobs/save_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def save_clusters(nb_clusters):
mongo_db.stations.find({"status": {"$ne": "hidden"}, "last._id": {"$gt": now - 30 * 24 * 3600}})
)
range_clusters = np.geomspace(20, len(all_stations), num=nb_clusters, dtype=int)
mongo_db.stations_clusters.find_one_and_update(
{"_id": "save_clusters"}, {"$set": {"min": 20, "max": len(all_stations)}}, upsert=True
)

ids = np.array([station["_id"] for station in all_stations])

Expand Down
3 changes: 1 addition & 2 deletions providers/metar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
import json
import math
import os
from gzip import GzipFile
from random import randint

Expand Down Expand Up @@ -82,7 +81,7 @@ def get_station_names(names: StationNames) -> StationNames:
station["lon"],
StationStatus.GREEN,
altitude=station["elev"],
url=os.path.join(self.provider_url),
url=f"{self.provider_url}/data/metar/?id=${metar_id}&hours=0&decoded=yes&include_taf=yes",
)

station_id = station["_id"]
Expand Down
8 changes: 5 additions & 3 deletions winds_mobi_provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class StationStatus(Enum):


class Provider:
provider_code = ""
provider_name = ""
provider_url = ""
provider_code = None
provider_name = None
provider_url = None

connect_timeout = 7
read_timeout = 30
Expand All @@ -54,6 +54,8 @@ def google_api_cache_duration(self):
return (60 + randint(-5, 5)) * 24 * 3600

def __init__(self):
if None not in (self.provider_code, self.provider_name, self.provider_url):
raise ProviderException("Missing provider_code, provider_name or provider_url")
self.mongo_db = MongoClient(MONGODB_URL).get_database()
self.__stations_collection = self.mongo_db.stations
self.__stations_collection.create_index(
Expand Down

0 comments on commit cd8004a

Please sign in to comment.