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 wetter import db
from datetime import datetime, timedelta
class Stations(db.Model): class Stations(db.Model):
__tablename__ = 'stations' __tablename__ = 'stations'
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
@ -13,6 +15,19 @@ class Stations(db.Model):
state = db.Column(db.String) state = db.Column(db.String)
sea_level = db.Column(db.Integer) 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): class Climate(db.Model):
__tablename__ = 'climate' __tablename__ = 'climate'
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)

View File

@ -27,13 +27,13 @@
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="datetimepicker-from">von</label> <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> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="datetimepicker-to">bis</label> <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> </div>
</div> </div>

View File

@ -9,6 +9,11 @@
{% block content %} {% block content %}
<section> <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="card ">
<div class="embed-responsive embed-responsive-16by9"> <div class="embed-responsive embed-responsive-16by9">
<div class="clickoverlay embed-responsive-item"> <div class="clickoverlay embed-responsive-item">
@ -51,7 +56,7 @@
</div> </div>
</div> </div>
</div> </div>
<a href="/station/{{ station.dwd_id }}/export/" class="btn btn-lg btn-block btn-outline-primary">Exportieren</a> <a href="/station/{{ station.dwd_id }}/export/" class="btn btn-lg btn-block btn-outline-primary">Exportieren</a>
<div class="card"> <div class="card">
@ -60,6 +65,7 @@
</div> </div>
<div class="list-group list-group-flush"> <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> <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 class="list-group-item">Letztes Update: {{ station.dwd_last_update }}</div>
</div> </div>
</div> </div>