FormStat v3.0

Mobile statistics for Google Forms research.

By Abdul Hannan
'; h += '
📄 In the print dialog, choose Save as PDF as the destination / printer, then tap Save to download your analyzed report.
'; h += '

FormStat Analysis Report

'; h += '

Generated ' + new Date().toLocaleString() + '  •  Responses: ' + DS.rows.length + '  •  Questions: ' + DS.headers.length + (withCharts ? '  •  With charts' : '  •  Tables only') + '

'; DS.headers.forEach(function (qh, i) { var vals = S.columnValues(DS.rows, i); if (S.isNumericColumn(vals)) { var d = S.descriptives(vals); h += '

' + esc(qh) + ' (numeric)

n = ' + d.n + '

'; h += '
MeanSDMedianMinMax
' + fmt(d.mean, 2) + '' + fmt(d.sd, 2) + '' + fmt(d.median, 2) + '' + fmt(d.min, 2) + '' + fmt(d.max, 2) + '
'; if (withCharts) h += '
' + histogramSVG(vals) + '
'; } else if (isMultiResp(vals)) { var mr = S.multiResponse(vals); h += '

' + esc(qh) + ' (multiple response)

'; h += '

Answered by ' + mr.nCases + ' respondents • ' + mr.nResponses + ' total selections

'; h += ''; mr.options.forEach(function (o) { h += ''; }); h += '
OptionSelected by% of responses% of cases
' + esc(o.value) + '' + o.count + '' + fmt(o.pctResponses) + '' + fmt(o.pctCases) + '
'; if (withCharts) h += '
' + barSVG(mr.options.map(function (o) { return o.value; }), mr.options.map(function (o) { return o.count; })) + '
'; } else { var f = S.frequency(vals); h += '

' + esc(qh) + '

Valid: ' + f.valid + ' • Missing: ' + f.missing + '

'; h += ''; f.table.forEach(function (r) { h += ''; }); h += '
ValueFrequencyPercentValid PercentCumulative Percent
' + esc(r.value) + '' + r.count + '' + fmt(r.percent) + '' + fmt(r.validPercent) + '' + fmt(r.cumulativePercent) + '
'; if (withCharts) h += '
' + barSVG(f.table.map(function (r) { return r.value; }), f.table.map(function (r) { return r.count; })) + '
'; } }); var keys = ['twoGroup', 'multiGroup', 'paired', 'corr', 'chisq', 'multiResp', 'oaAnova']; if (keys.some(function (k) { return LAST[k]; })) { h += '

Comparisons & tests

'; keys.forEach(function (k) { if (LAST[k]) { var comp = LAST[k]; if (!withCharts) comp = comp.replace(/
[\s\S]*?<\/svg><\/div>/g, ''); h += comp; } }); } h += '

Analyzed with FormStat • By Abdul Hannan

'; h += '
'; return h; } function openPdfReport(withCharts) { var w = window.open('', '_blank'); if (!w) { alert('Please allow pop-ups for this page, then try again.'); return; } w.document.write(buildPdfReport(withCharts)); w.document.close(); setTimeout(function () { try { w.print(); } catch (e) {} }, 500); } el('btnPdfCharts').addEventListener('click', function () { openPdfReport(true); }); el('btnPdfTables').addEventListener('click', function () { openPdfReport(false); }); /* ---------------- report ---------------- */ el('btnReport').addEventListener('click', function () { var h = 'FormStat Report '; h += '

FormStat Report

Generated ' + new Date().toLocaleString() + ' • Responses: ' + DS.rows.length + ' • Questions: ' + DS.headers.length + '

'; h += '

Frequency tables

'; DS.headers.forEach(function (qh, i) { var vals = S.columnValues(DS.rows, i); if (S.isNumericColumn(vals)) { var d = S.descriptives(vals); h += '

' + esc(qh) + ' (numeric)

n = ' + d.n + '

MeanSDMedianMinMax
' + fmt(d.mean, 2) + '' + fmt(d.sd, 2) + '' + fmt(d.median, 2) + '' + fmt(d.min, 2) + '' + fmt(d.max, 2) + '
'; } else { var f = S.frequency(vals); h += '

' + esc(qh) + '

Valid: ' + f.valid + ' • Missing: ' + f.missing + '

'; h += ''; f.table.forEach(function (r) { h += ''; }); h += '
ValueFrequencyPercentValid PercentCumulative Percent
' + esc(r.value) + '' + r.count + '' + fmt(r.percent) + '' + fmt(r.validPercent) + '' + fmt(r.cumulativePercent) + '
'; } }); var keys = ['twoGroup', 'multiGroup', 'paired', 'corr', 'chisq', 'multiResp', 'oaAnova']; var anyComp = keys.some(function (k) { return LAST[k]; }); if (anyComp) { h += '

Comparisons & tests

'; keys.forEach(function (k) { if (LAST[k]) h += LAST[k]; }); } h += ''; var blob = new Blob([h], { type: 'text/html' }); var a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'formstat-report.html'; document.body.appendChild(a); a.click(); setTimeout(function () { URL.revokeObjectURL(a.href); a.remove(); }, 500); }); el('btnCopyAll').addEventListener('click', function () { var parts = []; DS.headers.forEach(function (qh, i) { var vals = S.columnValues(DS.rows, i); if (S.isNumericColumn(vals)) { var d = S.descriptives(vals); parts.push(qh + ' (n=' + d.n + ')\n' + tsvTable(['Mean', 'SD', 'Median', 'Min', 'Max'], [[fmt(d.mean, 2), fmt(d.sd, 2), fmt(d.median, 2), fmt(d.min, 2), fmt(d.max, 2)]])); } else { var f = S.frequency(vals); parts.push(qh + ' (n=' + f.valid + ', missing=' + f.missing + ')\n' + tsvTable(['Value', 'Frequency', 'Percent', 'Valid Percent', 'Cumulative Percent'], f.table.map(function (r) { return [r.value, r.count, fmt(r.percent), fmt(r.validPercent), fmt(r.cumulativePercent)]; }))); } }); copyText(parts.join('\n\n'), 'All tables copied — paste into Excel.'); }); /* ---------------- home menu navigation ---------------- */ function showView(name) { ['homeMenu', 'viewAnalyze', 'viewSS', 'viewRec'].forEach(function (id) { el(id).style.display = (id === name) ? '' : 'none'; }); if (window.scrollTo) window.scrollTo(0, 0); } el('menuAnalyze').addEventListener('click', function () { showView('viewAnalyze'); }); el('menuSS').addEventListener('click', function () { showView('viewSS'); }); el('menuRec').addEventListener('click', function () { showView('viewRec'); }); el('btnBackA').addEventListener('click', function () { showView('homeMenu'); }); el('btnBackS').addEventListener('click', function () { showView('homeMenu'); }); el('btnBackR').addEventListener('click', function () { showView('homeMenu'); }); // test hook (harmless in production) if (typeof window !== 'undefined') window.FormStatTest = { load: setData, state: DS, last: LAST, pdf: buildPdfReport, dvSet: dvSetCell, openDV: openDataView, closeDV: closeDataView, parseExcel: parseExcelFile, oaAdd: oaAddRow, oaInputs: oaInputs, oaReset: oaResetGrid }; })();