Module: Legion::Extensions::MindGrowth::Runners::Dashboard

Includes:
Helpers::Lex
Defined in:
lib/legion/extensions/mind_growth/runners/dashboard.rb

Class Method Summary collapse

Class Method Details

.bottom_extensions(extensions:, limit: 10) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/legion/extensions/mind_growth/runners/dashboard.rb', line 71

def bottom_extensions(extensions:, limit: 10, **)
  exts = Array(extensions)
  ranked = Helpers::FitnessEvaluator.rank(exts)
  bottom = ranked.last(limit).reverse.map do |e|
    { name:             e[:name] || e[:extension_name],
      invocation_count: e[:invocation_count] || 0,
      fitness:          e[:fitness] }
  end

  { success: true, bottom: bottom, limit: limit }
end

.build_metricsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/legion/extensions/mind_growth/runners/dashboard.rb', line 33

def build_metrics(**)
  stats = Runners::Proposer.proposal_stats[:stats]
  by_status = stats[:by_status] || {}
  total     = stats[:total] || 0

  approved = by_status[:approved].to_i
  rejected = by_status[:rejected].to_i
  built    = (by_status[:passing].to_i + by_status[:wired].to_i + by_status[:active].to_i)
  failed   = by_status[:build_failed].to_i

  attempted    = built + failed
  success_rate = attempted.positive? ? (built.to_f / attempted).round(3) : 0.0

  evaluated = approved + rejected
  approval_rate = evaluated.positive? ? (approved.to_f / evaluated).round(3) : 0.0

  { success:         true,
    total_proposals: total,
    approved:        approved,
    rejected:        rejected,
    built:           built,
    failed:          failed,
    success_rate:    success_rate,
    approval_rate:   approval_rate }
end

.category_distribution(extensions:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/extensions/mind_growth/runners/dashboard.rb', line 21

def category_distribution(extensions:, **)
  exts = Array(extensions)
  dist = Helpers::Constants::CATEGORIES.to_h { |c| [c, 0] }

  exts.each do |ext|
    cat = (ext[:category] || :cognition).to_sym
    dist[cat] = (dist[cat] || 0) + 1
  end

  { success: true, distribution: dist, total: exts.size }
end

.extension_timeline(extensions:, days: 30) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/legion/extensions/mind_growth/runners/dashboard.rb', line 13

def extension_timeline(extensions:, days: 30, **)
  count = Array(extensions).size
  today = Time.now.utc.strftime('%Y-%m-%d')
  series = [{ date: today, count: count }]

  { success: true, series: series, range_days: days }
end

.full_dashboard(extensions:) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/legion/extensions/mind_growth/runners/dashboard.rb', line 88

def full_dashboard(extensions:, **)
  exts = Array(extensions)

  { success:               true,
    category_distribution: category_distribution(extensions: exts)[:distribution],
    build_metrics:         build_metrics,
    top_extensions:        top_extensions(extensions: exts)[:top],
    bottom_extensions:     bottom_extensions(extensions: exts)[:bottom],
    recent_proposals:      recent_proposals[:proposals],
    health_summary:        Runners::Monitor.health_summary(extensions: exts),
    timestamp:             Time.now.utc.iso8601 }
end

.recent_proposals(limit: 10) ⇒ Object



83
84
85
86
# File 'lib/legion/extensions/mind_growth/runners/dashboard.rb', line 83

def recent_proposals(limit: 10, **)
  result = Runners::Proposer.list_proposals(limit: limit)
  { success: true, proposals: result[:proposals], count: result[:count] }
end

.top_extensions(extensions:, limit: 10) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/legion/extensions/mind_growth/runners/dashboard.rb', line 59

def top_extensions(extensions:, limit: 10, **)
  exts = Array(extensions)
  ranked = Helpers::FitnessEvaluator.rank(exts)
  top = ranked.first(limit).map do |e|
    { name:             e[:name] || e[:extension_name],
      invocation_count: e[:invocation_count] || 0,
      fitness:          e[:fitness] }
  end

  { success: true, top: top, limit: limit }
end