Skip to content

Instantly share code, notes, and snippets.

@tytydraco
Created April 15, 2020 23:47
Show Gist options
  • Save tytydraco/7b7570011f61893d61c747b31795e64e to your computer and use it in GitHub Desktop.
Save tytydraco/7b7570011f61893d61c747b31795e64e to your computer and use it in GitHub Desktop.
Cubic Spline of current data from WHO
import urllib.request, json
import matplotlib.pyplot as plt
import numpy
from scipy.interpolate import *
with urllib.request.urlopen("https://pomber.github.io/covid19/timeseries.json") as url:
data = json.loads(url.read().decode())
date = []
for report in data['US']:
date.append(report["date"])
confirmed = [0] * len(date)
deaths = [0] * len(date)
recovered = [0] * len(date)
for country in data:
_confirmed = []
_deaths = []
_recovered = []
for report in data[country]:
_confirmed.append(report["confirmed"])
_deaths.append(report["deaths"])
_recovered.append(report["recovered"])
for i in range(0, len(date)):
confirmed[i] = (confirmed[i] + _confirmed[i])
deaths[i] = (deaths[i] + _deaths[i])
recovered[i] = (recovered[i] + _recovered[i])
days_from_start = numpy.arange(len(date))
confirmed_f = CubicSpline(days_from_start, confirmed, extrapolate=True)
deaths_f = CubicSpline(days_from_start, deaths, extrapolate=True)
recovered_f = CubicSpline(days_from_start, recovered, extrapolate=True)
year = numpy.arange(100)
plt.axhline(y=0, color='black')
plt.axvline(x=days_from_start[-1], color='black')
plt.axhline(y=7794798739, color='black')
plt.plot(year, confirmed_f(year), color='y')
plt.plot(year, deaths_f(year), color='r')
plt.plot(year, recovered_f(year), color='b')
plt.ylim(-7794798739, 7794798739)
plt.ticklabel_format(style='plain')
plt.ylabel("People")
plt.xlabel(f"Days since {date[0]}")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment