Split results html into functions

This commit is contained in:
Marcus Kammer 2024-07-10 23:01:40 +02:00
parent 2bc287f3b7
commit 6fd418e738
Signed by: marcuskammer
GPG key ID: C374817BE285268F
2 changed files with 33 additions and 26 deletions

View file

@ -2,7 +2,7 @@
(defsystem "dev.metalisp.survey" (defsystem "dev.metalisp.survey"
:description "A simple survey" :description "A simple survey"
:version "0.2.3" :version "0.2.4"
:author "Marcus Kammer <marcus.kammer@metalisp.dev>" :author "Marcus Kammer <marcus.kammer@metalisp.dev>"
:source-control "git@git.sr.ht:~marcuskammer/dev.metalisp.survey" :source-control "git@git.sr.ht:~marcuskammer/dev.metalisp.survey"
:licence "MIT" :licence "MIT"

View file

@ -80,6 +80,36 @@
(loop for i from 0 by 3 while (< i (length lst)) (loop for i from 0 by 3 while (< i (length lst))
collect (subseq lst i (min (+ i 3) (length lst))))) collect (subseq lst i (min (+ i 3) (length lst)))))
(defun sus-results-html (count-answers sus-results)
(spinneret:with-html
(:h3 :class "py-1" "SUS")
(:table :class "table table-hover"
(:caption "Questionnaire results table")
(:thead
(:tr
(:th :scope "col" "Time")
(loop for header from 1 below count-answers
do (:th :scope "col" (format nil "Q ~a" header)))
(:th :scope "col" "SUS Score")))
(:tbody
(loop for row in sus-results
do (:tr (mapcar (lambda (data) (:td data)) row)))))))
(defun results-html (results)
(loop for (type data) on results by #'cddr unless (eq type :sus)
do (spinneret:with-html (:h3 :class "py-1" (format nil "~a" type))
(:div :class "container"
(loop for row in (group-in-chunks data)
do (:div :class "row"
(loop for col in row
do (:ul :class "col-4 list-group py-3"
(loop for entry in col
for i from 0
do (:li :class (if (zerop i)
"list-group-item active"
"list-group-item")
entry))))))))))
(defun view (survey &optional results) (defun view (survey &optional results)
"Generates the view to show the survey created." "Generates the view to show the survey created."
(check-type survey survey) (check-type survey survey)
@ -99,32 +129,9 @@
(if sus-results (if sus-results
(let ((count-answers (length (cdr (car sus-results))))) (let ((count-answers (length (cdr (car sus-results)))))
(:h3 :class "py-1" "SUS") (sus-results-html count-answers sus-results)))
(:table :class "table table-hover"
(:caption "Questionnaire results table")
(:thead
(:tr
(:th :scope "col" "Time")
(loop for header from 1 below count-answers
do (:th :scope "col" (format nil "Q ~a" header)))
(:th :scope "col" "SUS Score")))
(:tbody
(loop for row in sus-results
do (:tr (mapcar (lambda (data) (:td data)) row)))))))
(loop for (type data) on results by #'cddr unless (eq type :sus) (results-html results))))))
do (progn (:h3 :class "py-1" (format nil "~a" type))
(:div :class "container"
(loop for row in (group-in-chunks data)
do (:div :class "row"
(loop for col in row
do (:ul :class "col-4 list-group py-3"
(loop for entry in col
for i from 0
do (:li :class (if (zerop i)
"list-group-item active"
"list-group-item")
entry))))))))))))))
(defun extract-numbers (results) (defun extract-numbers (results)
"Extract numbers from a questionnaire RESULTS list. "Extract numbers from a questionnaire RESULTS list.
Returns a list of integers." Returns a list of integers."