Display age of data

This commit is contained in:
clerie 2020-04-11 15:58:29 +02:00
parent cb6e845d52
commit ccc89c80ba
3 changed files with 24 additions and 3 deletions

View File

@ -2,6 +2,8 @@
from wetter import db
from datetime import datetime, timedelta
class Stations(db.Model):
__tablename__ = 'stations'
id = db.Column(db.Integer, primary_key=True)
@ -13,6 +15,19 @@ class Stations(db.Model):
state = db.Column(db.String)
sea_level = db.Column(db.Integer)
def climate_date_range(self):
r = db.session.query(db.func.min(Climate.date), db.func.max(Climate.date)).filter_by(station=self.id).one()
return {"min": r[0], "max": r[1]}
def climate_date_old(self):
return self.climate_date_range()["max"] < (datetime.today().date() - timedelta(days=1))
def climate_count(self):
return db.session.query(db.func.count(Climate.id)).filter_by(station=self.id).one()[0]
def __str__(self):
return self.name
class Climate(db.Model):
__tablename__ = 'climate'
id = db.Column(db.Integer, primary_key=True)

View File

@ -27,13 +27,13 @@
<div class="col-sm-6">
<div class="form-group">
<label for="datetimepicker-from">von</label>
<input type="date" value="{{ fr }}" name="from" class="form-control" id="datetimepicker-from" required max="{{ today }}">
<input type="date" value="{{ fr }}" name="from" class="form-control" id="datetimepicker-from" required min="{{ station.climate_date_range()["min"] }}" max="{{ station.climate_date_range()["max"] }}">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="datetimepicker-to">bis</label>
<input type="date" value="{{ to }}" name="to" class="form-control" id="datetimepicker-to" required max="{{ today }}">
<input type="date" value="{{ to }}" name="to" class="form-control" id="datetimepicker-to" required min="{{ station.climate_date_range()["min"] }}" max="{{ station.climate_date_range()["max"] }}">
</div>
</div>
</div>

View File

@ -9,6 +9,11 @@
{% block content %}
<section>
{% if station.climate_date_old() %}
<div class="alert alert-danger" role="alert">
Die letzten Messwerte zu dieser Station sind von {{ station.climate_date_range()["max"] }}.
</div>
{% endif %}
<div class="card ">
<div class="embed-responsive embed-responsive-16by9">
<div class="clickoverlay embed-responsive-item">
@ -60,6 +65,7 @@
</div>
<div class="list-group list-group-flush">
<a href="https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/daily/kl/recent/tageswerte_KL_{{ station.dwd_id }}_akt.zip" class="list-group-item" target="_blank">Aktueller Source vom DWD</a>
<div class="list-group-item">Bereich Messdaten: {{ station.climate_date_range()["min"] }} - {{ station.climate_date_range()["max"] }}</div>
<div class="list-group-item">Letztes Update: {{ station.dwd_last_update }}</div>
</div>
</div>