Calc NPS score

This commit is contained in:
Marcus Kammer 2025-01-01 17:31:55 +01:00
parent 2e6a9cbf2a
commit 35df30bce6
Signed by: marcuskammer
GPG key ID: C374817BE285268F
2 changed files with 29 additions and 6 deletions

View file

@ -15,4 +15,5 @@
(:file "calculator")
(:file "displayer")
(:file "sus")
(:file "visawi")))))))
(:file "visawi")
(:file "nps")))))))

View file

@ -1,28 +1,50 @@
;;; -*- mode: lisp; coding: utf-8; comment-column 79; -*-
;;; -*- mode: lisp; coding: utf-8; -*-
(in-package :ml-qmetrics/assessment)
(defun nps-calc-score (promoters detractors total)
"Calculate the Net Promoter Score (NPS)."
(* (/ (- promoters detractors) total) 100))
(defun nps-enumerate (data)
(check-type data list)
(if data
(let ((clean-data (remove-if (lambda (x) (or (> x 10) (< x 0))) data)))
(loop for score in clean-data
counting (>= score 9) into promoters
counting (<= score 6) into detractors
finally (return (list promoters detractors (length clean-data)))))
(error "Empty DATA list.")))
;;;
;;; CALCULATOR
;;;
(defclass nps-calculator (calculator) ())
(defmethod calculator-calc-results ((calc nps-calculator) responses))
(defmethod calculator-calc-results ((calc nps-calculator) responses)
(let ((values (mapcar #'parse-integer (mapcar #'cdadr responses))))
(apply #'nps-calc-score (nps-enumerate values))))
(defmethod calculator-calc-group-stats ((calc nps-calculator) results)
nil)
;;;
;;; DISPLAYER
;;;
(defclass nps-displayer (displayer))
(defclass nps-displayer (displayer) ())
(defmethod displayer-generate-html ((disp nps-displayer) results &optional group-stats survey-id))
(defmethod displayer-generate-html ((disp nps-displayer) results &optional group-stats survey-id)
(with-section
(with-title-bar (format nil "~A" (displayer-name disp)))
(format nil "~A" results)))
;;;
;;; ASSESSMENT
;;;
(defclass nps-assessment (assessment))
(defclass nps-assessment (assessment) ())
(defmethod initialize-instance :after ((a nps-assessment) &key)
(setf (assessment-calculator a) (make-instance 'nps-calculator)