Class: Aidp::Evaluations::EvaluationRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/evaluations/evaluation_record.rb

Overview

Represents a single evaluation record

An evaluation captures user feedback (good/neutral/bad) for AIDP outputs such as prompts, work units, or full work loops, along with rich context.

Examples:

Creating an evaluation

record = EvaluationRecord.new(
  rating: "good",
  comment: "Generated code was clean and well-structured",
  target_type: "work_unit",
  target_id: "01_INIT"
)

Constant Summary collapse

VALID_RATINGS =
%w[good neutral bad].freeze
VALID_TARGET_TYPES =
%w[prompt work_unit work_loop step plan review build ci_fix change_request].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rating:, comment: nil, target_type: nil, target_id: nil, context: {}, id: nil, created_at: nil) ⇒ EvaluationRecord



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aidp/evaluations/evaluation_record.rb', line 26

def initialize(rating:, comment: nil, target_type: nil, target_id: nil, context: {}, id: nil, created_at: nil)
  @id = id || generate_id
  @rating = validate_rating(rating)
  @comment = comment
  @target_type = validate_target_type(target_type)
  @target_id = target_id
  @context = context || {}
  @created_at = created_at || Time.now.iso8601

  Aidp.log_debug("evaluation_record", "create",
    id: @id, rating: @rating, target_type: @target_type, target_id: @target_id)
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



23
24
25
# File 'lib/aidp/evaluations/evaluation_record.rb', line 23

def comment
  @comment
end

#contextObject (readonly)

Returns the value of attribute context.



23
24
25
# File 'lib/aidp/evaluations/evaluation_record.rb', line 23

def context
  @context
end

#created_atObject (readonly)

Returns the value of attribute created_at.



23
24
25
# File 'lib/aidp/evaluations/evaluation_record.rb', line 23

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/aidp/evaluations/evaluation_record.rb', line 23

def id
  @id
end

#ratingObject (readonly)

Returns the value of attribute rating.



23
24
25
# File 'lib/aidp/evaluations/evaluation_record.rb', line 23

def rating
  @rating
end

#target_idObject (readonly)

Returns the value of attribute target_id.



23
24
25
# File 'lib/aidp/evaluations/evaluation_record.rb', line 23

def target_id
  @target_id
end

#target_typeObject (readonly)

Returns the value of attribute target_type.



23
24
25
# File 'lib/aidp/evaluations/evaluation_record.rb', line 23

def target_type
  @target_type
end

Class Method Details

.from_h(hash) ⇒ Object

Create record from stored hash



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/aidp/evaluations/evaluation_record.rb', line 53

def self.from_h(hash)
  hash = symbolize_keys(hash)
  new(
    id: hash[:id],
    rating: hash[:rating],
    comment: hash[:comment],
    target_type: hash[:target_type],
    target_id: hash[:target_id],
    context: hash[:context] || {},
    created_at: hash[:created_at]
  )
end

Instance Method Details

#bad?Boolean

Check if rating is negative



72
73
74
# File 'lib/aidp/evaluations/evaluation_record.rb', line 72

def bad?
  @rating == "bad"
end

#good?Boolean

Check if rating is positive



67
68
69
# File 'lib/aidp/evaluations/evaluation_record.rb', line 67

def good?
  @rating == "good"
end

#neutral?Boolean

Check if rating is neutral



77
78
79
# File 'lib/aidp/evaluations/evaluation_record.rb', line 77

def neutral?
  @rating == "neutral"
end

#to_hObject

Convert to hash for storage



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/aidp/evaluations/evaluation_record.rb', line 40

def to_h
  {
    id: @id,
    rating: @rating,
    comment: @comment,
    target_type: @target_type,
    target_id: @target_id,
    context: @context,
    created_at: @created_at
  }
end