/
potogon
/
statbit
Обзор
Документация
Войти
/
potogon
/
statbit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
forGoogle/code.js
205 строк
8 KB
Alex
add phys test
28 июл 2026, 20:21
28 июл 2026, 20:21
3d38ab2
Код
Авторство
О чём код?
// ============ НАСТРОЙКИ ============ const SHEET_ID = ''; const DOCTOR_PASSWORD = ''; // ============ ОБРАБОТЧИКИ ============ function doGet(e) { const action = e.parameter.action; let result; try { if (action === 'getResults') { const password = e.parameter.password; const testFilter = e.parameter.test || 'all'; // 'all' | 'beck' | 'coping' if (password !== DOCTOR_PASSWORD) { result = { ok: false, error: 'Неверный пароль' }; } else { result = { ok: true, data: getAllResults(testFilter) }; } } else { result = { ok: false, error: 'Неизвестное действие' }; } } catch (err) { result = { ok: false, error: String(err) }; } return ContentService .createTextOutput(JSON.stringify(result)) .setMimeType(ContentService.MimeType.JSON); } function doPost(e) { let result; try { const data = JSON.parse(e.postData.contents); if (data.action === 'saveResult') { const p = data.payload; if (p.testName === 'Опросник депрессии Бека') { saveBeckResult(p); } else if (p.testName === 'Копинг-тест') { saveCopingResult(p); } else if (p.testName === 'Тест физической активности') { savePhysicalResult(p); } else { throw new Error('Неизвестный тип теста'); } result = { ok: true }; } else { result = { ok: false, error: 'Неизвестное действие' }; } } catch (err) { result = { ok: false, error: String(err) }; } return ContentService .createTextOutput(JSON.stringify(result)) .setMimeType(ContentService.MimeType.JSON); } // ============ ЛИСТЫ ============ function getBeckSheet() { const ss = SpreadsheetApp.openById(SHEET_ID); let sh = ss.getSheetByName('Опросник Бека'); if (!sh) { sh = ss.insertSheet('Опросник Бека'); const headers = [ 'Дата и время', 'ФИО', 'Возраст', 'Пол', 'Группа 1', 'Группа 2', 'Группа 3', 'Группа 4', 'Группа 5', 'Группа 6', 'Группа 7', 'Группа 8', 'Группа 9', 'Группа 10', 'Группа 11', 'Группа 12', 'Группа 13', 'Группа 14', 'Группа 15', 'Группа 16', 'Группа 17', 'Группа 18', 'Группа 19', 'Группа 20', 'Группа 21', 'Доп. вопрос 19 (похудение)', 'Итого баллов', 'Тест' ]; sh.appendRow(headers); sh.getRange(1, 1, 1, headers.length).setFontWeight('bold').setBackground('#f0f0f0'); sh.setFrozenRows(1); } return sh; } function getCopingSheet() { const ss = SpreadsheetApp.openById(SHEET_ID); let sh = ss.getSheetByName('Копинг-тест'); if (!sh) { sh = ss.insertSheet('Копинг-тест'); const headers = [ 'Дата и время', 'ФИО', 'Возраст', 'Пол', // 50 вопросов ...Array.from({ length: 50 }, (_, i) => `Вопрос ${i + 1}`), // 8 шкал 'Конфронтативный', 'Дистанцирование', 'Самоконтроль', 'Поиск соц. поддержки', 'Принятие ответственности', 'Бегство-избегание', 'Планирование', 'Положительная переоценка', 'Тест' ]; sh.appendRow(headers); sh.getRange(1, 1, 1, headers.length).setFontWeight('bold').setBackground('#f0f0f0'); sh.setFrozenRows(1); } return sh; } function getPhysicalSheet() { const ss = SpreadsheetApp.openById(SHEET_ID); let sh = ss.getSheetByName('Тест физической активности'); if (!sh) { sh = ss.insertSheet('Тест физической активности'); const headers = [ 'Дата и время', 'ФИО', 'Возраст', 'Пол', 'Q1_НеЗнаю', 'Q1_Дней', 'Q2_НеЗнаю', 'Q2_Часов', 'Q2_Минут', 'Q3_НеЗнаю', 'Q3_Часов', 'Q3_Минут', 'Q4_НеЗнаю', 'Q4_Дней', 'Q5_НеЗнаю', 'Q5_Часов', 'Q5_Минут', 'Q6_НеЗнаю', 'Q6_Часов', 'Q6_Минут', 'Q7_НеЗнаю', 'Q7_Дней', 'Q8_НеЗнаю', 'Q8_Часов', 'Q8_Минут', 'Q9_НеЗнаю', 'Q9_Часов', 'Q9_Минут', 'Q10_НеЗнаю', 'Q10_Часов', 'Q10_Минут', 'Q11_НеЗнаю', 'Q11_Часов', 'Q11_Минут', 'Тест' ]; sh.appendRow(headers); sh.getRange(1, 1, 1, headers.length).setFontWeight('bold').setBackground('#f0f0f0'); sh.setFrozenRows(1); } return sh; } // ============ СОХРАНЕНИЕ ============ function saveBeckResult(p) { const sh = getBeckSheet(); const row = [ new Date(), p.fio || '', p.age || '', p.gender || '', ...p.answers, // 21 значение p.extraQ19 || '', p.totalScore, 'Опросник депрессии Бека' ]; sh.appendRow(row); } function saveCopingResult(p) { const sh = getCopingSheet(); const row = [ new Date(), p.fio || '', p.age || '', p.gender || '', ...p.answers, // 50 значений p.scales['Конфронтативный'], p.scales['Дистанцирование'], p.scales['Самоконтроль'], p.scales['Поиск соц. поддержки'], p.scales['Принятие ответственности'], p.scales['Бегство-избегание'], p.scales['Планирование'], p.scales['Положительная переоценка'], 'Копинг-тест' ]; sh.appendRow(row); } function savePhysicalResult(p) { const sh = getPhysicalSheet(); const a = p.answers; const row = [ new Date(), p.fio || '', p.age || '', p.gender || '', a.q1.dontKnow ? 'Да' : 'Нет', a.q1.days || '', a.q2.dontKnow ? 'Да' : 'Нет', a.q2.hours || '', a.q2.minutes || '', a.q3.dontKnow ? 'Да' : 'Нет', a.q3.hours || '', a.q3.minutes || '', a.q4.dontKnow ? 'Да' : 'Нет', a.q4.days || '', a.q5.dontKnow ? 'Да' : 'Нет', a.q5.hours || '', a.q5.minutes || '', a.q6.dontKnow ? 'Да' : 'Нет', a.q6.hours || '', a.q6.minutes || '', a.q7.dontKnow ? 'Да' : 'Нет', a.q7.days || '', a.q8.dontKnow ? 'Да' : 'Нет', a.q8.hours || '', a.q8.minutes || '', a.q9.dontKnow ? 'Да' : 'Нет', a.q9.hours || '', a.q9.minutes || '', a.q10.dontKnow ? 'Да' : 'Нет', a.q10.hours || '', a.q10.minutes || '', a.q11.dontKnow ? 'Да' : 'Нет', a.q11.hours || '', a.q11.minutes || '', 'Тест физической активности' ]; sh.appendRow(row); } // ============ ЧТЕНИЕ ============ function getAllResults(filter) { const ss = SpreadsheetApp.openById(SHEET_ID); const results = []; const sheetNames = []; if (filter === 'all' || filter === 'beck') sheetNames.push('Опросник Бека'); if (filter === 'all' || filter === 'coping') sheetNames.push('Копинг-тест'); if (filter === 'all' || filter === 'physical') sheetNames.push('Тест физической активности'); sheetNames.forEach(name => { const sh = ss.getSheetByName(name); if (!sh) return; const data = sh.getDataRange().getValues(); if (data.length <= 1) return; const headers = data[0]; data.slice(1).forEach(row => { const obj = { _sheet: name }; headers.forEach((h, i) => { obj[h] = row[i]; }); results.push(obj); }); }); return results; }