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-09-15 Tue>.

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)

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[nrow(new_national),]$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        
Oct                                                              
Nov                                                              
Dec                                                              

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
  Sep 01 Sep 02 Sep 03 Sep 04 Sep 05 Sep 06 Sep 07 Sep 08 Sep 09 Sep 10 Sep 11 Sep 12 Sep 13 Sep 14 Sep 15 Sep 16 Sep 17 Sep 18 Sep 19 Sep 20 Sep 21 Sep 22 Sep 23 Sep 24 Sep 25 Sep 26 Sep 27
Abruzzo 5 24 24 25 13 26 15 14 5 11 35 11 37 1 18 18 33 54 0 0 72 18 22 17 51 16 47
Basilicata 1 2 15 7 7 9 1 8 14 6 12 5 3 0 5 5 5 0 3 6 1 14 17 9 13 25 47
Calabria 22 32 13 19 19 27 17 8 19 8 8 18 14 3 4 19 16 28 25 22 12 24 19 9 10 15 31
Campania 102 117 193 171 119 100 218 249 203 180 140 103 122 90 136 186 195 208 149 171 243 156 248 195 253 274 245
Emilia-Romagna 99 107 118 126 133 124 132 94 110 110 152 138 143 127 125 106 110 121 133 115 116 56 101 99 122 99 96
Friuli Venezia Giulia 17 20 25 23 49 20 11 12 54 39 34 39 45 4 20 29 63 39 33 32 13 14 57 28 37 54 28
Lazio 125 130 154 171 158 122 159 129 175 163 148 155 143 181 139 165 181 193 197 165 198 238 195 230 230 219 181
Liguria 19 47 22 47 95 111 59 64 51 114 82 112 78 65 141 73 40 158 78 85 64 105 108 102 73 97 45
Lombardia 242 237 228 337 388 198 109 271 218 245 257 269 265 125 176 159 281 224 243 211 90 182 196 229 277 256 216
Marche 16 17 21 17 32 20 6 15 19 40 41 27 39 11 14 38 37 29 24 31 17 18 32 17 33 26 24
Molise 3 0 2 4 0 2 9 3 4 3 4 3 3 4 1 6 2 3 5 1 31 2 3 4 5 5 7
P.A. Bolzano 13 10 4 11 23 7 0 4 10 20 26 25 40 7 21 12 15 72 26 20 20 8 37 20 52 29 22
P.A. Trento 3 33 91 23 53 33 17 3 7 82 29 22 9 20 20 32 76 18 22 45 2 25 22 23 23 51 42
Piemonte 42 66 75 82 54 56 37 42 112 74 57 93 82 61 39 117 70 127 74 98 57 84 95 104 120 107 132
Puglia 39 67 78 117 55 60 43 143 97 70 82 76 82 61 76 103 63 84 108 50 81 67 89 73 90 51 76
Sardegna 50 73 39 66 65 19 59 51 47 63 65 51 33 54 36 27 51 66 59 72 64 53 49 66 57 63 139
Sicilia 33 83 54 78 114 37 49 84 77 106 104 44 61 65 77 90 96 179 98 116 75 108 89 125 107 110 107
Toscana 40 69 113 99 113 122 85 59 88 92 147 138 91 59 41 90 119 99 143 147 84 74 90 156 139 110 101
Umbria 10 27 9 35 16 25 13 7 33 24 17 33 24 12 22 17 22 21 32 24 5 26 19 29 23 35 21
Valle d’Aosta 0 2 4 2 0 0 0 5 0 0 3 1 2 3 3 1 1 8 0 3 2 1 2 3 1 11 0
Veneto 97 163 115 273 188 179 69 105 91 147 173 138 142 55 115 159 109 176 186 173 103 119 150 248 196 216 159

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-09-15 Tue 17:56 (created on: 2020-08-01 Sat 00:00)

Published: 2020-09-27 Sun 18:08