@@ -36,24 +36,45 @@ export default {
3636 )
3737 return timeSince ( last ) + ' ago'
3838 }
39- const cases = confirmed . locations . map ( ( location , index ) => {
40- return {
41- type : 'Feature' ,
42- properties : {
43- country : location . country ,
44- country_code : location . country_code ,
45- confirmed_count : location . latest ,
46- recovered_count : recovered . locations [ index ] . latest || 0 ,
47- dead_count : deaths . locations [ index ] . latest || 0 ,
48- province : location . province ,
49- last_update : lastUpdate ( location . history )
50- } ,
51- geometry : {
52- type : 'Point' ,
53- coordinates : [ location . coordinates . long , location . coordinates . lat ]
39+ const cases = confirmed . locations
40+ . reduce ( ( result , currentValue ) => {
41+ if ( currentValue . latest ) {
42+ result . push ( currentValue )
5443 }
55- }
56- } )
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 {
59+ type : 'Feature' ,
60+ properties : {
61+ country : location . country ,
62+ country_code : location . country_code ,
63+ province : location . province ,
64+ confirmed_count : location . latest ,
65+ 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 ) ,
70+ last_update : lastUpdate ( location . history )
71+ } ,
72+ geometry : {
73+ type : 'Point' ,
74+ coordinates : [ location . coordinates . long , location . coordinates . lat ]
75+ }
76+ }
77+ } )
5778 state . data = {
5879 type : 'FeatureCollection' ,
5980 features : cases
@@ -72,6 +93,19 @@ export default {
7293 state . countries = groupProvinceByCountry ( data . locations , 'country' )
7394 } ,
7495 SET_COUNTRY_CASE : ( state , country_case ) => {
75- state . country_case = country_case
96+ // const merged_history = {}
97+ // const history = [
98+ // country_case[0].properties.confirmed_history,
99+ // country_case[0].properties.recovered_history,
100+ // country_case[0].properties.dead_history
101+ // ]
102+ // history.forEach(item => {
103+ // Object.keys(item).forEach(key => {
104+ // merged_history[key] = merged_history[key] || []
105+ // merged_history[key].push(item[key] || 0)
106+ // })
107+ // })
108+ // state.country_case = Object.assign(country_case[0].properties, { merged_history: merged_history })
109+ state . country_case = Object . assign ( { } , country_case [ 0 ] . properties )
76110 }
77111}
0 commit comments