Skip to content

Commit 4dbfa67

Browse files
committed
Fix data
1 parent 5bd16d7 commit 4dbfa67

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# COVID-19 Tracker
22
tracks COVID-19 around the world
3+
4+
## API
5+
The API was provided by [ExpDev07/coronavirus-tracker-api](https://github.com/ExpDev07/coronavirus-tracker-api).
6+
7+
## Data
8+
The data comes from the [2019 Novel Coronavirus (nCoV) Data Repository, provided
9+
by JHU CCSE](https://github.com/CSSEGISandData/2019-nCoV).
10+

store/mutations.js

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
export default {
22
SET_DATA: (state, data) => {
33
const { confirmed, deaths, recovered } = data
4+
const dataCollection = {
5+
type: 'FeatureCollection',
6+
features: []
7+
}
48
const timeSince = (date) => {
59
let seconds = Math.floor((new Date() - date) / 1000)
610
let interval = Math.floor(seconds / 31536000)
@@ -36,49 +40,60 @@ export default {
3640
)
3741
return timeSince(last) + ' ago'
3842
}
39-
const cases = confirmed.locations
40-
.reduce((result, currentValue) => {
41-
if (currentValue.latest) {
42-
result.push(currentValue)
43-
}
44-
return result
45-
}, [])
46-
.map((location, index) => {
47-
const sortDate = dates => {
48-
const sorted_date = {}
49-
Object.keys(dates)
50-
.sort((a, b) => {
51-
return new Date(a) - new Date(b)
52-
})
53-
.forEach(key => {
54-
sorted_date[key] = dates[key]
55-
})
56-
return sorted_date
57-
}
58-
return {
43+
const sortDate = dates => {
44+
const sorted_date = {}
45+
Object.keys(dates)
46+
.sort((a, b) => {
47+
return new Date(a) - new Date(b)
48+
})
49+
.forEach(key => {
50+
sorted_date[key] = dates[key]
51+
})
52+
return sorted_date
53+
}
54+
confirmed.locations.forEach((location, index) => {
55+
const recovered_locations = recovered.locations[index]
56+
const dead_locations = deaths.locations[index]
57+
let recovered_count = 0
58+
let dead_count = 0
59+
if (
60+
location.coordinates.long === recovered_locations.coordinates.long
61+
&& location.coordinates.lat === recovered_locations.coordinates.lat
62+
) {
63+
recovered_count = recovered_locations.latest
64+
}
65+
if (
66+
location.coordinates.long === dead_locations.coordinates.long
67+
&& location.coordinates.lat === dead_locations.coordinates.lat
68+
) {
69+
dead_count = dead_locations.latest
70+
}
71+
if (location.latest || recovered_count || dead_count) {
72+
dataCollection.features.push({
5973
type: 'Feature',
6074
properties: {
6175
country: location.country,
6276
country_code: location.country_code,
6377
province: location.province,
6478
confirmed_count: location.latest,
6579
confirmed_history: sortDate(location.history),
66-
recovered_count: recovered.locations[index].latest || 0,
67-
recovered_history: sortDate(recovered.locations[index].history),
68-
dead_count: deaths.locations[index].latest || 0,
69-
dead_history: sortDate(deaths.locations[index].history),
80+
recovered_count: recovered_count,
81+
recovered_history: sortDate(recovered_locations.history),
82+
dead_count: dead_count,
83+
dead_history: sortDate(recovered_locations.history),
7084
last_update: lastUpdate(location.history)
7185
},
7286
geometry: {
7387
type: 'Point',
74-
coordinates: [ location.coordinates.long, location.coordinates.lat ]
88+
coordinates: [
89+
location.coordinates.long,
90+
location.coordinates.lat
91+
]
7592
}
76-
}
77-
})
78-
state.data = {
79-
type: 'FeatureCollection',
80-
features: cases
81-
}
93+
})
94+
}
95+
})
96+
state.data = dataCollection
8297
},
8398
SET_LATEST: (state, latest) => {
8499
state.latest = latest

0 commit comments

Comments
 (0)