go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/kana-server/pkg/types/quiz_stats.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package types
     9  
    10  import "time"
    11  
    12  // QuizStats hold statistics for a quiz.
    13  type QuizStats struct {
    14  	Total          int
    15  	Correct        int
    16  	ElapsedAverage time.Duration
    17  	ElapsedMin     time.Duration
    18  	ElapsedMax     time.Duration
    19  	ElapsedP75     time.Duration
    20  	ElapsedP90     time.Duration
    21  	ElapsedP95     time.Duration
    22  }
    23  
    24  // PercentCorrect returns the percentage correct.
    25  func (qs QuizStats) PercentCorrect() float64 {
    26  	if qs.Total == 0 {
    27  		return 0.0
    28  	}
    29  	return (float64(qs.Correct) / float64(qs.Total)) * 100
    30  }