From d3caed4241328258dee6190463bae8b4b5f3800d Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 28 Sep 2020 14:39:59 +0300 Subject: Use grouped predictions for dates in table --- iss/predictions.py | 16 ++++++++++++++++ iss/server.py | 2 +- iss/templates/index.html | 31 ++++++++++++++++++------------- iss/tests/test_predictions.py | 12 ++++++++++++ 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/iss/predictions.py b/iss/predictions.py index bab9f17..df6326a 100644 --- a/iss/predictions.py +++ b/iss/predictions.py @@ -1,3 +1,4 @@ +from collections import defaultdict from skyfield.api import Topos, load from .utils import chunks @@ -90,3 +91,18 @@ class Predictions(object): def get_predictions(self): preds = self.get_prediction_events() return [self.get_prediction_details(*p) for p in preds] + + def truncate_prediction_dates(self, pred): + for t in ["rise", "culminate", "set"]: + pred[t]["time"] = pred[t]["time"][11:] + return pred + + def get_grouped_predictions(self): + preds = self.get_predictions() + res = defaultdict(list) + + for pred in preds: + date = pred["rise"]["time"][:10] + res[date].append(self.truncate_prediction_dates(pred)) + + return res diff --git a/iss/server.py b/iss/server.py index 90b2e58..d03cec4 100644 --- a/iss/server.py +++ b/iss/server.py @@ -13,7 +13,7 @@ templates = Jinja2Templates(directory="iss/templates") @app.get("/") async def home(request: Request): - preds = Predictions(34.7641, 32.0669, altitude=10).get_predictions() + preds = Predictions(34.7641, 32.0669, altitude=0, days=5).get_grouped_predictions() return templates.TemplateResponse( "index.html", {"request": request, "predictions": preds} ) diff --git a/iss/templates/index.html b/iss/templates/index.html index 5c498c7..e29da64 100644 --- a/iss/templates/index.html +++ b/iss/templates/index.html @@ -2,13 +2,14 @@ {% block content %}
| Total | Rise | Culminate | Set | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Date | Length | Time | Azimuth | @@ -19,18 +20,22 @@Time | Azimuth | ||||
| {{ pred.length }} | -{{ pred.rise.time }} | -{{ pred.rise.azimuth }} | -{{ pred.culminate.time }} | -{{ pred.culminate.azimuth }} | -{{ pred.culminate.degrees }} | -{{ pred.culminate.distance }} | -{{ pred.set.time }} | -{{ pred.set.azimuth }} | -|
| {{ date }} | {% endif %} +{{ pred.length }} | +{{ pred.rise.time }} | +{{ pred.rise.azimuth }} | +{{ pred.culminate.time }} | +{{ pred.culminate.azimuth }} | +{{ pred.culminate.degrees }} | +{{ pred.culminate.distance }} | +{{ pred.set.time }} | +{{ pred.set.azimuth }} | +