diff options
Diffstat (limited to 'iss')
| -rw-r--r-- | iss/predictions.py | 16 | ||||
| -rw-r--r-- | iss/server.py | 2 | ||||
| -rw-r--r-- | iss/templates/index.html | 31 | ||||
| -rw-r--r-- | 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 %} <table class="tl pa1"> - <tr class="ba tc pa1 f3"> + <tr class=" tc pa1 f3"> <th colspan="1">Total</th> <th colspan="2">Rise</th> <th colspan="4">Culminate</th> <th colspan="2">Set</th> </tr> <tr class="pa1 f4"> + <th>Date</th> <th>Length</th> <th>Time</th> <th>Azimuth</th> @@ -19,18 +20,22 @@ <th>Time</th> <th>Azimuth</th> </tr> - {% for pred in predictions %} - <tr class="pa1"> - <td>{{ pred.length }}</td> - <td>{{ pred.rise.time }}</td> - <td>{{ pred.rise.azimuth }}</td> - <td>{{ pred.culminate.time }}</td> - <td>{{ pred.culminate.azimuth }}</td> - <td>{{ pred.culminate.degrees }}</td> - <td>{{ pred.culminate.distance }}</td> - <td>{{ pred.set.time }}</td> - <td>{{ pred.set.azimuth }}</td> - </tr> + {% for date, preds in predictions.items() %} + {% set date_loop = loop %} + {% for pred in preds %} + <tr class="pa2 {{ date_loop.cycle('light-gray', 'light-silver') }}"> + {% if loop.first %}<td rowspan="{{ preds|length }}">{{ date }}</td>{% endif %} + <td>{{ pred.length }}</td> + <td>{{ pred.rise.time }}</td> + <td>{{ pred.rise.azimuth }}</td> + <td>{{ pred.culminate.time }}</td> + <td>{{ pred.culminate.azimuth }}</td> + <td>{{ pred.culminate.degrees }}</td> + <td>{{ pred.culminate.distance }}</td> + <td>{{ pred.set.time }}</td> + <td>{{ pred.set.azimuth }}</td> + </tr> + {% endfor %} {% endfor %} </table> diff --git a/iss/tests/test_predictions.py b/iss/tests/test_predictions.py index 85dcf0a..29b939b 100644 --- a/iss/tests/test_predictions.py +++ b/iss/tests/test_predictions.py @@ -65,3 +65,15 @@ def test_get_predictions(): assert preds[0]["rise"]["azimuth"] == 347 assert preds[0]["culminate"]["degrees"] == 1 assert preds[0]["set"]["distance"] == 2364 + + +def test_get_grouped_predictions(): + start = 2459117.245895914 + p = Predictions( + lat=32.0853, lng=34.7817, tz="Asia/Jerusalem", start=start, tle_file=STATIONS + ) + preds = p.get_grouped_predictions() + assert "2020-09-28" in preds + assert preds["2020-09-28"][0]["rise"]["time"] == "10:14:44Z" + assert preds["2020-09-28"][1]["culminate"]["time"] == "11:51:14Z" + assert preds["2020-09-28"][1]["set"]["time"] == "11:56:36Z" |
