From 72fa55fb252569fb25222f4196439149e14786f6 Mon Sep 17 00:00:00 2001 From: Kevin Donahue Date: Tue, 25 Jun 2024 08:37:46 -0400 Subject: [PATCH] use configurable log level --- api/README.md | 2 ++ api/api/prediction/prediction.py | 3 ++- pp/pp/main.py | 2 +- pp/pp/prediction.py | 15 +++++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/api/README.md b/api/README.md index d06f955..749c84f 100644 --- a/api/README.md +++ b/api/README.md @@ -1,5 +1,7 @@ # api +api server for sky brightness. + ## Building and training the sky brightness model - `python -m api.model.build` to write the csv that the model trains on diff --git a/api/api/prediction/prediction.py b/api/api/prediction/prediction.py index 6fb7924..134e689 100644 --- a/api/api/prediction/prediction.py +++ b/api/api/prediction/prediction.py @@ -12,6 +12,7 @@ from .observer_site import ObserverSite from .constants import LOGFILE_KEY from .config import model_state_dict_file_name +from ..config import log_level logfile_name = os.getenv(LOGFILE_KEY) path_to_logfile = (Path.home() / logfile_name) if logfile_name else None @@ -20,7 +21,7 @@ format="%(asctime)s [%(levelname)s] %(message)s", filename=path_to_logfile if bool(path_to_logfile) else None, encoding="utf-8", - level=logging.DEBUG, + level=log_level, ) diff --git a/pp/pp/main.py b/pp/pp/main.py index 384d4aa..52a6dde 100644 --- a/pp/pp/main.py +++ b/pp/pp/main.py @@ -27,7 +27,7 @@ async def main(): except AMQPConnectionError as e: import sys - log.error(f"could not form amqp connection {e}") + log.error(f"could not form amqp connection; has rabbitmq started?") log.warning("exiting") sys.exit(1) except Exception as e: diff --git a/pp/pp/prediction.py b/pp/pp/prediction.py index 921c184..257e590 100644 --- a/pp/pp/prediction.py +++ b/pp/pp/prediction.py @@ -31,6 +31,9 @@ async def get_prediction_message_for_lat_lon(client: httpx.AsyncClient, lat: flo ) +# message_store = {} + + async def predict_on_cell_coords(client: httpx.AsyncClient, coords: Tuple[float, float], channel: Channel): """retrieve and publish a sky brightness prediction at coords for the h3 cell""" import json @@ -38,11 +41,15 @@ async def predict_on_cell_coords(client: httpx.AsyncClient, coords: Tuple[float, try: lat, lon = coords - prediction_message = await get_prediction_message_for_lat_lon(client, lat, lon) - message_body = asdict(prediction_message) - - log.info(f"publishing prediction message {message_body} with routing key {prediction_queue}") + m = await get_prediction_message_for_lat_lon(client, lat, lon) + message_body = asdict(m) channel.basic_publish(exchange="", routing_key=prediction_queue, body=json.dumps(message_body)) + + # keep track of how many messages are published for each cell + # message_store[m.h3_id] = message_store.get(m.h3_id, 0) + 1 + # with open("data.json", "w") as f: + # json.dump(message_store, f, indent=4) + except httpx.HTTPStatusError as e: log.error(f"got bad status from api server {e}") except Exception as e: