(function() {
'use strict';
var mininumCount = 6;
var readyToGetMap = false;
var belowMinReplacement = 'N<6';
var load_data = (function() {
var datacache = {}; // in closure
return function(config, callback) {
if (datacache.hasOwnProperty(config.data_url)) {
callback(datacache[config.data_url], config);
} else {
$.ajax({
url: config.data_url,
datatype: "json",
success: function(result) {
var json_object = (typeof result === 'string')
? JSON.parse(result)
: result;
datacache[config.data_url] = json_object;
callback(json_object, config);
}
});
}
};
}());
var process_prep = function (datax) {
let calculatePercentages = function (prepareSectionData) {
let enrollment = prepareSectionData.n_enrolled;
let allKeys = Object.keys(prepareSectionData);
let returnValue = {}
if (enrollment < mininumCount) {
allKeys.forEach(key => {
returnValue[key] = belowMinReplacement;
returnValue[key.replace('n_', 'p_')] = belowMinReplacement;
});
}
let targetKeys = allKeys.filter(key => key.startsWith('n_') && !key.includes('enrolled'));
// copy data
allKeys.forEach(key => returnValue[key] = prepareSectionData[key]);
// generate new data
targetKeys.forEach(key => returnValue[key.replace('n_', 'p_')] = Math.round(prepareSectionData[key] / enrollment * 100) + '%');
return returnValue;
};
// will contain two very long strings of html
let returnValue = [];
var years = Object.keys(datax.prepareDetail).sort();
var detailData = {};
for (let cohort of years) {
detailData[cohort] = calculatePercentages(datax.prepareDetail[cohort]);
}
var columnTotal = (years.length * 2) + 1;
// Heading rows
var totalEnrollmentHeading = `
Total Enrollment | `;
var fulfilledRequirementHeading = `Fulfilled GE Math/Quantitative Reasoning Requirement | `;
var placedInCourseHeading = `Placed in Math/Quantitative Reasoning Course | `;
// Label column (left table column)
var numRegularAdmitsLabel = '# Regular Admits | ';
var fulfilledReqLabel = ` Fulfilled req.
| `;
var inWithoutSILabel = 'In course, NO supported instruction | ';
var inWithSILabel = ' In course WITH supported instruction | ';
var inWithSI_ESPLabel = ' In course WITH supported instruction AND in the Early Start program | ';
// Empty Cell
var emptyCell = ' | ';
var headRows = [];
var bodyRows = [];
// build math table
headRows.push(totalEnrollmentHeading);
var rowHtml = '';
rowHtml += emptyCell;
years.forEach(cohort => {
rowHtml += `${cohort} | `;
});
bodyRows.push(rowHtml);
rowHtml = emptyCell;
years.forEach(cohort => {
rowHtml += `N | % | `;
});
bodyRows.push(rowHtml);
rowHtml = numRegularAdmitsLabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_enrolled} | - | `;
});
bodyRows.push(rowHtml);
bodyRows.push(fulfilledRequirementHeading);
rowHtml = fulfilledReqLabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_mpr1} | ${detailData[cohort].p_mpr1} | `;
});
bodyRows.push(rowHtml);
bodyRows.push(placedInCourseHeading);
rowHtml = inWithoutSILabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_mpr2} | ${detailData[cohort].p_mpr2} | `;
});
bodyRows.push(rowHtml);
rowHtml = inWithSILabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_mpr3} | ${detailData[cohort].p_mpr3} | `;
});
bodyRows.push(rowHtml);
rowHtml = inWithSI_ESPLabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_mpr4} | ${detailData[cohort].p_mpr4} | `;
});
bodyRows.push(rowHtml);
let mathHeadHtml = `${headRows.join('
')}
`;
let mathBodyHtml = `${bodyRows.join('
')}
`;
let mathTableHtml = `${mathHeadHtml}${mathBodyHtml}
`;
returnValue.push(mathTableHtml);
//build written comm table
headRows = []; // reset this
bodyRows = []; // reset this
headRows.push(totalEnrollmentHeading);
var rowHtml = '';
rowHtml += emptyCell;
years.forEach(cohort => {
rowHtml += `${cohort} | `;
});
bodyRows.push(rowHtml);
rowHtml = emptyCell;
years.forEach(cohort => {
rowHtml += `N | % | `;
});
bodyRows.push(rowHtml);
rowHtml = numRegularAdmitsLabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_enrolled} | - | `;
});
bodyRows.push(rowHtml);
bodyRows.push(fulfilledRequirementHeading);
rowHtml = fulfilledReqLabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_wc1} | ${detailData[cohort].p_wc1} | `;
});
bodyRows.push(rowHtml);
bodyRows.push(placedInCourseHeading);
rowHtml = inWithoutSILabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_wc2} | ${detailData[cohort].p_wc2} | `;
});
bodyRows.push(rowHtml);
rowHtml = inWithSILabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_wc3} | ${detailData[cohort].p_wc3} | `;
});
bodyRows.push(rowHtml);
rowHtml = inWithSI_ESPLabel;
years.forEach(cohort => {
rowHtml += `${detailData[cohort].n_wc4} | ${detailData[cohort].p_wc4} | `;
});
bodyRows.push(rowHtml);
let writtenHeadHtml = `${headRows.join('
')}
`;
let writtenBodyHtml = `${bodyRows.join('
')}
`;
let writtenTableHtml = `${writtenHeadHtml}${writtenBodyHtml}
`;
returnValue.push(writtenTableHtml);
// return array of html strings [