/** * TPU Survey - Standalone Statistics Logic */ function renderStatsQuestions(questions) { let html = ''; const ratingQuestions = questions.filter(q => q.question_type === 'radio' && q.mean !== undefined); const categoricalQuestions = questions.filter(q => (q.question_type === 'dropdown' || q.question_type === 'checkbox' || (q.question_type === 'radio' && q.mean === undefined)) && q.frequencies && q.frequencies.length > 0 ); if (categoricalQuestions.length > 0) { categoricalQuestions.forEach(q => { const cleanText = q.question_text.replace(/^\s*[\d๑-๙]+[\.\)\s-:]*\s*/, ''); html += `
${escapeHtml(cleanText)}
| ตัวเลือก | จำนวน | ร้อยละ |
|---|---|---|
| ${escapeHtml(String(f.value))} | ${f.count} | ${f.percentage}% |
| รายการประเมิน | 5 | 4 | 3 | 2 | 1 | X̄ | S.D. | แปลผล |
|---|---|---|---|---|---|---|---|---|
| ${escapeHtml(cleanText)} | `; for (let i = 4; i >= 0; i--) { const freq = q.frequencies?.[i] || { count: 0 }; html += `${freq.count} | `; } html += `${q.mean?.toFixed(2) || '-'} | `; html += `${q.sd?.toFixed(2) || '-'} | `; html += `${q.interpretation || '-'} | `; html += `||||
| รวมเฉลี่ย | `; html += ` | ${avgMean.toFixed(2)} | ${avgSD.toFixed(2)} | `; html += `${avgInterp} | ||||
${escapeHtml(cleanText)}
`; if (q.text_responses && q.text_responses.length > 0) { q.text_responses.forEach((t, i) => { html += `(ไม่มีข้อคิดเห็น)
`; } html += `${err.message}
วันเวลาที่ส่ง: ${new Date(r.submitted_at).toLocaleString('th-TH')}
IP Address: ${r.ip_address}