Class: Aidp::PromptOptimization::OptimizerStats

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeOptimizerStats

Returns a new instance of OptimizerStats.



250
251
252
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 250

def initialize
  reset!
end

Instance Attribute Details

#runs_countObject (readonly)

Returns the value of attribute runs_count.



242
243
244
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 242

def runs_count
  @runs_count
end

#total_fragments_excludedObject (readonly)

Returns the value of attribute total_fragments_excluded.



242
243
244
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 242

def total_fragments_excluded
  @total_fragments_excluded
end

#total_fragments_indexedObject (readonly)

Returns the value of attribute total_fragments_indexed.



242
243
244
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 242

def total_fragments_indexed
  @total_fragments_indexed
end

#total_fragments_scoredObject (readonly)

Returns the value of attribute total_fragments_scored.



242
243
244
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 242

def total_fragments_scored
  @total_fragments_scored
end

#total_fragments_selectedObject (readonly)

Returns the value of attribute total_fragments_selected.



242
243
244
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 242

def total_fragments_selected
  @total_fragments_selected
end

#total_optimization_timeObject (readonly)

Returns the value of attribute total_optimization_time.



242
243
244
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 242

def total_optimization_time
  @total_optimization_time
end

#total_tokens_usedObject (readonly)

Returns the value of attribute total_tokens_used.



242
243
244
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 242

def total_tokens_used
  @total_tokens_used
end

Instance Method Details

#average_budget_utilizationObject

Get average budget utilization



303
304
305
306
307
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 303

def average_budget_utilization
  return 0.0 if @budget_utilizations.empty?

  (@budget_utilizations.sum / @budget_utilizations.count.to_f).round(2)
end

#average_fragments_selectedObject

Get average fragments selected per run



317
318
319
320
321
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 317

def average_fragments_selected
  return 0.0 if @runs_count.zero?

  (@total_fragments_selected.to_f / @runs_count).round(2)
end

#average_optimization_timeObject

Get average optimization time



310
311
312
313
314
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 310

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



293
294
295
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 293

def record_budget_utilization(utilization)
  @budget_utilizations << utilization
end

#record_fragments_excluded(count) ⇒ Object

Record fragments excluded



283
284
285
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 283

def record_fragments_excluded(count)
  @total_fragments_excluded += count
end

#record_fragments_indexed(count) ⇒ Object

Record fragments indexed



267
268
269
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 267

def record_fragments_indexed(count)
  @total_fragments_indexed += count
end

#record_fragments_scored(count) ⇒ Object

Record fragments scored



272
273
274
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 272

def record_fragments_scored(count)
  @total_fragments_scored += count
end

#record_fragments_selected(count) ⇒ Object

Record fragments selected



277
278
279
280
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 277

def record_fragments_selected(count)
  @total_fragments_selected += count
  @runs_count += 1
end

#record_optimization_time(seconds) ⇒ Object

Record optimization time



298
299
300
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 298

def record_optimization_time(seconds)
  @total_optimization_time += seconds
end

#record_tokens_used(tokens) ⇒ Object

Record tokens used



288
289
290
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 288

def record_tokens_used(tokens)
  @total_tokens_used += tokens
end

#reset!Object

Reset all statistics



255
256
257
258
259
260
261
262
263
264
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 255

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

#summaryHash

Get summary statistics

Returns:

  • (Hash)

    Statistics summary



326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 326

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_sObject



340
341
342
343
# File 'lib/aidp/prompt_optimization/optimizer.rb', line 340

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