Another Covid Dashboard¶

Updates¶

Given that some people with COVID-19 had no symptoms or mild symptoms, the reported number of cases was never completely accurate. Now with widespread home testing, the reported cases are even less accurate.

Likely, COVID-19 is now or close to being endemic rather than a pandemic. Whatever term we use, COVID-19 is here to stay like the flu.

Updated Nov 27, 2022

Source¶

The US data comes from https://usafacts.org which was started by Steve Ballmer, the former CEO of Microsoft.

Contents¶

  1. US National data
  2. Southern California data
  3. Some US state data
  4. Julia source code

Roger Whitney
whitney@sdsu.edu
http://www.eli.sdsu.edu

US National Data¶

Plot the number of new cases per week in the country. Going back up but no one cares.

In [3]:
plot_country(county_new_weekly_covid)
Out[3]:

Southern California Data¶

Steep up and steep down.

In [4]:
plot_county("CA", "San Diego County ", county_new_weekly_covid)
Out[4]:
In [5]:
plot_county("CA", "Orange County ", county_new_weekly_covid)
Out[5]:
In [6]:
plot_county("CA", "Los Angeles County ", county_new_weekly_covid)
Out[6]:

US State Data¶

In [7]:
plot_state("CA", states_new_weekly_covid)
Out[7]:
In [8]:
plot_two_states("MN", "IL", states_new_weekly_covid)
Out[8]:
In [9]:
plot_two_states("AL", "FL", states_new_weekly_covid)
Out[9]:
In [10]:
plot_two_states("GA", "WI", states_new_weekly_covid)
Out[10]:
In [11]:
plot_two_states("SD", "ND", states_new_weekly_covid)
Out[11]:
In [12]:
plot_two_states("VA", "MD", states_new_weekly_covid)
Out[12]:
In [13]:
plot_two_states("NY", "WA", states_new_weekly_covid)
Out[13]:
In [14]:
plot_two_states("AZ", "TX", states_new_weekly_covid)
Out[14]:
In [15]:
plot_two_states("UT", "NV", states_new_weekly_covid)
Out[15]:

Julia Source Code¶

This was created using Jupyter notebook run Julia 1.8.1. The following is the Julia code used.

In [1]:
using DataFrames
using DataFramesMeta
using CSV
using StatsPlots
using Lazy
using Dates
#using Downloads

function issunday(datestring)
    date_format = DateFormat("y-m-d")
    date = Date(datestring, date_format)
    Dates.dayofweek(date) == 7
end

"""
First 4 columns are state & county ids
"""
usa_covid_just_data(raw_covid_data) = raw_covid_data[:,5:end]
usa_covid_labels(raw_covid_data) = raw_covid_data[:,1:4]

function usa_covid_sunday_cumulative(raw_covid_data)
    sundays = filter(issunday, names(raw_covid_data))
    return raw_covid_data[:, sundays]
end

"""Returns new cases each week"""
function counties_covid_weekly(raw_covid_data)
    labels = usa_covid_labels(raw_covid_data)
    just_data = usa_covid_just_data(raw_covid_data)
    sunday_cumulative = usa_covid_sunday_cumulative(just_data)
    sundays = names(sunday_cumulative[:,2:end])
    weekly_new_cases = sunday_cumulative[:,2:end] .- rename(sunday_cumulative[:,1:end-1], sundays)
    with_labels = hcat(labels, weekly_new_cases)
    return rename!(with_labels, [2 => :County] )
end

function state_covid_weekly_cummulative(raw_covid_data)
    # Is this needed?
    labels = usa_covid_labels(raw_covid_data)
    just_data = usa_covid_just_data(raw_covid_data)
    sunday_cumulative = usa_covid_sunday_cumulative(just_data)
    with_labels = hcat(labels, sunday_cumulative)
    return states_covid_weekly(with_labels)
end

"""input 2020-02-02_sum
   output 02-02"""
function shorten_date_label(aString)
    return aString[6:10]
end

function states_covid_weekly(weekly_data)
    grouped = DataFrames.groupby(weekly_data,[:State])
    states_sumed = combine(grouped, names(grouped)[5:end].=> [sum])
    state_labels = states_sumed[:,1]
    dates_shortened = rename!(shorten_date_label, states_sumed[:,2:end])
    hcat(DataFrame(State = state_labels),dates_shortened)
end


""" select state from DF """
function state_data(state_Abriv, states_weekly)
    return states_weekly[states_weekly.State .== state_Abriv,:]
end

county_data(state_Abriv, county, county_weekly_covid) =  @as data county_weekly_covid begin
    data[data.State .== state_Abriv ,:]
    data[data.County .== county, :]
end

country_covid_weekly(weekly_data) = @as data weekly_data begin
    usa_covid_just_data(data)
    combine(data, names(data).=> [sum])
    rename(shorten_date_label, data)
end

plot_covid(coviddf) = plot_covid(coviddf, "New Cases Per Week")
function plot_covid(coviddf, title)
    plot(coviddf[!,2],xticks = (1:8:nrow(coviddf), coviddf[!,1][1:8:end]),legend=false, title="New Cases Per Week: " * title, ylabel = "Number of New Cases", xlabel = "Week", formatter = :plain, dpi = 110, guidefontsize = 7, titlefontsize = 7, tickfontsize = 5)
end

plot_country(county_weekly_covid) = @as data county_weekly_covid begin
    country_covid_weekly(data)
    stack(data, 1:ncol(data))
    plot_covid(data, "USA")
end

plot_state(state, states_weekly) = @as data states_weekly begin
    state_data(state, data)
    data[:,2:end] #Remove state column
    stack(data, 1:ncol(data))
    plot_covid(data, state)
end

plot_county(state, county, county_weekly_covid) = @as data county_weekly_covid begin
    county_data(state, county, data)
    data[:,5:end] #Remove state column
    rename(shorten_date_label, data)
    stack(data, 1:ncol(data)) #convert columns to rows
    plot_covid(data, county)
end

function plot_two_states(stateA, StateB, states_new_weekly_covid)
    a = plot_state(stateA, states_new_weekly_covid)
    b = plot_state(StateB, states_new_weekly_covid)
    plot(a, b, layout = (2), size = (700, 300), dpi = 90, guidefontsize = 6, titlefontsize = 6, tickfontsize = 5)
end
Out[1]:
plot_two_states (generic function with 1 method)
In [2]:
covid_cases_url = "https://usafactsstatic.blob.core.windows.net/public/data/covid-19/covid_confirmed_usafacts.csv"
covid_cases_url = "https://static.usafacts.org/public/data/covid-19/covid_confirmed_usafacts.csv"
download(covid_cases_url,"currentCovid.csv")
covid_raw = DataFrame(CSV.File("currentCovid.csv"))
county_new_weekly_covid = counties_covid_weekly(covid_raw)
states_new_weekly_covid = states_covid_weekly(county_new_weekly_covid)
covid_raw[1:5,end-5:end]
Out[2]:

5 rows × 6 columns

2022-11-162022-11-172022-11-182022-11-192022-11-202022-11-21
Int64Int64Int64Int64Int64Int64
1000000
2185921859218592185921859218592
3662686626866268662686626866268
4695969596959695969596959
5761276127612761276127612
In [ ]: