Created
November 21, 2021 12:37
-
-
Save hellwolf/da3d51d90b8d2ec7fcb83cf74c68ddba to your computer and use it in GitHub Desktop.
transformONSTable4 used in Open Safety Vaccine Inquiry (https://docs.google.com/spreadsheets/d/1rHTI_Ir2EOvC1FFqK8ASHR_Ts2ckrqMkbf67Zkvhl8s/edit#gid=0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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