move parsing to parsing.gs; write a simple parser for a demographics line

This commit is contained in:
stupidcomputer 2024-06-24 07:21:55 -05:00
parent 01b8cbee4a
commit 967a06a1b4
2 changed files with 55 additions and 0 deletions

View File

@ -1,3 +1,5 @@
function onOpen() { function onOpen() {
var ui = SpreadsheetApp.getUi(); var ui = SpreadsheetApp.getUi();

53
parsing.gs Normal file
View File

@ -0,0 +1,53 @@
/* The "Intern" age is an implementation detail. */
ages = ["Adult", "Child", "Intern"]
/* These genders are not representative of the totality, but because I'm
* programming to a spec these are the choices. */
genders = ["Male", "Female", "Unknown", "Other"]
/* This sounds wrong but it's the data we need to output. */
ethnicities = ["Hispanic", "Not Hispanic"]
/* Sorry in advance. */
races = [
"American Indian/Alaskan Native",
"Asian",
"Black/African American",
"Native Hawaiian/Other Pacific Islander",
"White",
"More than one race",
"Unknown",
]
/* These are for brevity -- they're as they appear on the form.
* The form should be at ./demographic-information-form.pdf. */
age_shortcodes = ["A", "C", "I"]
gender_shortcodes = ["M", "F", "U", "O"]
ethnicity_shortcodes = ["H", "NH"]
race_shortcodes = ["AI/AN", "AS", "B/AA", "NH/OPI", "WH", "1+", "UNK"]
function parseDemographicsLine(line) {
/* Take a row of the Demographics Data spreadsheet, then parse it into a dictionary. */
site_name = line[0]
count = Number(line[1])
age = ages[age_shortcodes.indexOf(line[2])]
gender = genders[gender_shortcodes.indexOf(line[3])]
ethnicity = ethnicities[ethnicity_shortcodes.indexOf(line[4])]
race = races[race_shortcodes.indexOf(line[5])]
return Array(count).fill({
site: site_name,
age: age,
gender: gender,
ethnicity: ethnicity,
race: race,
})
}
function parseDemographicsLineTest() {
console.log(parseDemographicsLine([
"Testing site",
5,
"A",
"M",
"NH",
"B/AA"
]))
}