Graph world total COVID-19 cases, deaths, and recoveries in C#


[COVID-19]

My previous COVID-19 posts examined cases, deaths, and recoveries for different countries. I recently wanted to look at the world-wide totals, so I made this modification.

Making changes to handle the world totals separately would have been a lot of work, so instead I simply made a new artificial country named All. When the program loads the data for the countries, it adds all of the values to the All country’s data. For example, the following code shows how the program loads case data with the new pieces highlighted in blue.

// Save the world values.
float[] all_values = new float[num_dates];

// Load the country data.
const int country_col = 2;
for (int country_num = 2; country_num <= max_row; country_num++)
{
    // Get the country's name.
    string country_name = fields[country_num, country_col].ToString();

    // Get or create the country's CountryData object.
    CountryData country_data =
        GetOrCreateCountryData(country_name, num_dates);

    // Add to the country's data.
    for (int col = 1; col <= num_dates; col++)
    {
        // Add the value to the country's total.
        country_data.Cases[col - 1] +=
            (int)(double)fields[country_num, col + first_date_col - 1];

        all_values[col - 1] +=
            (int)(double)fields[country_num, col + first_date_col - 1];
    }
}

CountryData all_data =
    GetOrCreateCountryData("All", num_dates);
all_data.Cases = all_values;

The code first creates an array to hold the total values. It then loops through the countries as before. It gets the CountryData object for each country and then loops through the dates for which data exists, adding each value to the country’s data. It also adds the new value to the all_values total.

After it has finished loading the data, the program gets the CountryData for the All country and saves the total that it created in that object’s Cases value.

The code that loads the death and recovery data works similarly. Download the example to see the details.

The picture at the top of the post shows deaths per resolution for the world, US, and Italy. In the world data, the number seems to be leveling off a bit below 20%. All three curves trend downward over time, possibly because increased testing is raising the number of known cases and thus decreasing the ratio of deaths to resolutions. To think of this in another way, increased testing means a greater number of minor infections are being recorded.

The following picture shows cases per million.


[COVID-19]

The curves for Spain and Italy show a slight downward curve near their ends indicating that the rate of increase in cases may be slowing.

The US curve seems to be roughly linear right now, indicating that the number of new cases is roughly the same each day. Unfortunately that has been the trend for quite a while so the number of cases does not seem to be slowing. At least it’s not curving upward as an unchecked exponential growth curve would be.

The world curve also seems roughly linear, although with a lower slope. The linear shapes of the US and world curves seem to imply that the pandemic is far from over. The lower slope on the world curve may mean it’s taking longer for the virus to penetrate some parts of the world, or it could reflect weak testing in parts of the world so the recorded number of cases isn’t rising as quickly as the actual number.

Download the example and experiment with it. If you learn anything interesting, please post a note in the comments below. Also post a comment if you know of a data source where we can get similar data for the US states, or any other localities that you think would be interesting.


Download Example   Follow me on Twitter   RSS feed   Donate




About RodStephens

Rod Stephens is a software consultant and author who has written more than 30 books and 250 magazine articles covering C#, Visual Basic, Visual Basic for Applications, Delphi, and Java.
This entry was posted in drawing, graphics and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink.

2 Responses to Graph world total COVID-19 cases, deaths, and recoveries in C#

  1. Pingback: Quick COVID-19 update - C# HelperC# Helper

  2. Pingback: Display COVID-19 data for US states in C# - C# HelperC# Helper

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.