COVID Data Tracking
The worldwide COVID-19 pandemic has hit every corner of the world in unprecedented ways. There exist many data reports, analytics tools, and projections about the virus's current and future state. I, however, wanted to create an easily accessible way to track how the virus is spreading in my area, using the number of new cases every day as a guide.
Importing Data
It turned out the Virginia Department of Health (VDH) used data management software called Socrata to publish and manage data on COVID-19, which conveniently had a continuously updated .csv file hosted on their servers. I copied older data (that wasn't on the hosted .csv file) into a Google Sheets spreadsheet, and used the powerful IMPORTRANGE() function to pull all new data into the sheet.
Creating the Graph
The data import seemed simple enough, so I then combined the static and imported data. After aggregating it a bit (again using Sheets functions to get the number of new cases, average over 7 days, etc.), the chart I wanted was easy to create.
However, a day later, a problem surfaced. It turned out that the url which hosted VDH data only held a rolling 7 days of data. This meant when new data was published, data from a week ago was deleted. Since I was using the IMPORTRANGE() function in Sheets, this meant that deletion would reflect on my chart as well. The result was that days of data were missing.
Recording Data Permanently: Creating a Google App Script
It quickly became apparent that I needed a more complex function in order to record the data I was importing from VDH, not simply display the data fetched from the url.
Luckily, Google had some really great scripting functionality that allowed me to do just that. Google Apps Script is a developer utility that links into almost every Google Product, and allows developers like me to utilize the full power of G Suite. I set up a Google Apps Script program to retrieve and record all data published by VDH each day. This enabled my automatically-updating graph to display both the most current data along and historical data. The graph updates to this day and is available at leohorwitz.com/covid!
Comments
Post a Comment