J'utilise ce qui suit pour regrouper des données :
const formatted = data.map(
area => {
return {
"state": area["Province_State"],
"lat": area["lat"],
"long": area["long"],
"data": Object.keys(area).reduce( (prev, next) => {
if(next === 'date' ) {
// do something
prev[next] = removeTime( area[next])
} else {
prev[next]= area[next];
}
return prev;
} , {})
};
}
);
Mais cela ne correspond pas au format dont j'ai besoin.
Cela produit une série de données comme celle-ci :
{state: "Alabama", ID: "c6d6ee4b-89d3-4634-807d-340a2b35d6a4", long: -86, lat: 32, name: "Alabama", …}
ID: "c6d6ee4b-89d3-4634-807d-340a2b35d6a4"
data:
Active: "3470"
Confirmed: "3563"
Country_Region: "US"
Deaths: "93"
FIPS: "1"
Hospitalization_Rate: "12.26494527"
ISO3: "USA"
Incident_Rate: "75.98802021"
Mortality_Rate: "2.610159978"
People_Hospitalized: "437"
People_Tested: "21583"
Province_State: "Alabama"
Recovered: ""
Testing_Rate: "460.3001516"
UID: "84000001"
date: "2020-04-12"
lat: "32.3182"
long: "-86.9023"
__proto__: Object
lat: 32
long: -86
name: "Alabama"
state: "Alabama"
Mais comme chaque État dispose d'un plus grand nombre de données pour chaque date
J'ai besoin de toutes les dates sous data
afin de l'avoir comme :
State: "Alabama"
ID: 2
Lat: 41.1533
Long: 20.1683
Province/State: ""
data: Array(109)
[0 … 99]
0: {date: "1/22/20", Confirmed: 0, Deaths: 0, Recovered: 0}
1: {date: "1/23/20", Confirmed: 0, Deaths: 0, Recovered: 0}
2: {date: "1/24/20", Confirmed: 0, Deaths: 0, Recovered: 0}
Le code que j'utilise ne regroupe pas TOUTES les dates sous la rubrique data
mais il donne une série d'objs séparés