currentData = {
const sourceData = await d3.csv(DATA_URLS[`${dataInfo.dataset1}_${dataInfo.variable}`])
const targetData = await d3.csv(DATA_URLS[`${dataInfo.dataset2}_${dataInfo.variable}`])
let pctData = {};
let sourceSums = [];
let targetSums = [];
const allKeys = Object.keys(sourceData[0]).slice(1,)
const tempKeys = Object.keys(sourceData[0]).slice(1+7*(weekAggregation-1),)
for (let i=0; i<sourceData.length; i++){
let tempObj = {
'fips':sourceData[i].fips
}
const tempTargetData = find(targetData, 'fips', sourceData[i].fips)
if (tempTargetData === undefined) {
continue
}
for (let n=0; n<tempKeys.length; n++){
let sourceValue = +sourceData[i][tempKeys[n]]
let targetValue = +tempTargetData[tempKeys[n]]
if (sourceValue && targetValue) {
for (let q=1; q<weekAggregation; q++){
sourceValue += +sourceData[i][allKeys[allKeys.indexOf(tempKeys[n])-(q*7)]]||0
targetValue += +targetData[i][allKeys[allKeys.indexOf(tempKeys[n])-(q*7)]]||0
}
sourceValue = sourceValue/weekAggregation
targetValue = targetValue/weekAggregation
if (sourceSums[n]===undefined){
sourceSums.push(+sourceValue||0)
targetSums.push(+targetValue||0)
} else {
sourceSums[n] += +sourceValue||0
targetSums[n] += +targetValue||0
}
if (sourceValue === targetValue || (sourceValue === 0 && targetValue === 0)) {
tempObj[tempKeys[n]] = 0
} else if (sourceValue === 0 && targetValue !== 0){
tempObj[tempKeys[n]] = 1
} else {
tempObj[tempKeys[n]] = (targetValue-sourceValue)/sourceValue
}
} else {
continue
}
}
pctData[sourceData[i].fips] = tempObj
}
let returnSums = []
for (let i=0; i<sourceSums.length; i++){
returnSums.push({
'value':sourceSums[i],
'dataset':dataInfo.dataset1,
'date':tempKeys[i]
})
returnSums.push({
'value':targetSums[i],
'dataset':dataInfo.dataset2,
'date':tempKeys[i]
})
}
return {pctData, returnSums, dates: tempKeys, [dataInfo.dataset1]: sourceSums, [dataInfo.dataset2]: targetSums }
}