|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import toml
|
|
|
|
|
import os
|
|
|
|
|
import db_model as db
|
|
|
|
|
from peewee import SqliteDatabase
|
|
|
|
|
from peewee import fn
|
|
|
|
|
from peewee import PostgresqlDatabase
|
|
|
|
|
import datetime
|
|
|
|
|
from sshtunnel import SSHTunnelForwarder
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def config_laden():
|
|
|
|
@ -29,26 +30,15 @@ def verdoppelungsrate_ermitteln(quelle, land, confirmed, confirmed_ts):
|
|
|
|
|
return verdoppelungstage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def letzte_verdopplungsrate(quelle, land):
|
|
|
|
|
query = db.CoronaDaten.select(db.CoronaDaten.ts, fn.max(db.CoronaDaten.confirmed).alias("confirmed")).where(
|
|
|
|
|
(db.CoronaDaten.quelle == quelle) & (db.CoronaDaten.country_region == land)).dicts()
|
|
|
|
|
for datensatz in query:
|
|
|
|
|
verdoppelung = verdoppelungsrate_ermitteln(quelle, land, datensatz["confirmed"], datensatz["ts"])
|
|
|
|
|
print(verdoppelung)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def durchschnittliche_verdoppelungsrate(quelle, land):
|
|
|
|
|
def letzte_verdopplungsraten(quelle, land, ts):
|
|
|
|
|
query = db.CoronaDaten.select(db.CoronaDaten.ts, db.CoronaDaten.confirmed).where(
|
|
|
|
|
(db.CoronaDaten.quelle == quelle) & (db.CoronaDaten.country_region == land)
|
|
|
|
|
).namedtuples()
|
|
|
|
|
|
|
|
|
|
verdoppelungsraten = []
|
|
|
|
|
(db.CoronaDaten.quelle == quelle) & (db.CoronaDaten.country_region == land) & (db.CoronaDaten.ts > ts)).dicts()
|
|
|
|
|
for datensatz in query:
|
|
|
|
|
verdoppelungsrate = verdoppelungsrate_ermitteln(quelle, land, datensatz.confirmed, datensatz.ts)
|
|
|
|
|
verdoppelungsrate = verdoppelungsrate_ermitteln(quelle, land, datensatz["confirmed"], datensatz["ts"])
|
|
|
|
|
if verdoppelungsrate is not None:
|
|
|
|
|
verdoppelungsraten.append(verdoppelungsrate)
|
|
|
|
|
durchschnitt = sum(verdoppelungsraten) / len(verdoppelungsraten)
|
|
|
|
|
print(verdoppelungsrate_in_tagen(durchschnitt))
|
|
|
|
|
verdoppelungsrate_tage = round(verdoppelungsrate_in_tagen(verdoppelungsrate), 3)
|
|
|
|
|
print(f"Verdoppelungsrate am {datensatz['ts']}: {verdoppelungsrate_tage}")
|
|
|
|
|
print("Verlasse letzte_Verdoppelungsraten")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def jede_verdoppelungsrate(quelle, land):
|
|
|
|
@ -57,7 +47,9 @@ def jede_verdoppelungsrate(quelle, land):
|
|
|
|
|
).order_by(db.CoronaDaten.ts.desc()).namedtuples()
|
|
|
|
|
for datensatz in query:
|
|
|
|
|
verdoppelungsrate = verdoppelungsrate_ermitteln(quelle, land, datensatz.confirmed, datensatz.ts)
|
|
|
|
|
print(f"Verdoppelungsrate am {datensatz.ts}: {verdoppelungsrate_in_tagen(verdoppelungsrate)}")
|
|
|
|
|
if verdoppelungsrate is not None:
|
|
|
|
|
verdoppelungsrate_tage = round(verdoppelungsrate_in_tagen(verdoppelungsrate), 3)
|
|
|
|
|
print(f"Verdoppelungsrate am {datensatz.ts}: {verdoppelungsrate_tage}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def verdoppelungsrate_in_tagen(verdoppelungsrate):
|
|
|
|
@ -68,12 +60,25 @@ def verdoppelungsrate_in_tagen(verdoppelungsrate):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
db.DATABASE.initialize(SqliteDatabase(os.path.join(SKRIPTPFAD, "corona.db3")))
|
|
|
|
|
for quelle in QUELLEN:
|
|
|
|
|
query = db.CoronaCountry.select().where(db.CoronaCountry.quelle == quelle)
|
|
|
|
|
for datensatz in query:
|
|
|
|
|
if quelle == "jhu" and datensatz.country_region == "Germany":
|
|
|
|
|
jede_verdoppelungsrate(quelle, datensatz.country_region)
|
|
|
|
|
with SSHTunnelForwarder(
|
|
|
|
|
(CONFIG["ssh"]["ip_server"], CONFIG["ssh"]["ssh_port"]), ssh_username=CONFIG["ssh"]["user"],
|
|
|
|
|
ssh_password=CONFIG["ssh"]["pw"], remote_bind_address=('127.0.0.1', CONFIG["pg"]["pgport"])) as server:
|
|
|
|
|
|
|
|
|
|
db.database.initialize(PostgresqlDatabase(CONFIG["pg"]["pgdb"],
|
|
|
|
|
user=CONFIG["pg"]["pguser"], password=CONFIG["pg"]["pgpw"],
|
|
|
|
|
host="127.0.0.1",
|
|
|
|
|
port=server.local_bind_port))
|
|
|
|
|
|
|
|
|
|
query_quelle = db.CoronaDaten.select(db.CoronaDaten.quelle).group_by(db.CoronaDaten.quelle)
|
|
|
|
|
for data in query_quelle:
|
|
|
|
|
query_country = db.CoronaDaten.select(
|
|
|
|
|
db.CoronaDaten.country_region).where(db.CoronaDaten.quelle == data.quelle
|
|
|
|
|
).group_by(db.CoronaDaten.country_region)
|
|
|
|
|
for datensatz in query_country:
|
|
|
|
|
if data.quelle == "jhu" and datensatz.country_region == "Germany":
|
|
|
|
|
letzte_verdopplungsraten(data.quelle, datensatz.country_region, datetime.datetime(2020, 4, 3))
|
|
|
|
|
print("Verlasse schleife")
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|