Created
November 24, 2020 08:01
-
-
Save Bertik23/a0a39adf925108c2b412dd2aa830ebf6 to your computer and use it in GitHub Desktop.
Python script pro počítání rizikového indexu protiepidemiologického sysému (PES).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import datetime | |
from math import inf | |
import time | |
start = time.time() | |
data = requests.get("https://onemocneni-aktualne.mzcr.cz/api/v2/covid-19/orp.json").json()["data"] | |
print(time.time()-start) | |
now = datetime.date.today() | |
yesterDay = now.replace(day=now.day-1) | |
def pozitivni(now): | |
last14days = 0 | |
last14days65 = 0 | |
for orp in reversed(data): | |
if now - datetime.date.fromisoformat(orp["datum"]) < datetime.timedelta(days=14): | |
if (now - datetime.date.fromisoformat(orp["datum"])) % datetime.timedelta(days=7) == datetime.timedelta(days=0): | |
#print(orp["datum"]) | |
last14days += orp["incidence_7"] | |
last14days65 += orp["incidence_65_7"] | |
else: | |
break | |
return (last14days/10693939)*100000, (last14days65/2131630)*100000 | |
def R(now): | |
R = [[],[]] | |
for orp in reversed(data): | |
if now - datetime.date.fromisoformat(orp["datum"]) < datetime.timedelta(days=10): | |
if (now - datetime.date.fromisoformat(orp["datum"])) % datetime.timedelta(days=5) == datetime.timedelta(days=0): | |
#print(orp["datum"]) | |
R[0 if now == datetime.date.fromisoformat(orp["datum"]) else 1].append(orp["incidence_7"]) | |
else: | |
break | |
return sum(R[0])/sum(R[1]) | |
def pozitivitaTestu(now): | |
testy = 0 | |
last7days = 0 | |
for orp in reversed(data): | |
if datetime.date.fromisoformat(orp["datum"]) == now: | |
testy += orp["testy_7"] | |
last7days += orp["incidence_7"] | |
return last7days/testy | |
def index(now): | |
yesterDay = now.replace(day=now.day-1) | |
pozitivitaDict = {10:0,25:2,50:4,120:7,240:10,480:13,960:16,inf:20} | |
rDict = {0.8:0, 1.0:5, 1.2:10, 1.4:15,1.6:20,1.9:25,inf:30} | |
testyDict = {0.03:0,0.07:3,0.11:7, 0.15:11,0.19:15,0.23:20,0.26:25,inf:30} | |
pY = pozitivni(yesterDay) | |
pW = pozitivni(now.replace(day=now.day-7)) | |
body = [] | |
allBreak = False | |
oldBreak = False | |
for p in pozitivitaDict: | |
if pY[0] < p and not allBreak: | |
body.append(pozitivitaDict[p]) | |
allBreak = True | |
if pY[1] < p and not oldBreak: | |
body.append(pozitivitaDict[p]) | |
oldBreak = True | |
if oldBreak and allBreak: | |
break | |
if pY[1] > pW[1]: | |
body.append(2) | |
r = R(yesterDay) | |
for p in rDict: | |
if r < p: | |
body.append(rDict[p]) | |
break | |
t = pozitivitaTestu(yesterDay) | |
for p in testyDict: | |
if t < p: | |
body.append(testyDict[p]) | |
break | |
if t > pozitivitaTestu(now.replace(day=now.day-7)): | |
body.append(2) | |
print(body) | |
return sum(body) | |
print(pozitivni(yesterDay), R(yesterDay), pozitivitaTestu(yesterDay)) | |
print(time.time()-start) | |
print(index(now)) | |
print(time.time()-start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment