From 5f58ca130c68f601bad23c999abace4b8782e512 Mon Sep 17 00:00:00 2001 From: Kevin Donahue Date: Sun, 30 Jun 2024 17:56:54 -0400 Subject: [PATCH] use mpsas as response key --- api/README.md | 2 +- api/api/main.py | 3 ++- api/api/models.py | 3 +-- api/api/tests/test_prediction_api.py | 8 ++------ pp/pp/prediction.py | 6 +++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/api/README.md b/api/README.md index 0a8769e..abecbed 100644 --- a/api/README.md +++ b/api/README.md @@ -49,7 +49,7 @@ curl "http://localhost:8000/api/v1/predict?lat=-30.2466&lon=-70.7494" ```json { - "sky_brightness": 22.0388 + "mpsas": 22.0388 } ``` diff --git a/api/api/main.py b/api/api/main.py index e0eeb0b..3a569bc 100644 --- a/api/api/main.py +++ b/api/api/main.py @@ -27,9 +27,10 @@ def get_log_config(): def create_prediction_response(prediction_obj: Prediction) -> PredictionResponse: + """create the object that is ultimately served to clients as the prediction response.""" precision_digits = 4 y = round(float(prediction_obj.y.item()), precision_digits) - return PredictionResponse(sky_brightness=y) + return PredictionResponse(mpsas=y) @main_router.get("/predict") diff --git a/api/api/models.py b/api/api/models.py index 3bae507..ff423d8 100644 --- a/api/api/models.py +++ b/api/api/models.py @@ -3,5 +3,4 @@ @dataclass class PredictionResponse: - """in magnitudes per square arcsecond""" - sky_brightness: float + mpsas: float diff --git a/api/api/tests/test_prediction_api.py b/api/api/tests/test_prediction_api.py index 95d83d6..f6eff5a 100644 --- a/api/api/tests/test_prediction_api.py +++ b/api/api/tests/test_prediction_api.py @@ -8,11 +8,6 @@ API_PREFIX = f"/api/{api_version}" -def test_get_prediction_bad_status_without_lat_lon(): - r = client.get(f"{API_PREFIX}/predict") - assert r.status_code != 200 - - @pytest.mark.parametrize("coords, lowerbound, upperbound", [ ((-30.2466, -70.7494), 6, 25), ((19.8264, -155.4750), 6, 28) @@ -20,6 +15,7 @@ def test_get_prediction_bad_status_without_lat_lon(): def test_prediction(coords, lowerbound, upperbound): lat, lon = coords response = client.get(f"{API_PREFIX}/predict?lat={lat}&lon={lon}") + # assert response.json() == {} assert response.status_code == 200 - brightness = response.json()["sky_brightness"] + brightness = response.json()["mpsas"] assert lowerbound <= brightness <= upperbound diff --git a/pp/pp/prediction.py b/pp/pp/prediction.py index 44c99ca..f315c25 100644 --- a/pp/pp/prediction.py +++ b/pp/pp/prediction.py @@ -23,7 +23,7 @@ def get_cell_id(lat, lon) -> str: """get the h3 cell for this lat and lon""" - return h3.geo_to_h3(lat, lon, resolution=0)[0] + return h3.geo_to_h3(lat, lon, resolution=0) async def create_brightness_message(client: httpx.AsyncClient, h3_lat: float, h3_lon: float) -> BrightnessMessage: @@ -33,7 +33,7 @@ async def create_brightness_message(client: httpx.AsyncClient, h3_lat: float, h3 data = res.json() - if (mpsas := data.get("sky_brightness", None)) is None: + if (mpsas := data.get("mpsas", None)) is None: raise ValueError("no sky brightness reading in api response") utc_now = datetime.utcnow() @@ -58,7 +58,7 @@ async def publish_cell_brightness(client: httpx.AsyncClient, h3_coords: Tuple[fl m = await create_brightness_message(client, lat, lon) message_body = asdict(m) - log.info(f"publishing {message_body} to {prediction_queue}") + log.info(f"publishing brightness message {message_body}") channel.basic_publish(exchange="", routing_key=prediction_queue, body=json.dumps(message_body)) keydb.incr(m.h3_id)