change project structure, introduce data collation mechanism
This commit is contained in:
parent
967a06a1b4
commit
981226c0d2
120
Code.gs
120
Code.gs
|
@ -1,4 +1,6 @@
|
|||
|
||||
var _demographic_data = "*Demographic Data";
|
||||
var _site_information = "*Site Information";
|
||||
var _intern_data = "*Intern Data";
|
||||
|
||||
function onOpen() {
|
||||
var ui = SpreadsheetApp.getUi();
|
||||
|
@ -32,7 +34,7 @@ function spread_init() {
|
|||
try {
|
||||
spreadsheet.deleteSheet(sheetsToRemove[sheet]);
|
||||
} catch { // ran out of spreadsheets to nuke, so rename it to the first thing we need
|
||||
spreadsheet.getSheets()[0].setName("*Demographic Data")
|
||||
spreadsheet.getSheets()[0].setName(_demographic_data)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,21 +52,121 @@ function spread_init() {
|
|||
sheet.getCurrentCell().setValue('Ethnicity');
|
||||
sheet.getRange('F1').activate();
|
||||
sheet.getCurrentCell().setValue('Race');
|
||||
sheet.getRange('F2').activate();
|
||||
|
||||
var newSheet = spreadsheet.insertSheet();
|
||||
newSheet.setName("*Site Information")
|
||||
newSheet.setName(_site_information)
|
||||
newSheet.getRange('A1').activate();
|
||||
newSheet.getCurrentCell().setValue('Site Name');
|
||||
newSheet.getRange('B1').activate();
|
||||
newSheet.getCurrentCell().setValue('Date');
|
||||
newSheet.getRange('C1').activate();
|
||||
newSheet.getCurrentCell().setValue('Time');
|
||||
newSheet.getRange('D1').activate();
|
||||
newSheet.getCurrentCell().setValue('Those Present');
|
||||
newSheet.getRange('E1').activate();
|
||||
newSheet.getRange('D1').activate();
|
||||
newSheet.getCurrentCell().setValue('Data Leads');
|
||||
newSheet.getRange('F1').activate();
|
||||
newSheet.getRange('E1').activate();
|
||||
newSheet.getCurrentCell().setValue('Who Collected?');
|
||||
newSheet.getRange('F2').activate();
|
||||
|
||||
newSheet = spreadsheet.insertSheet();
|
||||
newSheet.setName(_intern_data)
|
||||
newSheet.getRange('A1').activate();
|
||||
newSheet.getCurrentCell().setValue('First Name');
|
||||
newSheet.getRange('B1').activate();
|
||||
newSheet.getCurrentCell().setValue('Last Name');
|
||||
newSheet.getRange('C1').activate();
|
||||
newSheet.getCurrentCell().setValue('Gender');
|
||||
newSheet.getRange('D1').activate();
|
||||
newSheet.getCurrentCell().setValue('Ethnicity');
|
||||
newSheet.getRange('E1').activate();
|
||||
newSheet.getCurrentCell().setValue('Race');
|
||||
}
|
||||
|
||||
function get_titled_spreadsheet_contents(sheet_name) {
|
||||
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name);
|
||||
var rows = spreadsheet.getDataRange().getValues();
|
||||
rows.shift(); /* remove the column headers from the data */
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
/*
|
||||
* @param {string} site_name
|
||||
*/
|
||||
function get_demographic_records_for_site(site_name) {
|
||||
var rows = get_titled_spreadsheet_contents(_demographic_data);
|
||||
var output = [];
|
||||
|
||||
for(row of rows) {
|
||||
if(row[0] === site_name) {
|
||||
output = output.concat(Array([1]).fill({
|
||||
"site_name": row[0],
|
||||
"age": row[2],
|
||||
"gender": row[3],
|
||||
"ethnicity": row[4],
|
||||
"race": row[4],
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function get_sites() {
|
||||
var rows = get_titled_spreadsheet_contents(_site_information);
|
||||
var output = [];
|
||||
|
||||
for(row of rows) {
|
||||
output.push({
|
||||
"site_name": row[0],
|
||||
"date": row[1],
|
||||
"present": row[2],
|
||||
"data_leads": row[3],
|
||||
"compiled_by": row[4],
|
||||
"attached_records": [],
|
||||
})
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function get_intern_data() {
|
||||
var rows = get_titled_spreadsheet_contents(_intern_data);
|
||||
var output = {};
|
||||
|
||||
for(row of rows) {
|
||||
var no_last_name = row[1] === "";
|
||||
/* if there's no last name, then just use the first name
|
||||
* as the key */
|
||||
var key = row[0].concat(no_last_name ? "" : " ".concat(row[1]))
|
||||
output[key] = {
|
||||
"first_name": row[0],
|
||||
"last_name": row[1],
|
||||
"calculated_name": key,
|
||||
"age": "Intern",
|
||||
"gender": row[2],
|
||||
"ethnicity": row[3],
|
||||
"race": row[4],
|
||||
};
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function collate_data() {
|
||||
var sites = get_sites();
|
||||
var intern_data = get_intern_data();
|
||||
|
||||
for(site of sites) {
|
||||
var name = site["site_name"];
|
||||
var data = get_demographic_records_for_site(name);
|
||||
|
||||
site["attached_records"].push(...data);
|
||||
var those_present = site["present"].split(',').map((x) => x.trim());
|
||||
|
||||
for(person of those_present) {
|
||||
site["attached_records"].push(
|
||||
intern_data[person]
|
||||
)
|
||||
}
|
||||
var data_leads = site["data_leads"].split(',').map((x) => x.trim());
|
||||
}
|
||||
}
|
22
macros.gs
22
macros.gs
|
@ -1,22 +0,0 @@
|
|||
function UntitledMacro() {
|
||||
var spreadsheet = SpreadsheetApp.getActive();
|
||||
spreadsheet.getRange('A1:F1').activate();
|
||||
spreadsheet.getRange('A1:F1').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
|
||||
};
|
||||
|
||||
function UntitledMacro2() {
|
||||
var spreadsheet = SpreadsheetApp.getActive();
|
||||
spreadsheet.getRange('A1').activate();
|
||||
spreadsheet.getCurrentCell().setValue('Site Name');
|
||||
spreadsheet.getRange('B1').activate();
|
||||
spreadsheet.getCurrentCell().setValue('Count');
|
||||
spreadsheet.getRange('C1').activate();
|
||||
spreadsheet.getCurrentCell().setValue('Age');
|
||||
spreadsheet.getRange('D1').activate();
|
||||
spreadsheet.getCurrentCell().setValue('Gender');
|
||||
spreadsheet.getRange('E1').activate();
|
||||
spreadsheet.getCurrentCell().setValue('Ethnicity');
|
||||
spreadsheet.getRange('F1').activate();
|
||||
spreadsheet.getCurrentCell().setValue('Race');
|
||||
spreadsheet.getRange('F2').activate();
|
||||
};
|
53
parsing.gs
53
parsing.gs
|
@ -1,53 +0,0 @@
|
|||
/* 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"
|
||||
]))
|
||||
}
|
Loading…
Reference in New Issue