Skip to content

Commit

Permalink
use configurable log level
Browse files Browse the repository at this point in the history
  • Loading branch information
nonnontrivial committed Jun 25, 2024
1 parent adf35c0 commit 72fa55f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion api/api/prediction/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)


Expand Down
2 changes: 1 addition & 1 deletion pp/pp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions pp/pp/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@ 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

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:
Expand Down

0 comments on commit 72fa55f

Please sign in to comment.