import { ExamFact, ExamDim, QuestionStat } from "."; import { mean, min, max, stdDev } from "@rolesvillesoftware/tools/dist"; export class ExamStat { id: number; examDimId: number; questions: number; mean: number; minScore: number; maxScore: number; scoreRange: number; standardDev: number; aav: number; kr20: number; sumOfPq: number; krv: number; students: ExamFact[]; private calculateSumOfPq(questions: QuestionStat[]) { let sum = 0; questions.map(item => item.pq).forEach(item => sum += item); return sum; } private calculateKr20() { const N = 100 / this.questions; const K = this.questions; return (N * (K / (K - 1)) * (1 - (this.sumOfPq / (this.standardDev * this.standardDev)))) / (1 + (N - 1) * ((K / (K - 1)) * (1 - (this.sumOfPq / (this.standardDev * this.standardDev))))); } populate(exam: ExamDim, students: ExamFact[]) { this.students = students; this.examDimId = exam.id; this.mean = mean(students, "percentCorrect"); this.minScore = min(students, "percentCorrect"); this.maxScore = max(students, "percentCorrect"); this.scoreRange = Math.abs(this.maxScore - this.minScore); this.standardDev = stdDev(students, "percentCorrect"); this.aav = 1; } complete(questionStats: QuestionStat[]) { this.questions = questionStats.length; this.sumOfPq = this.calculateSumOfPq(questionStats); this.kr20 = this.calculateKr20(); this.krv = Math.pow(this.kr20, 4) * 10; } }