Skip to content

Commit cd8004a

Browse files
committed
Provider's improvements
- create or update save_clusters document with min/max clusters - new metar provider urls - raise an exception if there is no provider info
1 parent 181230f commit cd8004a

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

admin_jobs/save_clusters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def save_clusters(nb_clusters):
2323
mongo_db.stations.find({"status": {"$ne": "hidden"}, "last._id": {"$gt": now - 30 * 24 * 3600}})
2424
)
2525
range_clusters = np.geomspace(20, len(all_stations), num=nb_clusters, dtype=int)
26+
mongo_db.stations_clusters.find_one_and_update(
27+
{"_id": "save_clusters"}, {"$set": {"min": 20, "max": len(all_stations)}}, upsert=True
28+
)
2629

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

providers/metar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import io
22
import json
33
import math
4-
import os
54
from gzip import GzipFile
65
from random import randint
76

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

8887
station_id = station["_id"]

winds_mobi_provider/provider.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class StationStatus(Enum):
3434

3535

3636
class Provider:
37-
provider_code = ""
38-
provider_name = ""
39-
provider_url = ""
37+
provider_code = None
38+
provider_name = None
39+
provider_url = None
4040

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

5656
def __init__(self):
57+
if None not in (self.provider_code, self.provider_name, self.provider_url):
58+
raise ProviderException("Missing provider_code, provider_name or provider_url")
5759
self.mongo_db = MongoClient(MONGODB_URL).get_database()
5860
self.__stations_collection = self.mongo_db.stations
5961
self.__stations_collection.create_index(

0 commit comments

Comments
 (0)