Class: Aidp::PromptOptimization::OptimizerStats
- Inherits:
-
Object
- Object
- Aidp::PromptOptimization::OptimizerStats
- Defined in:
- lib/aidp/prompt_optimization/optimizer.rb
Overview
Statistics tracker for optimizer
Tracks metrics across optimization runs for monitoring and debugging prompt optimization performance
Instance Attribute Summary collapse
-
#runs_count ⇒ Object
readonly
Returns the value of attribute runs_count.
-
#total_fragments_excluded ⇒ Object
readonly
Returns the value of attribute total_fragments_excluded.
-
#total_fragments_indexed ⇒ Object
readonly
Returns the value of attribute total_fragments_indexed.
-
#total_fragments_scored ⇒ Object
readonly
Returns the value of attribute total_fragments_scored.
-
#total_fragments_selected ⇒ Object
readonly
Returns the value of attribute total_fragments_selected.
-
#total_optimization_time ⇒ Object
readonly
Returns the value of attribute total_optimization_time.
-
#total_tokens_used ⇒ Object
readonly
Returns the value of attribute total_tokens_used.
Instance Method Summary collapse
-
#average_budget_utilization ⇒ Object
Get average budget utilization.
-
#average_fragments_selected ⇒ Object
Get average fragments selected per run.
-
#average_optimization_time ⇒ Object
Get average optimization time.
-
#initialize ⇒ OptimizerStats
constructor
A new instance of OptimizerStats.
-
#record_budget_utilization(utilization) ⇒ Object
Record budget utilization.
-
#record_fragments_excluded(count) ⇒ Object
Record fragments excluded.
-
#record_fragments_indexed(count) ⇒ Object
Record fragments indexed.
-
#record_fragments_scored(count) ⇒ Object
Record fragments scored.
-
#record_fragments_selected(count) ⇒ Object
Record fragments selected.
-
#record_optimization_time(seconds) ⇒ Object
Record optimization time.
-
#record_tokens_used(tokens) ⇒ Object
Record tokens used.
-
#reset! ⇒ Object
Reset all statistics.
-
#summary ⇒ Hash
Get summary statistics.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ OptimizerStats
Returns a new instance of OptimizerStats.
239 240 241 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 239 def initialize reset! end |
Instance Attribute Details
#runs_count ⇒ Object (readonly)
Returns the value of attribute runs_count.
231 232 233 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 231 def runs_count @runs_count end |
#total_fragments_excluded ⇒ Object (readonly)
Returns the value of attribute total_fragments_excluded.
231 232 233 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 231 def total_fragments_excluded @total_fragments_excluded end |
#total_fragments_indexed ⇒ Object (readonly)
Returns the value of attribute total_fragments_indexed.
231 232 233 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 231 def total_fragments_indexed @total_fragments_indexed end |
#total_fragments_scored ⇒ Object (readonly)
Returns the value of attribute total_fragments_scored.
231 232 233 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 231 def total_fragments_scored @total_fragments_scored end |
#total_fragments_selected ⇒ Object (readonly)
Returns the value of attribute total_fragments_selected.
231 232 233 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 231 def total_fragments_selected @total_fragments_selected end |
#total_optimization_time ⇒ Object (readonly)
Returns the value of attribute total_optimization_time.
231 232 233 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 231 def total_optimization_time @total_optimization_time end |
#total_tokens_used ⇒ Object (readonly)
Returns the value of attribute total_tokens_used.
231 232 233 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 231 def total_tokens_used @total_tokens_used end |
Instance Method Details
#average_budget_utilization ⇒ Object
Get average budget utilization
292 293 294 295 296 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 292 def average_budget_utilization return 0.0 if @budget_utilizations.empty? (@budget_utilizations.sum / @budget_utilizations.count.to_f).round(2) end |
#average_fragments_selected ⇒ Object
Get average fragments selected per run
306 307 308 309 310 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 306 def average_fragments_selected return 0.0 if @runs_count.zero? (@total_fragments_selected.to_f / @runs_count).round(2) end |
#average_optimization_time ⇒ Object
Get average optimization time
299 300 301 302 303 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 299 def average_optimization_time return 0.0 if @runs_count.zero? (@total_optimization_time / @runs_count).round(4) end |
#record_budget_utilization(utilization) ⇒ Object
Record budget utilization
282 283 284 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 282 def record_budget_utilization(utilization) @budget_utilizations << utilization end |
#record_fragments_excluded(count) ⇒ Object
Record fragments excluded
272 273 274 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 272 def record_fragments_excluded(count) @total_fragments_excluded += count end |
#record_fragments_indexed(count) ⇒ Object
Record fragments indexed
256 257 258 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 256 def record_fragments_indexed(count) @total_fragments_indexed += count end |
#record_fragments_scored(count) ⇒ Object
Record fragments scored
261 262 263 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 261 def record_fragments_scored(count) @total_fragments_scored += count end |
#record_fragments_selected(count) ⇒ Object
Record fragments selected
266 267 268 269 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 266 def record_fragments_selected(count) @total_fragments_selected += count @runs_count += 1 end |
#record_optimization_time(seconds) ⇒ Object
Record optimization time
287 288 289 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 287 def record_optimization_time(seconds) @total_optimization_time += seconds end |
#record_tokens_used(tokens) ⇒ Object
Record tokens used
277 278 279 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 277 def record_tokens_used(tokens) @total_tokens_used += tokens end |
#reset! ⇒ Object
Reset all statistics
244 245 246 247 248 249 250 251 252 253 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 244 def reset! @runs_count = 0 @total_fragments_indexed = 0 @total_fragments_scored = 0 @total_fragments_selected = 0 @total_fragments_excluded = 0 @total_tokens_used = 0 @total_optimization_time = 0.0 @budget_utilizations = [] end |
#summary ⇒ Hash
Get summary statistics
315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 315 def summary { runs_count: @runs_count, total_fragments_indexed: @total_fragments_indexed, total_fragments_scored: @total_fragments_scored, total_fragments_selected: @total_fragments_selected, total_fragments_excluded: @total_fragments_excluded, total_tokens_used: @total_tokens_used, average_fragments_selected: average_fragments_selected, average_budget_utilization: average_budget_utilization, average_optimization_time_ms: (average_optimization_time * 1000).round(2) } end |
#to_s ⇒ Object
329 330 331 332 |
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 329 def to_s avg_time_ms = (average_optimization_time * 1000).round(2) "OptimizerStats<#{@runs_count} runs, #{average_fragments_selected} avg fragments, #{avg_time_ms}ms avg time>" end |