(Andamenti regionali)
(Andamenti regionali)
Riga 26: Riga 26:
 
         Plotly.d3.csv('https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni.csv', function(err, rows){
 
         Plotly.d3.csv('https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni.csv', function(err, rows){
  
        function unpack(rows, key) {
+
    function unpack(rows, key) {
            return rows.map(function(row) { return row[key]; });
+
        return rows.map(function(row) { return row[key]; });
 +
    }
 +
 
 +
    var allRegionNames = unpack(rows, 'denominazione_regione'),
 +
        allDay = unpack(rows, 'data'),
 +
        allRicoverati = unpack(rows, 'ricoverati_con_sintomi'),
 +
        allTi = unpack(rows, 'terapia_intensiva'),
 +
        allTo = unpack(rows, 'totale_ospedalizzati'),
 +
        allIdom = unpack(rows, 'isolamento_domiciliare'),
 +
        allAttPos = unpack(rows, 'totale_attualmente_positivi'),
 +
        allNewPos = unpack(rows, 'nuovi_attualmente_positivi'),
 +
        allDimGuariti = unpack(rows, 'dimessi_guariti'),
 +
        allMorti = unpack(rows, 'deceduti'),
 +
        allTotCasi = unpack(rows, 'totale_casi'),
 +
        allTamponi = unpack(rows, 'tamponi'),
 +
 
 +
        listofRegions = [],
 +
        currentCountry,
 +
        currentGdp = [],
 +
        currentYear = [];
 +
        currTitle = 'Abruzzo';
 +
        currallRicoverati = [];
 +
        currallTi = [];
 +
        currallTo = [];
 +
        currallIdom = [];
 +
        currallAttPos = [];
 +
        currallNewPos = [];
 +
        currallDimGuariti = [];
 +
        currallMorti = [];
 +
        currallTotCasi = [];
 +
        currallTamponi = [];
 +
 
 +
        currallMortiTi = [];
 +
        currallMortiOsp = [];
 +
        //allDay = allDay.split(' ')[0];
 +
 
 +
    for (var i = 0; i < allRegionNames.length; i++ ){
 +
        if (listofRegions.indexOf(allRegionNames[i]) === -1 ){
 +
            listofRegions.push(allRegionNames[i]);
 
         }
 
         }
 +
    }
  
         var allRegionNames = unpack(rows, 'denominazione_regione'),
+
    function getRegionData(chosenCountry) {
            allDay = unpack(rows, 'data'),
+
         currTitle = chosenCountry;
            allRicoverati = unpack(rows, 'ricoverati_con_sintomi'),
+
        currentYear = [];
            allTi = unpack(rows, 'terapia_intensiva'),
+
        currallRicoverati = [];
            allTo = unpack(rows, 'totale_ospedalizzati'),
+
        currallTi = [];
            allIdom = unpack(rows, 'isolamento_domiciliare'),
+
        currallTo = [];
            allAttPos = unpack(rows, 'totale_attualmente_positivi'),
+
        currallIdom = [];
            allNewPos = unpack(rows, 'nuovi_attualmente_positivi'),
+
        currallAttPos = [];
            allDimGuariti = unpack(rows, 'dimessi_guariti'),
+
        currallNewPos = [];
            allMorti = unpack(rows, 'deceduti'),
+
        currallDimGuariti = [];
            allTotCasi = unpack(rows, 'totale_casi'),
+
        currallMorti = [];
            allTamponi = unpack(rows, 'tamponi'),
+
        currallTotCasi = [];
 +
        currallTamponi = [];
  
            listofRegions = [],
+
        currallMortiTi = [];
            currentCountry,
+
        currallMortiOsp = [];
            currentGdp = [],
 
            currentYear = [];
 
            currTitle = 'Abruzzo';
 
            currallRicoverati = [];
 
            currallTi = [];
 
            currallTo = [];
 
            currallIdom = [];
 
            currallAttPos = [];
 
            currallNewPos = [];
 
            currallDimGuariti = [];
 
            currallMorti = [];
 
            currallTotCasi = [];
 
            currallTamponi = [];
 
  
            currallMortiTi = [];
+
        for (var i = 0 ; i < allRegionNames.length ; i++){
             currallMortiOsp = [];
+
             if ( allRegionNames[i] === chosenCountry ) {
            //allDay = allDay.split(' ')[0];
+
                currentYear.push(allDay[i].split(' ')[0]);
 +
                currallRicoverati.push(allRicoverati[i]);
 +
                currallTi.push(allTi[i]);
 +
                currallTo.push(allTo[i]);
 +
                currallIdom.push(allIdom[i]);
 +
                currallAttPos.push(allAttPos[i]);
 +
                currallNewPos.push(allNewPos[i]);
 +
                currallDimGuariti.push(allDimGuariti[i]);
 +
                currallMorti.push(allMorti[i]);
 +
                currallTotCasi.push(allTotCasi[i]);
 +
                currallTamponi.push(allTamponi[i]);
  
        for (var i = 0; i < allRegionNames.length; i++ ){
+
                currallMortiTi.push(parseInt(allTi[i])+parseInt(allMorti[i]));
            if (listofRegions.indexOf(allRegionNames[i]) === -1 ){
+
                 currallMortiOsp.push(parseInt(allTo[i])+parseInt(allMorti[i]));
                 listofRegions.push(allRegionNames[i]);
 
 
             }
 
             }
 
         }
 
         }
 +
    };
  
        function getRegionData(chosenCountry) {
+
    // Default Region Data
            currTitle = chosenCountry;
+
    setBubblePlot('Abruzzo');
            currentYear = [];
 
            currallRicoverati = [];
 
            currallTi = [];
 
            currallTo = [];
 
            currallIdom = [];
 
            currallAttPos = [];
 
            currallNewPos = [];
 
            currallDimGuariti = [];
 
            currallMorti = [];
 
            currallTotCasi = [];
 
            currallTamponi = [];
 
  
             currallMortiTi = [];
+
    function setBubblePlot(chosenCountry) {
             currallMortiOsp = [];
+
        getRegionData(chosenCountry);
 +
 
 +
        var trace1 = {
 +
            visible: 'legendonly',
 +
            x: currentYear,
 +
            y: currallRicoverati,
 +
           
 +
            name: 'Ricoverati con sintomi',
 +
            mode: 'markers',
 +
             marker: {
 +
                size: 6,
 +
                opacity: 1
 +
             }
 +
        };
  
            for (var i = 0 ; i < allRegionNames.length ; i++){
+
        var trace2 = {
                if ( allRegionNames[i] === chosenCountry ) {
+
            visible: 'legendonly',
                    currentYear.push(allDay[i].split(' ')[0]);
+
            x: currentYear,
                    currallRicoverati.push(allRicoverati[i]);
+
            y: currallTi,
                    currallTi.push(allTi[i]);
+
           
                    currallTo.push(allTo[i]);
+
            mode: 'markers',
                    currallIdom.push(allIdom[i]);
+
            name: 'Terapia Intensiva',
                    currallAttPos.push(allAttPos[i]);
+
            marker: {
                    currallNewPos.push(allNewPos[i]);
+
                size: 6,
                    currallDimGuariti.push(allDimGuariti[i]);
+
                opacity: 1
                    currallMorti.push(allMorti[i]);
+
            }
                    currallTotCasi.push(allTotCasi[i]);
+
        };
                    currallTamponi.push(allTamponi[i]);
 
  
                    currallMortiTi.push(parseInt(allTi[i])+parseInt(allMorti[i]));
+
        var trace3 = {
                    currallMortiOsp.push(parseInt(allTo[i])+parseInt(allMorti[i]));
+
            visible: 'legendonly',
                 }
+
            x: currentYear,
 +
            y: currallTo,
 +
           
 +
            mode: 'markers',
 +
            name: 'Totale ospedalizzati',
 +
            marker: {
 +
                size: 6,
 +
                opacity: 1,
 +
                 symbol: 'triangle-down'
 
             }
 
             }
 
         };
 
         };
  
         // Default Region Data
+
         var trace4 = {
        setBubblePlot('Abruzzo');
+
            visible: 'legendonly',
 +
            x: currentYear,
 +
            y: currallIdom,
 +
           
 +
            mode: 'markers',
 +
            name: 'Isolamento domiciliare',
 +
            marker: {
 +
                size: 6,
 +
                opacity: 1,
 +
                symbol: 'triangle-left'
 +
            }
 +
        };
  
         function setBubblePlot(chosenCountry) {
+
         var trace5 = {
             getRegionData(chosenCountry);
+
             visible: 'legendonly',
 +
            x: currentYear,
 +
            y: currallAttPos,
 +
           
 +
            mode: 'markers',
 +
            name: 'Totale attualmente positivi',
 +
            marker: {
 +
                size: 6,
 +
                opacity: 1,
 +
                symbol: 'triangle-right'
 +
            }
 +
        };
  
            var trace1 = {
+
        var trace6 = {
                visible: 'legendonly',
+
            visible: 'legendonly',
                x: currentYear,
+
            x: currentYear,
                y: currallRicoverati,
+
            y: currallNewPos,
               
+
           
                name: 'Ricoverati con sintomi',
+
            mode: 'markers',
                mode: 'markers',
+
            name: 'Nuovi attualmente positivi',
                marker: {
+
            marker: {
                    size: 6,
+
                size: 6,
                    opacity: 1
+
                opacity: 1,
                 }
+
                 symbol: 'pentagon'
            };
+
            }
 +
        };
  
            var trace2 = {
+
        var trace7 = {
                visible: 'legendonly',
+
            x: currentYear,
                 x: currentYear,
+
            y: currallDimGuariti,
                 y: currallTi,
+
           
 +
            mode: 'markers',
 +
            name: 'Dimessi guariti',
 +
            marker: {
 +
                 size: 6,
 +
                 opacity: 1,
 +
                symbol: 'triangle-up'
 
                  
 
                  
                mode: 'markers',
+
            }
                name: 'Terapia Intensiva',
+
        };
                marker: {
 
                    size: 6,
 
                    opacity: 1
 
                }
 
            };
 
  
            var trace3 = {
+
        var trace8 = {
                visible: 'legendonly',
+
            x: currentYear,
                 x: currentYear,
+
            y: currallMorti,
                 y: currallTo,
+
           
 +
            mode: 'markers',
 +
            name: 'Deceduti',
 +
            marker: {
 +
                 size: 6,
 +
                 opacity: 1,
 +
                symbol: 'star'
 
                  
 
                  
                mode: 'markers',
+
            }
                name: 'Totale ospedalizzati',
+
        };
                marker: {
 
                    size: 6,
 
                    opacity: 1,
 
                    symbol: 'triangle-down'
 
                }
 
            };
 
  
            var trace4 = {
+
        var trace9 = {
                visible: 'legendonly',
+
            x: currentYear,
                x: currentYear,
+
            y: currallTotCasi,
                y: currallIdom,
+
           
               
+
            mode: 'markers',
                mode: 'markers',
+
            name: 'Totale casi',
                name: 'Isolamento domiciliare',
+
            marker: {
                marker: {
+
                size: 6,
                    size: 6,
+
                opacity: 1,
                    opacity: 1,
+
                symbol: 'diamond'
                    symbol: 'triangle-left'
+
            }
                }
+
        };
            };
 
  
            var trace5 = {
+
        var trace10 = {
                visible: 'legendonly',
+
            visible: 'legendonly',
                x: currentYear,
+
            x: currentYear,
                y: currallAttPos,
+
            y: currallTamponi,
               
+
           
                mode: 'markers',
+
            mode: 'markers',
                name: 'Totale attualmente positivi',
+
            name: 'Tamponi',
                marker: {
+
            marker: {
                    size: 6,
+
                size: 6,
                    opacity: 1,
+
                opacity: 1,
                    symbol: 'triangle-right'
+
                symbol: 'square'
                }
+
            }
            };
+
        };
  
            var trace6 = {
+
        var trace11 = {
                visible: 'legendonly',
+
            x: currentYear,
                x: currentYear,
+
            y: currallMortiTi,
                y: currallNewPos,
+
           
               
+
            mode: 'markers',
                mode: 'markers',
+
            name: 'Deceduti+Terapia Intensiva',
                name: 'Nuovi attualmente positivi',
+
            marker: {
                marker: {
+
                size: 6,
                    size: 6,
+
                opacity: 1,
                    opacity: 1,
+
                symbol: 'cross'
                    symbol: 'pentagon'
+
            }
                }
+
        };
            };
 
  
            var trace7 = {
+
        var trace12 = {
                x: currentYear,
+
            x: currentYear,
                 y: currallDimGuariti,
+
            y: currallMortiOsp,
 +
           
 +
            mode: 'markers',
 +
            name: 'Deceduti+Terapia Intensiva+Ricoverati',
 +
            marker: {
 +
                 size: 6,
 +
                opacity: 1,
 +
                symbol: 'x'
 
                  
 
                  
                mode: 'markers',
+
            }
                name: 'Dimessi guariti',
+
        };
                marker: {
+
        var when = 21;
                    size: 6,
+
        [dx, dy,lname, when] = get_logistic(chosenCountry,when);
                    opacity: 1,
 
                    symbol: 'triangle-up'
 
                   
 
                }
 
            };
 
  
            var trace8 = {
+
        var trace13 = {
                x: currentYear,
+
            x: dx,
                y: currallMorti,
+
            y: dy,
               
+
            mode: 'line',
                mode: 'markers',
+
            name: lname,
                name: 'Deceduti',
+
            line: {
                marker: {
+
                color: 'rgba(255,0,0,0.5)',
                    size: 6,
+
                width: 4
                    opacity: 1,
+
            }
                    symbol: 'star'
+
        };
                   
 
                }
 
            };
 
  
            var trace9 = {
 
                x: currentYear,
 
                y: currallTotCasi,
 
               
 
                mode: 'markers',
 
                name: 'Totale casi',
 
                marker: {
 
                    size: 6,
 
                    opacity: 1,
 
                    symbol: 'diamond'
 
                }
 
            };
 
  
            var trace10 = {
+
        [dxa, dya,lnamea,when] = get_logistic(chosenCountry,when);
                visible: 'legendonly',
+
        var trace14 = {
                x: currentYear,
+
            x: dxa,
                y: currallTamponi,
+
            y: dya,
               
+
            mode: 'line',
                mode: 'markers',
+
            name: lnamea,
                name: 'Tamponi',
+
            line: {
                marker: {
+
                color: 'rgba(255,120,120,0.5)',
                    size: 6,
+
                width: 2
                    opacity: 1,
+
            }
                    symbol: 'square'
+
        };
                }
 
            };
 
  
            var trace11 = {
+
        [dxa, dya,lnamea,when] = get_logistic(chosenCountry,when);
                x: currentYear,
+
        var trace15 = {
                y: currallMortiTi,
+
            x: dxa,
               
+
            y: dya,
                mode: 'markers',
+
            mode: 'line',
                name: 'Deceduti+Terapia Intensiva',
+
            name: lnamea,
                marker: {
+
            line: {
                    size: 6,
+
                color: 'rgba(255,180,180,0.5)',
                    opacity: 1,
+
                width: 2
                    symbol: 'cross'
+
            }
                }
+
        };
            };
 
  
            var trace12 = {
+
        [dxa, dya,lnamea,when] = get_logistic(chosenCountry,when);
                x: currentYear,
+
        var trace16 = {
                y: currallMortiOsp,
+
            x: dxa,
               
+
            y: dya,
                mode: 'markers',
+
            mode: 'line',
                name: 'Deceduti+Terapia Intensiva+Ricoverati',
+
            name: lnamea,
                marker: {
+
            line: {
                    size: 6,
+
                color: 'rgba(255,210,210,0.5)',
                    opacity: 1,
+
                width: 2
                    symbol: 'x'
+
            }
                   
+
        };
                }
 
            };
 
  
            var data = [trace8,  
+
        var data = [trace8,  
                        trace7,  
+
                    trace7,  
                        trace11,  
+
                    trace11,  
                        trace12,  
+
                    trace12,  
                        trace9,  
+
                    trace9,  
                        trace1,  
+
                    trace1,  
                        trace2,  
+
                    trace2,  
                        trace3,  
+
                    trace3,  
                        trace4,  
+
                    trace4,  
                        trace5,
+
                    trace5,
                        trace6,
+
                    trace6,
                        trace10];
+
                    trace10,
 +
                    trace13, trace14, trace15, trace16];
  
            var updatemenus=[
+
        var updatemenus=[
                {
+
            {
                    buttons: [
+
                buttons: [
                        {
+
                    {
                            args: [{'yaxis.type': 'linear',
+
                        args: [{'yaxis.type': 'linear',
                                    'yaxis.tickmode':'auto'}],
+
                                'yaxis.tickmode':'auto'}],
                            label: 'Linear',
+
                        label: 'Linear',
                            method: 'relayout'
+
                        method: 'relayout'
                        },
+
                    },
                        {
+
                    {
                            args: [{'yaxis.type':'log',
+
                        args: [{'yaxis.type':'log',
                                    'yaxis.dtick':1}],
+
                                'yaxis.dtick':1}],
                            label:'SemiLog',
+
                        label:'SemiLog',
                            method:'relayout'
+
                        method:'relayout'
                        }
+
                    }
                    ],
+
                ],
                    direction: 'left',
+
                direction: 'left',
                    pad: {'r': 10, 't': 10},
+
                pad: {'r': 10, 't': 10},
                    showactive: true,
+
                showactive: true,
                    type: 'buttons',
+
                type: 'buttons',
                    x: 0.1,
+
                x: 0.1,
                    xanchor: 'left',
+
                xanchor: 'left',
                    y: 1.1,
+
                y: 1.1,
                    yanchor: 'top'
+
                yanchor: 'top'
                }
+
            }
            ]
+
        ]
  
            var layout = {
+
        var layout = {
                title: 'Andamento regionale ' + currTitle,
+
            title: 'Andamento regionale ' + currTitle,
                height: 600,
+
            height: 600,
                plot_bgcolor: "#000",
+
            plot_bgcolor: "#000",
                //width: 800,
+
            //width: 800,
                margin: { l: 40, r: 0},
+
            margin: { l: 40, r: 0},
                updatemenus: updatemenus,
+
            updatemenus: updatemenus,
                showlegend: true,
+
            showlegend: true,
                legend: { orientation: "h" ,
+
            legend: { orientation: "h" ,
                        x: 0,
+
                    x: 0,
                        y: -0.5},
+
                    y: -0.5},
                xaxis: {
+
            xaxis: {
                    tickmode: "linear", //  If "linear", the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick`
+
                tickmode: "linear", //  If "linear", the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick`
                    tick0: '2020-02-24',
+
                tick0: '2020-02-24',
                    gridcolor: '#555',
+
                gridcolor: '#555',
                    dtick: 24 * 60 * 60 * 1000
+
                dtick: 24 * 60 * 60 * 1000
                },
+
            },
                yaxis: {
+
            yaxis: {
                    autorange: true,
+
                autorange: true,
                    gridcolor: '#555',
+
                gridcolor: '#555',
                    //type: 'log',
+
                //type: 'log',
                    //fixedrange: true,
+
                //fixedrange: true,
                    //range: [0,3.70]
+
                //range: [0,3.70]
                    //range: [0,5000]
+
                //range: [0,5000]
                }
+
             }
            };
 
            var options = {
 
                scrollZoom: true,
 
                displayModeBar: false
 
             };
 
            Plotly.newPlot('myDiv', data, layout,options);
 
 
         };
 
         };
 +
        var options = {
 +
            scrollZoom: true,
 +
            displayModeBar: false
 +
        };
 +
        Plotly.newPlot('myDiv', data, layout,options);
 +
    };
  
        var innerContainer = document.querySelector('[data-num="0"'),
+
    var innerContainer = document.querySelector('[data-num="0"'),
            plotEl = innerContainer.querySelector('.plot'),
+
        plotEl = innerContainer.querySelector('.plot'),
            countrySelector = innerContainer.querySelector('.countrydata');
+
        countrySelector = innerContainer.querySelector('.countrydata');
  
        function assignOptions(textArray, selector) {
+
    function assignOptions(textArray, selector) {
            for (var i = 0; i < textArray.length;  i++) {
+
        for (var i = 0; i < textArray.length;  i++) {
                var currentOption = document.createElement('option');
+
            var currentOption = document.createElement('option');
                currentOption.text = textArray[i];
+
            currentOption.text = textArray[i];
                selector.appendChild(currentOption);
+
            selector.appendChild(currentOption);
             }
+
        }
 +
    }
 +
    function getRandomColor(){
 +
        var r = 0;
 +
        var g = 0;
 +
        var b = 0;
 +
        r = getRandomInt(0, 255);
 +
        g = getRandomInt(0, 255);
 +
        b = getRandomInt(0, 255);
 +
        return [r,g,b];
 +
    }
 +
 
 +
    function getRandomInt(min, max) {
 +
        min = Math.ceil(min);
 +
        max = Math.floor(max);
 +
        return Math.floor(Math.random() * (max - min)) + min; //Il max è escluso e il min è incluso
 +
    }
 +
    function get_logistic(chosenCountry,when){
 +
        //document.write('./'+chosenCountry + '.csv');
 +
        //
 +
       
 +
        var nome = when+'.03 - Fitting';
 +
        var x = [];
 +
        var y = [];
 +
        var url = "https://raw.githubusercontent.com/vtandrea/labtest/master/"+'2020-03-'+when+chosenCountry+".csv";
 +
        console.log(url);
 +
        var request = new XMLHttpRequest(); 
 +
        request.open("GET", url, false); 
 +
        request.send(null); 
 +
       
 +
        var csvData = new Array();
 +
        var jsonObject = request.responseText.split(/\r?\n|\r/);
 +
        for (var i = 0; i < jsonObject.length; i++) {
 +
            csvData.push(jsonObject[i].split(','));
 +
        }
 +
        for (var i=1;i<csvData.length;i++){
 +
            x.push(csvData[i][0]);
 +
            y.push(csvData[i][1]);
 +
              
 +
        }
 +
        //if(1){
 +
        if (y[40] == y[41]){
 +
            var x = [];
 +
            var y = [];
 +
            var nome = 'Empty';
 
         }
 
         }
 +
        //console.log(csvData[0][1]);
 +
        when = when-1;
 +
        return [x,y, nome,when];
 +
    }
  
        assignOptions(listofRegions, countrySelector);
+
    assignOptions(listofRegions, countrySelector);
  
        function updateCountry(){
+
    function updateCountry(){
            setBubblePlot(countrySelector.value);
+
        setBubblePlot(countrySelector.value);
        }
+
    }
  
        countrySelector.addEventListener('change', updateCountry, false);
+
    countrySelector.addEventListener('change', updateCountry, false);
    });
+
});
 
</script>
 
</script>
 
</html>
 
</html>

Revisione 01:50, 22 Mar 2020

COVID19 - Monitoraggio ed Analisi della situazione italiana

Andamento nazionale

Andamenti regionali

Regione:

Disclaimer

Dati forniti dal Ministero della Salute, elaborazione e gestione dati a cura del Dipartimento della Protezione Civile: https://github.com/pcm-dpc/COVID-19

Rielaborazione a cura del Control of Dynamic System Lab, Politecnico di Bari

COVID19 - Monitoraggio ed Analisi della situazione italiana[edit]

Andamento nazionale[edit]

Andamenti regionali[edit]

Regione:

Disclaimer[edit]

Dati forniti dal Ministero della Salute, elaborazione e gestione dati a cura del Dipartimento della Protezione Civile: https://github.com/pcm-dpc/COVID-19

Rielaborazione a cura del Control of Dynamic System Lab, Politecnico di Bari