Implementazione lettura da CSV
4
.editorconfig
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*.js]
|
||||||
|
indent_size = 2
|
0
.eslintrc.js
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
4
README.md
Normal file → Executable file
@ -8,9 +8,7 @@ https://franjsco.github.io/covid19-campania/
|
|||||||
|
|
||||||
|
|
||||||
## Provenienza dei dati
|
## Provenienza dei dati
|
||||||
I dati nella dashbord sono prelevati da un servizio web (REST API) messo a disposizione da OpenPuglia.
|
I dati nella dashbord sono prelevati direttamente dal [repository ufficiale della Protezione Civile](https://github.com/pcm-dpc/COVID-19).
|
||||||
|
|
||||||
Il [servizio web di OpenPuglia](https://github.com/ondata/covid19italia) è agganciato ai dati ufficiali pubblicati sul [repository della Protezione Civile](https://github.com/pcm-dpc/COVID-19) come indicato dal loro repository.
|
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
10
package-lock.json
generated
Normal file → Executable file
@ -4029,6 +4029,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.9.tgz",
|
||||||
"integrity": "sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q=="
|
"integrity": "sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q=="
|
||||||
},
|
},
|
||||||
|
"csvjson-csv2json": {
|
||||||
|
"version": "5.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/csvjson-csv2json/-/csvjson-csv2json-5.0.6.tgz",
|
||||||
|
"integrity": "sha512-to9QlVI4yQFPzSqi6XZ97lULKs5m3K8hlE/UkbvKSw81FfDwgV9MUtSbHFJ4SRT4IA7UPkuW2EqsH/MWN5YRow=="
|
||||||
|
},
|
||||||
"cyclist": {
|
"cyclist": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz",
|
||||||
@ -4078,6 +4083,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"date-fns": {
|
||||||
|
"version": "2.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.11.0.tgz",
|
||||||
|
"integrity": "sha512-8P1cDi8ebZyDxUyUprBXwidoEtiQAawYPGvpfb+Dg0G6JrQ+VozwOmm91xYC0vAv1+0VmLehEPb+isg4BGUFfA=="
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||||
|
2
package.json
Normal file → Executable file
@ -11,6 +11,8 @@
|
|||||||
"@testing-library/user-event": "^7.2.1",
|
"@testing-library/user-event": "^7.2.1",
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"bootstrap": "^4.4.1",
|
"bootstrap": "^4.4.1",
|
||||||
|
"csvjson-csv2json": "^5.0.6",
|
||||||
|
"date-fns": "^2.11.0",
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react": "^16.13.0",
|
"react": "^16.13.0",
|
||||||
"react-bootstrap": "^1.0.0-beta.17",
|
"react-bootstrap": "^1.0.0-beta.17",
|
||||||
|
0
public/favicon.ico
Normal file → Executable file
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
0
public/index.html
Normal file → Executable file
0
public/logo192.png
Normal file → Executable file
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
0
public/manifest.json
Normal file → Executable file
0
public/robots.txt
Normal file → Executable file
0
screenshot.png
Normal file → Executable file
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
0
src/App.css
Normal file → Executable file
0
src/App.js
Normal file → Executable file
0
src/App.test.js
Normal file → Executable file
0
src/LICENSE
Normal file → Executable file
58
src/api/DataFromRepository.js
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
// import axios from 'axios';
|
||||||
|
import axios from 'axios';
|
||||||
|
import csv2json from 'csvjson-csv2json';
|
||||||
|
|
||||||
|
import { format, addDays, getHours } from 'date-fns';
|
||||||
|
|
||||||
|
|
||||||
|
const getCSVRegionifromRepository = async (date) => {
|
||||||
|
const url = 'https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/';
|
||||||
|
const filename = `dpc-covid19-ita-regioni-${format(date, 'yyyyMMdd')}.csv`;
|
||||||
|
const finalURL = `${url + filename}`;
|
||||||
|
let result;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await axios.get(finalURL);
|
||||||
|
result = res.data;
|
||||||
|
} catch (error) {
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const convertCSVtoJSON = (csv) => {
|
||||||
|
if (!csv) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return csv2json(csv, { parseNumbers: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
const getData = async () => {
|
||||||
|
const actualDate = new Date();
|
||||||
|
const previousDate = addDays(actualDate, -1);
|
||||||
|
const hour = getHours(actualDate);
|
||||||
|
let result;
|
||||||
|
|
||||||
|
// preleva il CSV con data attuale solamente se sono passate le 18
|
||||||
|
if (hour >= 18) {
|
||||||
|
result = await getCSVRegionifromRepository(actualDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// preleva il CSV con data precedente qualora non fosse stato trovato quello attuale
|
||||||
|
if (!result) {
|
||||||
|
result = await getCSVRegionifromRepository(previousDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// converte il CSV in JSON e filtra i dati per la regione Campania
|
||||||
|
if (result) {
|
||||||
|
const tmpJSON = convertCSVtoJSON(result);
|
||||||
|
result = tmpJSON.find((d) => d.denominazione_regione === 'Campania');
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getData;
|
0
src/components/Card.js
Normal file → Executable file
0
src/components/Footer.js
Normal file → Executable file
0
src/components/Headbar.js
Normal file → Executable file
2
src/components/Infobox.js
Normal file → Executable file
@ -7,7 +7,7 @@ const Infobox = (props) => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<span className="font-weight-bold">Ultimo aggiornamento: </span>
|
<span className="font-weight-bold">Ultimo aggiornamento: </span>
|
||||||
{ dataAggiornamento }
|
{ dataAggiornamento.split(' ')[0] }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
0
src/components/Layout.js
Normal file → Executable file
25
src/containers/Dashboard.js
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Container, Row, Col } from 'react-bootstrap';
|
import { Container, Row, Col } from 'react-bootstrap';
|
||||||
import axios from 'axios';
|
|
||||||
|
import getDataFromRepository from '../api/DataFromRepository';
|
||||||
|
|
||||||
import Card from '../components/Card';
|
import Card from '../components/Card';
|
||||||
import Infobox from '../components/Infobox';
|
import Infobox from '../components/Infobox';
|
||||||
@ -11,12 +12,12 @@ class Dashboard extends Component {
|
|||||||
this.state = {};
|
this.state = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
async componentDidMount() {
|
||||||
axios
|
const data = await getDataFromRepository();
|
||||||
.get('https://openpuglia.org/api/?q=getdatapccovid-19®=campania')
|
this.setState(data);
|
||||||
.then((response) => this.setState(response.data[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { state } = this;
|
const { state } = this;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ class Dashboard extends Component {
|
|||||||
<Card
|
<Card
|
||||||
bgColor="warning"
|
bgColor="warning"
|
||||||
title="Totale casi"
|
title="Totale casi"
|
||||||
value={state['totale casi']}
|
value={state.totale_casi}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ class Dashboard extends Component {
|
|||||||
<Card
|
<Card
|
||||||
bgColor="success"
|
bgColor="success"
|
||||||
title="Guariti"
|
title="Guariti"
|
||||||
value={state['dimessi guariti']}
|
value={state.dimessi_guariti}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
@ -63,7 +64,7 @@ class Dashboard extends Component {
|
|||||||
<Card
|
<Card
|
||||||
bgColor="info"
|
bgColor="info"
|
||||||
title="Attualmente positivi"
|
title="Attualmente positivi"
|
||||||
value={state['totale attualmente positivi']}
|
value={state.totale_attualmente_positivi}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ class Dashboard extends Component {
|
|||||||
<Card
|
<Card
|
||||||
bgColor="info"
|
bgColor="info"
|
||||||
title="Nuovi attualmente positivi"
|
title="Nuovi attualmente positivi"
|
||||||
value={state['nuovi attualmente positivi']}
|
value={state.nuovi_attualmente_positivi}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ class Dashboard extends Component {
|
|||||||
<Card
|
<Card
|
||||||
textColor="dark"
|
textColor="dark"
|
||||||
title="Totale ospedalizzati"
|
title="Totale ospedalizzati"
|
||||||
value={state['totale ospedalizzati']}
|
value={state.totale_ospedalizzati}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ class Dashboard extends Component {
|
|||||||
<Card
|
<Card
|
||||||
textColor="dark"
|
textColor="dark"
|
||||||
title="Terapia intensiva"
|
title="Terapia intensiva"
|
||||||
value={state['terapia intensiva']}
|
value={state.terapia_intensiva}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ class Dashboard extends Component {
|
|||||||
<Card
|
<Card
|
||||||
textColor="dark"
|
textColor="dark"
|
||||||
title="Isolamento domiciliare"
|
title="Isolamento domiciliare"
|
||||||
value={state['isolamento domiciliare']}
|
value={state.isolamento_domiciliare}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
0
src/index.css
Normal file → Executable file
0
src/index.js
Normal file → Executable file
0
src/logo.svg
Normal file → Executable file
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |