Skip to content

Commit

Permalink
use mpsas as response key
Browse files Browse the repository at this point in the history
  • Loading branch information
nonnontrivial committed Jun 30, 2024
1 parent 274d101 commit 5f58ca1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down
3 changes: 2 additions & 1 deletion api/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

@dataclass
class PredictionResponse:
"""in magnitudes per square arcsecond"""
sky_brightness: float
mpsas: float
8 changes: 2 additions & 6 deletions api/api/tests/test_prediction_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
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)
])
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
6 changes: 3 additions & 3 deletions pp/pp/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 5f58ca1

Please sign in to comment.