# Novel coronavirus charts and numbers

**URL:** <https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177>\
**Category:** Grasshopper\
**Tags:** python, gh, coronavirus, covid-19, sars-cov-2\
**Created:** [March 15, 2020, 8:53pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177 "2020-03-15T20:53:52Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/769366_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [March 15, 2020, 8:53pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/1 "2020-03-15T20:53:52Z")

</div>

Hi all,

here a small definition that uses Python and GH to query public databases for coronavirus cases and provides that data for further analysis. It’s inspired by [this video by Luciano Ambrosini](https://www.youtube.com/watch?time_continue=1&v=wRnjrtWqm0o&feature=emb_title).

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/8/f8ad2a5f5aa2c7c842d1b48fb4ca80265da9bdec.png)

The data of some countries actually starts to look quite good.

There’s also a part that uses JSON to query the Italian more-up-to-date repository. It will prove useful for a sample in case your local data is provided in that format.  
Finally, this definition purposely does not use any add-ons. However, your charts will look more beautiful with some third-party library, for example [Human UI](http://grasshopperdocs.com/addons/human-ui.html).

Note: any responsibility on decisions taken based on this data or definition is disclaimed.

[coronavirus-data.gh](https://discourse.mcneel.com/uploads/short-url/pl5wk2VZtdh8utW4WemGn8ZD5s1.gh) (15.8 KB)

Giulio

–  
Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/769366_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [March 15, 2020, 9:00pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/2 "2020-03-15T21:00:00Z")

</div>

If you find it useful and edit this, please feel free to post your improvements here.

---

<div class="post-metadata">

**Author:** ![Willem](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/willem/32/773637_2.png) [@Willem](https://discourse.mcneel.com/u/Willem)\
**Post date:** [March 16, 2020, 11:20am UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/3 "2020-03-16T11:20:55Z")

</div>

Hi Giulio,

Thanks for sharing!

I added a list to easily scroll through to find the index of each country  
And I put the max values for each graph to get some reference.

[coronavirus-data\_WD.gh](https://discourse.mcneel.com/uploads/short-url/lfmcM1sj1U90g2oyr16DWTrN81Z.gh) (19.8 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/b/cbd2bb2b346aabd4366cf6799a140cfc738910ff.png)

Take care everyone!  
-Willem

---

<div class="post-metadata">

**Author:** ![mohamad.elatab](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mohamad.elatab/32/599049_2.png) [@mohamad.elatab](https://discourse.mcneel.com/u/mohamad.elatab)\
**Post date:** [March 16, 2020, 7:16pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/5 "2020-03-16T19:16:29Z")

</div>



---

<div class="post-metadata">

**Author:** ![Gijs](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gijs/32/769882_2.png) [@Gijs](https://discourse.mcneel.com/u/Gijs)\
**Post date:** [March 17, 2020, 2:21pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/6 "2020-03-17T14:21:40Z")

</div>

@piac @Willem what are the lower two graphs representing?

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/769366_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [March 17, 2020, 2:43pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/7 "2020-03-17T14:43:36Z")

</div>

> [@Gijs](#):
>
> @piac @Willem what are the lower two graphs representing?

First and second derivative.

> **[Derivative](https://en.wikipedia.org/wiki/Derivative)**
>
> In mathematics, the derivative is a fundamental tool that quantifies the sensitivity to change of a function's output with respect to its input. The derivative of a function of a single variable at a chosen input value, when it exists, is the slope of the tangent line to the graph of the function at that point. The tangent line is the best linear approximation of the function near that input value. The derivative is often described as the instantaneous rate of change, the ratio of the instantan...

It’s the (here daily) increment of the number of the first graph (1st derivative) and the rate by which the increment is modifying (2nd derivative). These show the trends, basically. They suffer of statistical error.

---

<div class="post-metadata">

**Author:** ![Dani\_Abalde](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dani_abalde/32/759411_2.png) [@Dani\_Abalde](https://discourse.mcneel.com/u/Dani_Abalde)\
**Post date:** [March 17, 2020, 3:35pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/8 "2020-03-17T15:35:04Z")

</div>

> [@Gijs](#):
>
> what are the lower two graphs representing?

The derivative tells you how a function (in this case a sampled distribution) change at any position. If A and B are points, the change from A to B is (A-B) / dt, where dt is the change in time. So in case of the change of a position, the derivative is its velocity. And the derivative of the derivative, or second derivative, is how its velocity changes, ie, its acceleration.

---

<div class="post-metadata">

**Author:** ![brian](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/brian/32/504171_2.png) [@brian](https://discourse.mcneel.com/u/brian)\
**Post date:** [March 17, 2020, 8:37pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/9 "2020-03-17T20:37:20Z")

</div>

Thanks @piac! Here’s an update that combines combines US counties into state summaries when `join_regions` is false, and rolls up by country when `join_regions` is true. Early data in the US was by county, and is now aggregated by state, so the overall time-period graphs for either didn’t make sense.

[coronavirus-data\_WD.gh](https://discourse.mcneel.com/uploads/short-url/i0GzUHbcXGYuQW9jK5qYY9igV6B.gh) (17.7 KB)

---

<div class="post-metadata">

**Author:** ![antoinemaes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoinemaes/32/499716_2.png) [@antoinemaes](https://discourse.mcneel.com/u/antoinemaes)\
**Post date:** [March 18, 2020, 4:39pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/10 "2020-03-18T16:39:19Z")

</div>

Thanks @piac  
Here is a small Gh contribution to make fancy graphs…  
I used Log scaling for heights.

Cheers

[coronavirus-data\_AMA.gh](https://discourse.mcneel.com/uploads/short-url/1dQ0F2OMtJKw0zBtrrxuyxEm08I.gh) (32.5 KB)

 ![1-know](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/6/f6cba5b0712eeb6805b8c682cf2b22d5ed2203ce.jpeg) ![2-new](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/4/146bb54fdf9fb0e40c77829dc65c7d316df9e5db.jpeg) ![3-increment](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/7/b/7bdfe8e007d1d104526154a151093d5049c0df95.jpeg)  
 ![canvas](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/a/f/af33fcaf26764e841390c94068410e40375ed106.jpeg)

---

<div class="post-metadata">

**Author:** ![antoinemaes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoinemaes/32/499716_2.png) [@antoinemaes](https://discourse.mcneel.com/u/antoinemaes)\
**Post date:** [March 18, 2020, 5:03pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/11 "2020-03-18T17:03:19Z")

</div>

small update !!

It now also works for death cases and recoveries ! Also displays the selection in tiltle !

[coronavirus-data\_AMA.gh](https://discourse.mcneel.com/uploads/short-url/qh3FG3VTwDrUEYOH2ny5CIyPEhc.gh) (30.5 KB)

 ![4-recovered](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/1/c1dda879eb166c90674dd7e4a276fb01754ba1b4.jpeg)

---

<div class="post-metadata">

**Author:** ![Gijs](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gijs/32/769882_2.png) [@Gijs](https://discourse.mcneel.com/u/Gijs)\
**Post date:** [March 18, 2020, 10:13pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/12 "2020-03-18T22:13:07Z")

</div>

I wonder why these numbers are higher, while the source is the same?  
[https://localfocus2.appspot.com/5e6f877460e13](https://localfocus2.appspot.com/5e6f877460e13)

---

<div class="post-metadata">

**Author:** ![ivelin.peychev](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ivelin.peychev/32/676038_2.png) [@ivelin.peychev](https://discourse.mcneel.com/u/ivelin.peychev)\
**Post date:** [March 18, 2020, 10:15pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/13 "2020-03-18T22:15:06Z")

</div>

update rate

---

<div class="post-metadata">

**Author:** ![antoinemaes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoinemaes/32/499716_2.png) [@antoinemaes](https://discourse.mcneel.com/u/antoinemaes)\
**Post date:** [March 20, 2020, 8:53am UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/14 "2020-03-20T08:53:43Z")

</div>

Last update :

you can highlight your or any country super easily.

You will need [Human plugin](https://www.food4rhino.com/app/human)

[coronavirus-data\_AMA.gh](https://discourse.mcneel.com/uploads/short-url/6GuPXZfmx1uwVFaSvdMPIw3ifhL.gh) (37.0 KB)

 ![1-known-C](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/e/3/e33a61048a4f4d1d0e1757dd4aafd69cbd0fc88f.jpeg)

---

<div class="post-metadata">

**Author:** ![adityajain30120](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/adityajain30120/32/495422_2.png) [@adityajain30120](https://discourse.mcneel.com/u/adityajain30120)\
**Post date:** [March 24, 2020, 7:52am UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/15 "2020-03-24T07:52:19Z")

</div>

the c# component isnt working, line 22 error.  
pls help  
@antoinemaes

thanks  
triptonicart

---

<div class="post-metadata">

**Author:** ![antoinemaes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoinemaes/32/499716_2.png) [@antoinemaes](https://discourse.mcneel.com/u/antoinemaes)\
**Post date:** [March 24, 2020, 9:52am UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/16 "2020-03-24T09:52:22Z")

</div>

Ok so these (python) components are from Giulio Piacentino… I’m not on the same python level 🙃

But as I understand it, there is a mistake in the data, where information is missing (empty spot in one list that does not convert to integer). That maybe could be fixed by some python magicians (any idea @piac ?)

 ![Canvas at 10;35;47](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/d/4/d468aa09ced1b0c206d4fe35ff79ca1d9ca557db.png)

While waiting for that, as a python noob, when there are errors, I simply _pass_ them 😅  
Here is a working version… This should be ok, but I don’t really know what is being thrown by my “try/except” combo. (if anyone could enlighten me, please do !)  
[coronavirus-data\_AMA.gh](https://discourse.mcneel.com/uploads/short-url/2u28844piPPQULo6xuP33iFGqGy.gh) (39.1 KB)

```
from io import StringIO as s
import csv
import ghpythonlib.treehelpers as th

f = s(x)
reader = csv.reader(f, delimiter=',')

results = dict()

count = -1
for row in reader:
    count += 1
    if count == 0: continue
    Province_State_Country = row[1] if join_regions else row[0]
    if not Province_State_Country: Province_State_Country = row[1]
    if not join_regions and Province_State_Country != row[1]: Province_State_Country = row[1] + ", " + Province_State_Country
    
    raw_vals = row[4:]
    
    if Province_State_Country in results:
        prevs = results[Province_State_Country]
        #print(raw_vals)
        
        try:
            extra = [(int(c) + prevs[i]) for (i,c) in enumerate(raw_vals)]
        except (ValueError):
            pass
        values = extra
        #
    else:
        try:
            values = [int(c) for c in raw_vals]
        except(ValueError):
            pass
    results[Province_State_Country] = values

results = sorted(results.items(), key = lambda kv: kv[0])
a = [n[0] for n in results]
b = th.list_to_tree([n[1] for n in results])
```

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/769366_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [March 31, 2020, 5:56pm UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/17 "2020-03-31T17:56:17Z")

</div>

Just updated AMA’s file with the new modified source in the [CSSEGISandData](https://github.com/CSSEGISandData) repository.

[coronavirus-data\_AMA\_2.gh](https://discourse.mcneel.com/uploads/short-url/v1tNzhSP9jrJ4KYGl0rjMSDhi1M.gh) (38.3 KB)

---

<div class="post-metadata">

**Author:** ![tognatta.aditya](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tognatta.aditya/32/647552_2.png) [@tognatta.aditya](https://discourse.mcneel.com/u/tognatta.aditya)\
**Post date:** [April 29, 2020, 8:52am UTC](https://discourse.mcneel.com/t/novel-coronavirus-charts-and-numbers/98177/18 "2020-04-29T08:52:10Z")

</div>

Guys! is there any way to updated the source files?  
thanks in advance!
