New Cases in Italy

Table of Contents

Menu

Introduction

This page focuses on new cases in Italy.

This page was created on <2020-08-01 Sat> and last updated on <2020-10-25 Sun>.

The source code available on the COVID-19 pages is distributed under the MIT License; the content is distributed under a Creative Commons - Attribution 4.0.

R Functions

We read the data from the CSV files of the Civil Protection repository:

PATH="/home/adolfo/Downloads/COVID-19/"

# evolution over time, by Region
data = read.csv(file.path(PATH, "dati-regioni/dpc-covid19-ita-regioni.csv"))
data$data <- as.Date(data$data)

# evolution over time at the National level
new_national = read.csv(file.path(PATH, "dati-andamento-nazionale/dpc-covid19-ita-andamento-nazionale.csv"))
new_national$data <- as.Date(new_national$data)

# latest regional data
by_region = read.csv(file.path(PATH, "dati-regioni/dpc-covid19-ita-regioni-latest.csv"))
by_region$data <- as.Date(by_region$data)

We then output a table of new cases from R, which we then use in Ruby. (The table is not exported to HTML.)

Inferior Ruby shells perform very badly with long input lines. Make sure you don’t pass the variable to a Ruby :session or the evaluation will break, while IRB tries to cope with the declaration of the input variable.

If you need a :session, you should read data directly from the Ruby session, rather than passing it as a variables.

new_national[, c("data", "nuovi_positivi")]

New Cases in Italy

Line Plot

The shaded area corresponds to the lockdown. The red horizontal line allows to compare the latest data with historical data.

p = plot(new_national$nuovi_positivi ~ new_national$data, type="l", lwd=6, pch=16, cex=1.6, col=c("#3B3176"))
#text(new_national$nuovi_positivi ~ new_national$data, labels=new_national$nuovi_positivi, pos=2, cex=1.3)
abline(v = as.Date("2020-10-25"), col="#FF0000", lwd=3)

grid(p, col = "black", lty="dotted")
rect(as.Date("2020-03-09"), -200, as.Date("2020-05-19"), 7000, border = "#AA0055", col = "#AA0055", density=2)
abline(h = new_national[27,]$nuovi_positivi, col="#FF0000", lwd=3)

p12_newcases.png

Calendar Heatmap

<<EOS
<div id="heatmap-total"></div>
<script>
calendar_heatmap.create({
    data: [
    #{data.map { |x| "{ day: \"%s\", count: %d }" % [x[0], x[1].to_i] }.join(",") }
    ],
    date_var: "day",
    fill_var: "count",
    target: "#heatmap-total"
});
</script>
EOS

Tabular Data

require 'date'

def find_new_cases_for date, table
  table.each do |row|
    return row[1] if date == Date.parse(row[0])
  end
  return ""
end

year_grid = Array.new
legenda = (0..31).map { |x| x }
legenda[0] = ""
year_grid << legenda

(1..12).each do |month|
  month_row = Array.new(32)
  month_row[0] = Date.new(2020, month, 1).strftime("%b")
  (1..31).each do |day|
    if Date.valid_date?(2020, month, day) 
      date = Date.new(2020, month, day)
      cases = find_new_cases_for(date, table)
      month_row[day] = cases
    else
      month_row[day] = ""
    end
  end
  year_grid << month_row
end
year_grid
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Jan                                                              
Feb                                               221 93 78 250 238 240    
Mar 566 342 466 587 769 778 1247 1492 1797 977 2313 2651 2547 3497 3590 3233 3526 4207 5322 5986 6557 5560 4789 5249 5210 6153 5959 5974 5217 4050 4053
Apr 4782 4668 4585 4805 4316 3599 3039 3836 4204 3951 4694 4092 3153 2972 2667 3786 3493 3491 3047 2256 2729 3370 2646 3021 2357 2324 1739 2091 2086 1872  
May 1965 1900 1389 1221 1075 1444 1401 1327 1083 802 744 1402 888 992 789 875 675 451 813 665 642 652 669 531 300 397 584 593 516 416 355
Jun 178 318 321 177 518 270 197 280 283 202 379 163 346 338 303 210 329 333 251 262 224 218 122 190 296 259 175 174 126 142  
Jul 187 201 223 235 192 208 138 193 229 276 188 234 169 114 163 230 233 249 219 190 129 282 306 252 275 255 170 212 289 386 379
Aug 295 239 159 190 384 402 552 347 463 259 412 481 523 574 629 479 320 403 642 845 947 1071 1210 953 878 1367 1411 1462 1444 1365 996
Sep 978 1326 1397 1733 1694 1297 1108 1370 1434 1597 1616 1501 1458 1008 1229 1452 1585 1907 1638 1587 1350 1392 1640 1786 1912 1869 1766 1494 1648 1851  
Oct 2548 2499 2844 2578 2257 2677 3678 4458 5372 5724 5456 4619 5901 7332 8804 10010 10925 11705 9338 10874 15199 16079 19143 19644 21273 17012 21994 24991 26831 31084 31758
Nov 29907 22253 28244 30550 34505 37809 39811 32616 25271 35098 32961 37978 40902 37255 33979 27354 32191 34282 36176 37242 34767 28337 22930 23232 25853 29003 28352 26323 20648 16377  
Dec 19350 20709 23225                                                        

New Cases by Region

Tabular Data

New cases by region in August.

The table is built as follows:

  • egrep selects entries in the current month, getting the current month from the date command
  • the first sed gets rid of the “T17:00:00” timestamp in dates
  • the second sed compacts the date, by removing the year and replacing the month number with its name
  • datamash pivots the table by region and date
current_month=$(date +"%b")
current_month_no=$(date +"%m")

egrep 2020-${current_month_no} ~/Downloads/COVID-19/dati-regioni/dpc-covid19-ita-regioni.csv | sed -e "s/T17:00:00//g" | sed -e "s/2020-${current_month_no}-/${current_month} /g" | datamash -t, crosstab 4,1 sum 13
  Dec 01 Dec 02 Dec 03
Abruzzo 396 381 395
Basilicata 156 157 131
Calabria 318 230 280
Campania 1113 1842 2295
Emilia-Romagna 1471 1569 1766
Friuli Venezia Giulia 736 812 772
Lazio 1669 1791 1769
Liguria 339 349 422
Lombardia 4048 3425 3751
Marche 337 421 476
Molise 60 95 53
P.A. Bolzano 94 317 374
P.A. Trento 156 278 239
Piemonte 1617 1568 2230
Puglia 1659 1668 1602
Sardegna 420 445 538
Sicilia 1399 1483 1294
Toscana 658 776 929
Umbria 144 278 286
Valle d’Aosta 25 42 42
Veneto 2535 2782 3581

Line Plots

# how many rows and columns?
par(mfrow=c(11, 2))
regions <- c("Valle d'Aosta", "Piemonte", "Liguria", "Lombardia", "Veneto",
             "P.A. Trento", "P.A. Bolzano", "Friuli Venezia Giulia",
             "Emilia-Romagna", "Toscana", "Marche", "Umbria",
             "Lazio", "Abruzzo", "Molise", "Campania",
             "Puglia", "Basilicata", "Calabria", "Sicilia",
             "Sardegna")
for (region in regions) {
  my_plot(region,
          data, 
          max=max(data$nuovi_positivi),
          filter=TRUE, 
          textlabels=FALSE,
          variables=c("nuovi_positivi"),
          graphtypes=c("l"),
          colors=c("black"))
}

new_cases_by_region.png

Author: Adolfo Villafiorita

Last modified: 2020-10-25 Sun 22:12 (created on: 2020-08-01 Sat 00:00)

Published: 2020-12-04 Fri 13:21