forked from paolini/covid19-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset_vaccini.js
157 lines (140 loc) · 5.11 KB
/
dataset_vaccini.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* database opendata-vaccini
*/
class VacciniDataset extends BaseDataset {
constructor(options) {
super(options);
this.filter_column = "codice_regione_ISTAT";
this.filter_name_column = "nome_area";
this.REPOSITORY_URL = "https://raw.githubusercontent.com/italia/covid19-opendata-vaccini/master/";
this.translate = {
'population': 'popolazione',
'increment': 'incremento',
'rate': 'tasso'
};
}
init_html() {
super.init_html();
this.$column = $("select[name='" + this.prefix + "_column']");
this.$select = this.filter_column ? $("select[name='" + this.prefix + "_" + this.filter_column + "']") : null;
this.$modifier = $("select[name='vaccini_modifier']");
}
populate_html() {
var self = this;
if (this.filter_column) {
var pairs = this.table.get_column_distinct_pairs(this.filter_column, this.filter_name_column);
pairs.sort(function(a,b){return a[1].localeCompare(b[1])});
this.$select.find('option').remove();
this.$select.append("<option value=''>-- tutte le regioni --</option>");
pairs.forEach(function(pair) {
self.$select.append("<option value='" + pair[0] + "'>" + pair[1] + "</option>");
});
}
this.$column.find('option').remove();
this.fields.forEach(function(field){
self.$column.append("<option value='" + field + "'>" + dash_to_space(field) + "</option>");
});
}
get_options() {
var options = super.get_options();
options.column = this.$column.children("option:selected").val();
if (this.filter_column) {
options.value = this.$select.children("option:selected").val();
options.value_name = this.$select.children("option:selected").text()
}
if (this.$modifier) {
var modifier = this.$modifier.val();
if (this.$modifier.is(':visible') && modifier && modifier.indexOf('*')>=0) {
options.column = modifier.replace('*', options.column);
}
}
return options;
}
get_population(options) {
if (options['value']=='') return country_population['Italy'];
return popolazione_regioni[options['value_name']];
}
get_series_basic(column, options) {
var subtable = this.table;
var label = dash_to_space(column);
if (this.filter_column) {
var value = options['value'];
if (value) {
subtable = subtable.filter(this.filter_column, value);
label += " " + options['value_name'];
}
}
var data_x = [];
var data_y = [];
var x_col = subtable.headers.indexOf("data_somministrazione");
var y_col = subtable.headers.indexOf(column);
subtable.rows.forEach(function(row) {
var l = data_x.length;
var x = string_to_date(row[x_col]);
var y = string_to_int(row[y_col]);
if (l>0 && data_x[l-1].getTime() === x.getTime()) {
data_y[l-1] += y;
} else {
data_x.push(x);
data_y.push(y);
}
});
var y_axis = 'count';
var series = new Series(data_x, data_y, label);
series.population = this.get_population(options);
series.y_axis = y_axis;
series.cumulative = false;
if (column == 'totale') series.cumulative = true;
return series;
}
}
class VacciniSomministrazioneDataset extends VacciniDataset {
constructor() {
super({
name: "somministrazione",
path: "dati/somministrazioni-vaccini-latest.csv"
});
this.fields = [
"sesso_maschile",
"sesso_femminile",
"categoria_operatori_sanitari_sociosanitari",
"categoria_personale_non_sanitario",
"categoria_ospiti_rsa",
"categoria_60_69",
"categoria_70_79",
"categoria_over80",
"categoria_forze_armate",
"categoria_personale_scolastico",
"categoria_soggetti_fragili",
"categoria_altro",
"prima_dose",
"seconda_dose"
];
}
}
class VacciniSomministrazioneSummaryDataset extends VacciniDataset {
constructor() {
super({
name: "somministrazione",
path: "dati/somministrazioni-vaccini-summary-latest.csv",
table_sort_column: "data_somministrazione"
});
this.fields = [
"totale",
"sesso_maschile",
"sesso_femminile",
"categoria_operatori_sanitari_sociosanitari",
"categoria_personale_non_sanitario",
"categoria_altro",
"categoria_ospiti_rsa",
"categoria_60_69",
"categoria_70_79",
"categoria_over80",
"categoria_forze_armate",
"categoria_personale_scolastico",
"categoria_soggetti_fragili",
"prima_dose",
"seconda_dose"
];
}
}