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 <2021-03-21 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="./data"

# evolution over time, by Region
data = read.csv(file.path(PATH, "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, "dpc-covid19-ita-andamento-nazionale.csv"))
new_national$data <- as.Date(new_national$data)

# latest regional data
by_region = read.csv(file.path(PATH, "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)

text(x = as.Date("2020-03-25"), y = 8000, "First Wave", col="#FF0000")
abline(h = new_national[27,]$nuovi_positivi, col="#FF0000", lwd=2)
#abline(v = as.Date("2020-03-01"), col="#FF0000", lwd=2)

abline(h = 41000, col="#FF0000", lwd=2)
abline(v = as.Date("2021-03-01"), col="#FF0000", lwd=2)

text(x = as.Date("2020-11-15"), y = 42000, "Second Wave", col="#FF0000")

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

This section used to present cases in a grid Month/Day… however, I should now update it with Month-Year/Day, since the pandemia has been around for more than a year, now.

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

New Cases by Region

Tabular Data

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")
year=$(date +"%Y")

egrep ${year}-${current_month_no} ./data/dpc-covid19-ita-regioni.csv | sed -e "s/T1[78]:00:00//g" | sed -e "s/${year}-${current_month_no}-/${current_month} /g" | datamash -t, crosstab 4,1 sum 13
  Mar 01 Mar 02 Mar 03 Mar 04 Mar 05 Mar 06 Mar 07 Mar 08 Mar 09 Mar 10 Mar 11 Mar 12 Mar 13 Mar 14 Mar 15 Mar 16 Mar 17 Mar 18 Mar 19 Mar 20 Mar 21
Abruzzo 199 246 573 552 473 442 553 273 187 372 608 515 320 323 329 212 304 462 417 370 353
Basilicata 75 147 124 122 164 178 144 28 182 115 151 141 137 106 67 166 126 179 116 147 108
Calabria 151 102 230 226 260 293 228 89 149 283 414 305 275 300 213 311 216 404 376 394 412
Campania 1896 2046 2635 2780 2842 2843 2560 1644 2709 3034 2981 2644 2940 2449 1823 2656 2665 2223 1997 2196 1810
Emilia-Romagna 2597 2040 2456 2545 3246 3232 3056 2987 2429 2155 2845 3477 2950 3023 2822 2184 2026 2531 3188 2560 2448
Friuli Venezia Giulia 172 479 693 643 823 661 466 415 598 866 991 971 953 604 398 672 986 1058 910 906 578
Lazio 1044 1188 1520 1702 1525 1563 1399 1175 1431 1654 1800 1757 1998 1812 1536 1497 1728 1963 2188 1821 1793
Liguria 309 337 368 414 338 272 384 215 248 342 405 406 307 321 242 343 321 324 427 458 380
Lombardia 2135 3762 4590 5174 5210 5658 4397 2301 4084 4422 5849 6262 5809 4334 2185 4235 4490 5641 5518 4810 4003
Marche 446 415 759 919 1027 836 852 349 423 881 921 874 1000 616 415 529 856 820 822 856 700
Molise 41 18 116 56 137 49 67 35 24 80 84 73 104 52 17 18 77 81 41 62 57
P.A. Bolzano 121 236 280 253 230 218 182 88 178 213 203 147 183 103 13 175 158 165 127 116 76
P.A. Trento 57 220 357 229 406 324 275 83 213 405 370 281 239 273 104 190 285 256 306 307 155
Piemonte 1155 1609 1537 2167 2283 1793 1543 1214 2018 2086 2322 2929 2159 1530 1742 2074 2374 2357 2997 2141 1751
Puglia 631 1021 1261 1438 1418 1483 1155 594 1286 1571 1634 1774 1700 1542 715 1126 1734 2082 1785 1983 1546
Sardegna 45 70 101 81 89 73 95 68 146 65 128 106 103 118 74 79 92 121 134 102 176
Sicilia 478 566 539 560 519 592 576 515 595 695 672 679 650 613 523 598 782 789 859 782 699
Toscana 877 1058 1163 1239 1231 1293 1355 1000 1001 1293 1302 1304 1326 1305 1106 1247 1275 1513 1365 1510 1358
Umbria 79 289 301 267 295 283 242 42 232 296 283 219 196 270 66 159 324 168 182 206 142
Valle d’Aosta 3 6 9 11 15 16 7 30 8 20 33 28 31 34 36 24 49 37 63 61 28
Veneto 603 1228 1272 1487 1505 1539 1229 757 1608 1561 1677 1932 2682 1587 841 1901 2191 1761 1917 2044 1586

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