allDataUnion= {
let array = [];
for (let year = 1900; year < 2020; year++) {
let gasPriceThisYear = gasPrice.filter(d => d.year == year);
if (gasPriceThisYear.length > 0) gasPriceThisYear = gasPriceThisYear[0].price;
else gasPriceThisYear = 0;
let incomeThisYear = income.filter(d => d.year == year);
if (incomeThisYear.length > 0) incomeThisYear = incomeThisYear[0].income;
else incomeThisYear = 0;
let populationThisYear = population.filter(d => d.year == year);
if (populationThisYear.length > 0) populationThisYear = d3.sum(populationThisYear.map(d => d.pop));
else populationThisYear = 0;
let tourismThisYear = tourismIn.filter(d => d.year == year);
if (tourismThisYear.length > 0) tourismThisYear = d3.sum(tourismThisYear.map(d => d.population));
else tourismThisYear = 0;
let numberOfParksThisYear = park.filter(d => d.year == year);
if (numberOfParksThisYear.length > 0) numberOfParksThisYear = d3.sum(numberOfParksThisYear.map(d => d.count));
else numberOfParksThisYear = 0;
let parkVisits = park.filter(d => d.year == year);
let tempList = [];
for (let c = 0; c < parkVisits.length; c++) {
let type = filter(parkVisits[c].type);
if (type === null) {
continue;
}
let d = {
year: year,
parkVisits: parseFloat(parkVisits[c].visitors),
parkState: parkVisits[c].state,
parkType: type,
parkName: parkVisits[c].parkname,
gasPrice: gasPriceThisYear,
income: incomeThisYear,
population: populationThisYear,
tourist: tourismThisYear,
numberOfParks: numberOfParksThisYear
}
tempList.push(d);
}
let typeCount = d3.nest()
.key(d => d.parkType)
.rollup(v => v.length)
.entries(tempList);
let typeVisitorsCount = d3.nest()
.key(d => d.parkType)
.rollup(v => {
return v.reduce((acc, d) => acc += d.parkVisits, 0)
})
.entries(tempList);
for (let c = 0; c < tempList.length; c++) {
let parkTemp = tempList[c];
let typeCountTemp = typeCount.filter(d => d.key == parkTemp.parkType)[0].value;
let typeVisitorsCountTemp = typeVisitorsCount.filter(d => d.key == parkTemp.parkType)[0].value;
parkTemp["percentPerTypePerYear"] = typeCountTemp/tempList.length*100;
parkTemp["perTypePerYearRatioWithVisitor"] = typeVisitorsCountTemp/tempList.filter(
d => d.parkType == parkTemp.parkType
).length;
}
array = array.concat(tempList);
}
array.filter(d => d.parkVisits > 0);
return array;
}