Class: Legion::Gaia::NotificationGate::BehavioralEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/gaia/notification_gate/behavioral_evaluator.rb

Constant Summary collapse

PRIORITY_BASE_THRESHOLD =
{ critical: 0.0, urgent: 0.0, normal: 0.3, low: 0.5, ambient: 0.7 }.freeze
THRESHOLD_MODIFIER =
0.3

Instance Method Summary collapse

Constructor Details

#initializeBehavioralEvaluator

Returns a new instance of BehavioralEvaluator.



10
11
12
13
# File 'lib/legion/gaia/notification_gate/behavioral_evaluator.rb', line 10

def initialize
  @arousal = nil
  @idle_seconds = nil
end

Instance Method Details

#notification_scoreObject



23
24
25
26
27
28
29
30
31
# File 'lib/legion/gaia/notification_gate/behavioral_evaluator.rb', line 23

def notification_score
  signals = []
  signals << arousal_signal if @arousal
  signals << idle_signal if @idle_seconds

  return 1.0 if signals.empty?

  signals.sum / signals.size
end

#should_deliver?(priority: :normal) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/legion/gaia/notification_gate/behavioral_evaluator.rb', line 33

def should_deliver?(priority: :normal)
  base = PRIORITY_BASE_THRESHOLD[priority] || PRIORITY_BASE_THRESHOLD[:normal]
  effective_threshold = base + ((1.0 - notification_score) * THRESHOLD_MODIFIER)
  priority_value(priority) >= effective_threshold
end

#update_arousal(value) ⇒ Object



15
16
17
# File 'lib/legion/gaia/notification_gate/behavioral_evaluator.rb', line 15

def update_arousal(value)
  @arousal = value.to_f.clamp(0.0, 1.0)
end

#update_idle_seconds(seconds) ⇒ Object



19
20
21
# File 'lib/legion/gaia/notification_gate/behavioral_evaluator.rb', line 19

def update_idle_seconds(seconds)
  @idle_seconds = seconds.to_f
end