Class: ABTestModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ABTestModel
- Defined in:
- lib/generators/decision_agent/install/templates/ab_test_model.rb
Overview
A/B Test model for decision_agent gem Stores A/B test configurations
Instance Method Summary collapse
- #challenger_assignments ⇒ Object
-
#champion_assignments ⇒ Object
Get assignments by variant.
-
#running? ⇒ Boolean
Check if test is currently running.
-
#statistics ⇒ Object
Get statistics for this test.
Instance Method Details
#challenger_assignments ⇒ Object
46 47 48 |
# File 'lib/generators/decision_agent/install/templates/ab_test_model.rb', line 46 def challenger_assignments ab_test_assignment_models.where(variant: "challenger") end |
#champion_assignments ⇒ Object
Get assignments by variant
42 43 44 |
# File 'lib/generators/decision_agent/install/templates/ab_test_model.rb', line 42 def champion_assignments ab_test_assignment_models.where(variant: "champion") end |
#running? ⇒ Boolean
Check if test is currently running
24 25 26 27 28 |
# File 'lib/generators/decision_agent/install/templates/ab_test_model.rb', line 24 def running? status == "running" && (start_date.nil? || start_date <= Time.current) && (end_date.nil? || end_date > Time.current) end |
#statistics ⇒ Object
Get statistics for this test
31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/decision_agent/install/templates/ab_test_model.rb', line 31 def statistics { total_assignments: ab_test_assignment_models.count, champion_count: ab_test_assignment_models.where(variant: "champion").count, challenger_count: ab_test_assignment_models.where(variant: "challenger").count, with_decisions: ab_test_assignment_models.where.not(decision_result: nil).count, avg_confidence: ab_test_assignment_models.where.not(confidence: nil).average(:confidence)&.to_f } end |