Class: SkillBench::TrendTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/skill_bench/trend_tracker.rb,
lib/skill_bench/trend_tracker/persistence.rb,
lib/skill_bench/trend_tracker/trend_calculator.rb

Overview

Tracks evaluation results over time and computes trend deltas.

Defined Under Namespace

Classes: Persistence, TrendCalculator

Constant Summary collapse

DEFAULT_HISTORY_FILE =
'.skill-bench-trends.json'

Instance Method Summary collapse

Constructor Details

#initialize(history_file: DEFAULT_HISTORY_FILE) ⇒ TrendTracker

Returns a new instance of TrendTracker.

Parameters:

  • history_file (String) (defaults to: DEFAULT_HISTORY_FILE)

    Path to the history JSON file.



13
14
15
# File 'lib/skill_bench/trend_tracker.rb', line 13

def initialize(history_file: DEFAULT_HISTORY_FILE)
  @persistence = Persistence.new(history_file)
end

Instance Method Details

#historyArray<Hash>

Loads the full history.

Returns:

  • (Array<Hash>)

    List of historical entries.



37
38
39
# File 'lib/skill_bench/trend_tracker.rb', line 37

def history
  @persistence.load
end

#record(result) ⇒ Hash

Records an evaluation result.

Parameters:

  • result (Hash)

    The evaluation result from EvaluationRunner.

Returns:

  • (Hash)

    Service response.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/skill_bench/trend_tracker.rb', line 21

def record(result)
  history = @persistence.load
  history << extract_entry(result)
  write_result = @persistence.write(history)

  return { success: false, response: { error: write_result[:error] } } unless write_result[:success]

  { success: true, response: { recorded: true } }
rescue StandardError => e
  SkillBench::ErrorLogger.log_error(e, 'TrendTracker Error')
  { success: false, response: { error: { message: e.message } } }
end

#trend_for(result) ⇒ Hash?

Computes the trend of the given result against the most recent matching history entry.

Parameters:

  • result (Hash)

    The current evaluation result.

Returns:

  • (Hash, nil)

    Trend data or nil if no matching history exists.



45
46
47
48
49
# File 'lib/skill_bench/trend_tracker.rb', line 45

def trend_for(result)
  entries = @persistence.load
  current = extract_entry(result)
  TrendCalculator.compute_trend(entries, current)
end