Class: McpServer::StatusTimeAnalysisTool

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/jirametrics/mcp_server.rb

Class Method Summary collapse

Class Method Details

.accumulate_times(server_context, project, issue_state, group_by) ⇒ Object



508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/jirametrics/mcp_server.rb', line 508

def self.accumulate_times server_context, project, issue_state, group_by
  totals = Hash.new { |hash, key| hash[key] = { total_seconds: 0.0, visit_count: 0 } }
  McpServer.each_allowed_issue(server_context, project) do |issue, _name, project_data|
    next unless select_issues(issue, issue_state)

    time_map_for(issue, project_data[:end_time], group_by).each do |name, seconds|
      totals[name][:total_seconds] += seconds
      totals[name][:visit_count] += 1
    end
  end
  totals
end

.call(server_context:, project: nil, project_name: nil, issue_state: 'all', group_by: 'status', column: nil) ⇒ Object



497
498
499
500
501
502
503
504
505
506
# File 'lib/jirametrics/mcp_server.rb', line 497

def self.call(server_context:, project: nil, project_name: nil, issue_state: 'all', group_by: 'status',
              column: nil, **)
  project ||= project_name
  group_by = 'column' if column

  totals = accumulate_times(server_context, project, issue_state, group_by)
  rows = totals.map { |name, data| summary_row(name, data) }.sort_by { |r| -r[:avg_days] }

  McpServer.render_rows(rows, empty: 'No data found.') { |r| format_line(r, group_by) }
end

.format_line(row, group_by) ⇒ Object



538
539
540
541
# File 'lib/jirametrics/mcp_server.rb', line 538

def self.format_line row, group_by
  label = group_by == 'column' ? 'Column' : 'Status'
  "#{label}: #{row[:name]} | Avg: #{row[:avg_days]}d | Total: #{row[:total_days]}d | Issues: #{row[:visit_count]}"
end

.select_issues(issue, issue_state) ⇒ Object



487
488
489
490
491
492
493
494
495
# File 'lib/jirametrics/mcp_server.rb', line 487

def self.select_issues issue, issue_state
  started, stopped = issue.started_stopped_times
  case issue_state
  when 'aging' then started && !stopped
  when 'completed' then !!stopped
  when 'not_started' then !started && !stopped
  else true
  end
end

.summary_row(name, data) ⇒ Object



529
530
531
532
533
534
535
536
# File 'lib/jirametrics/mcp_server.rb', line 529

def self.summary_row name, data
  {
    name: name,
    total_days: (data[:total_seconds] / 86_400.0).round(1),
    avg_days: (data[:total_seconds] / data[:visit_count] / 86_400.0).round(1),
    visit_count: data[:visit_count]
  }
end

.time_map_for(issue, end_time, group_by) ⇒ Object



521
522
523
524
525
526
527
# File 'lib/jirametrics/mcp_server.rb', line 521

def self.time_map_for issue, end_time, group_by
  if group_by == 'column'
    McpServer.time_per_column(issue, end_time)
  else
    McpServer.time_per_status(issue, end_time)
  end
end