go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/kana-server/pkg/types/prompt_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  // PromptStats hold statistics for a prompt.
    13  type PromptStats struct {
    14  	Prompt         string
    15  	Weight         float64
    16  	Total          int
    17  	Correct        int
    18  	ElapsedAverage time.Duration
    19  	ElapsedMin     time.Duration
    20  	ElapsedMax     time.Duration
    21  	ElapsedP75     time.Duration
    22  	ElapsedP90     time.Duration
    23  	ElapsedP95     time.Duration
    24  	ElapsedTimes   []time.Duration
    25  }
    26  
    27  // PercentCorrect returns the percentage correct.
    28  func (ps PromptStats) PercentCorrect() float64 {
    29  	if ps.Total == 0 {
    30  		return 0.0
    31  	}
    32  	return (float64(ps.Correct) / float64(ps.Total)) * 100.0
    33  }