<jupyter_start><jupyter_text><jupyter_code>!pip install matplotlib
!pip install numpy
!pip install scipy
!pip install pandas
import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.colors as mplcol
import matplotlib.font_manager
import matplotlib as mpl
import pandas as pd
import json
import datetime as dt
import time



fsize=20

plt.rcParams.update({'font.size': fsize})
%config InlineBackend.figure_format = 'retina'
!printf "[info] Processing notebook"
!mkdir -p plots
!wget https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv
pop = 2_180_085
norm = 100_000
time_delta = 14 # days ie 2 weeks
lag = 2 # days
df = pd.read_csv("us-counties.csv").query("county=='San Bernardino'")
df = df.set_index(pd.to_datetime(df.date.values)).sort_index()
#data = (df["cases"].rolling(window="14d").sum()/pop*norm)[time_delta:]
data = np.array([df["cases"].values[i+14]-df["cases"].values[i] for i in range(0, df.shape[0]-14)])
dates = pd.to_datetime([df["date"].values[i+14] for i in range(0, df.shape[0]-14)])

per_diem = np.array([df["cases"].values[i+14]-df["cases"].values[i+13] for i in range(0, df.shape[0]-14)])
fig, ax = plt.subplots(figsize=(14, 7))

x = dates.date
y = data*norm/pop

yy = per_diem*norm/pop
# xx = df.index.max() - dt.timedelta(days=lag)

ax.plot(x,  y, color="k", label="14 day rolling sum")
ax.bar(x, yy, color="grey", label="New cases per day")
ax.axhline(y=200, color="blue", label="TK-6th grade threshold")
ax.axhline(y=100, color="orange", label="TK-12th grade threshold")
# ax.axvline(x=xx, label="Date after which data may be incomplete", color="grey", linestyle="--")

kwd = {
    "xlabel": "Date",
    "ylabel" : "Positive cases per 100,000"
}

myFmt = mpl.dates.DateFormatter('%Y-%m-%d')
ax.xaxis.set_major_formatter(myFmt)
# 
# ## Rotate date labels automatically
fig.autofmt_xdate()
# 
ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}'))
ax.set(**kwd)
ax.legend()

plt.savefig("./plots/graph.png",bbox_inches='tight', dpi=300)

fig.show()
fig, ax = plt.subplots(figsize=(14, 7))

x = dates.date

y = per_diem*norm/pop


ax.bar(x, y, color="grey", label="New cases per day")

ax.axhline(y=7, color="purple", label="Widespread")
ax.axhline(y=4, color="red", label="Substantial")
ax.axhline(y=1, color="orange", label="Moderate")

kwd = {
    "xlabel": "Date",
    "ylabel" : "Positive cases per 100,000"
}

myFmt = mpl.dates.DateFormatter('%Y-%m-%d')
ax.xaxis.set_major_formatter(myFmt)
# 
# ## Rotate date labels automatically
fig.autofmt_xdate()
# 
ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}'))
ax.set(**kwd)
ax.legend()

plt.savefig("./plots/classification.png",bbox_inches='tight', dpi=300)

fig.show()
!printf "[info] Finished processing notebook"
!pip3 freeze > requirements.txt<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18178633975481612, 'fraction_numerical': 0.029422066549912435, 'mean_word_length': 5.735849056603773, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '442854', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1104, 'n_words': 225, 'path': 'SB_County_Triggers.ipynb', 'repo_name': 'jonatdr/COVID19-County', 'size': '2855'}