Module: DailyFocus::StatsSection

Defined in:
app/services/daily_focus/stats_section.rb

Overview

Section 4 of the support briefing — rendered, not described.

This used to be two SQL queries in the prompt with instructions to build
the table from their results. The step that ran them consolidated nine
queries into one summary that the plan pipeline truncated at 2,000 chars —
right before the statistics — and the assembly then filled the table from
nothing: conv 4821's reasoning-off retry invented 42 presented calls, an
18s wait, a "5m 06s" talk time and a queue_call_logs citation
(2026-08-13), and gemini-3.7-flash invented a different set from the same
starved prompt. No model reports data it was never given, so the table now
arrives finished — the same cure CoverageSection applied to Section 1.

Constant Summary collapse

QUEUE_EXTENSIONS =

Mirrors SupportSections::QUEUE_EXTENSIONS: 613 daytime, 600 overflow.

SupportSections::QUEUE_EXTENSIONS
LOCAL_DATE_SQL =

queue_call_logs.start_time is naive UTC; every bucket is Chicago wall
clock, converted explicitly rather than trusting the session TimeZone.

"((start_time AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago')::date)"
TREND_DAYS =

Trailing window behind the trend column.

28
METRICS =

Row labels, fixed by the section spec (signed off 2026-07-27): every
briefing renders these six, in this order, whatever the data says.

['Calls presented', 'Calls taken', 'Calls missed',
'Calls abandoned', 'Avg wait', 'Avg talk'].freeze
DURATION_METRICS =

The rows whose values are seconds and render as "5m 34s".

['Avg wait', 'Avg talk'].freeze

Class Method Summary collapse

Class Method Details

.prompt_section(primary_employee:, covered:, date:) ⇒ String

Returns prompt block carrying the finished Section 4 table.

Parameters:

  • primary_employee (Employee)
  • covered (Array<Employee>)
  • date (Date)

    the briefing's focus date

Returns:

  • (String)

    prompt block carrying the finished Section 4 table



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/daily_focus/stats_section.rb', line 39

def self.prompt_section(primary_employee:, covered:, date:)
  rep_ids = [primary_employee, *covered].map(&:id)
  stats_date = last_business_day(date)
  table = stats_date && table_for(stats_date, rep_ids, primary_employee)

  <<~TEXT
    SECTION 4 — CALL STATISTICS & FORECAST. #{table ? 'The table below IS Section 4 and it is already finished' : 'The statistics line below IS Section 4'} — computed directly from queue_call_logs for extensions #{QUEUE_EXTENSIONS.join(' and ')}. Reproduce it verbatim under the "SECTION 4 — Call Statistics & Forecast" heading: every row, every cell, every "—". Do NOT run SQL for this section, recompute a value, fill a "—" from another source, or add, drop, reorder or rename a row or a column — a number you did not receive here does not exist.
    #{table || "The phone system reported no queue calls in the #{TREND_DAYS} days before #{date.strftime('%B %-d, %Y')} — state that rather than estimating."}
    #{forecast_line(date)}
    Close the section with one sentence on where today's coverage is most likely to breach wait times, based on Section 1's coverage table — that sentence is the only thing you write here.
  TEXT
end