Skip to content

Instantly share code, notes, and snippets.

@hellwolf
Created November 21, 2021 12:37
Show Gist options
  • Save hellwolf/da3d51d90b8d2ec7fcb83cf74c68ddba to your computer and use it in GitHub Desktop.
Save hellwolf/da3d51d90b8d2ec7fcb83cf74c68ddba to your computer and use it in GitHub Desktop.
function transformONSTable4(rangeONS, targetAgeGroup) {
const values = rangeONS;// a 2D array
var newDataMap = {};
// Get the value in each cell, remove apostrophes from the start,
// and replace the value in that cell
for(n in values){
const weekEnding = new Date(values[n][0]).toISOString().slice(0, 10);
const vaxStatus = values[n][2];
const ageGroup = values[n][3];
const nDeath = values[n][4];
const mortalityRate = values[n][7];
if (targetAgeGroup !== ageGroup) continue;
if (!(weekEnding in newDataMap)) newDataMap[weekEnding] = {};
newDataMap[weekEnding][vaxStatus] = {
nDeath,
mortalityRate,
}
}
return Object.keys(newDataMap).map(weekEnding => {
const row = newDataMap[weekEnding];
return [
weekEnding,
row["Unvaccinated"].mortalityRate,
row["Within 21 days of first dose"].mortalityRate,
row["21 days or more after first dose"].mortalityRate,
row["Second dose"].mortalityRate,
]
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment