Q2 2025 support SLA and ticket delays

Summary

1,268 of 1,467 eligible tickets met the first-response SLA (86.43%) in tickets.jsonl. Of the 199 misses, 52 were unanswered past deadline.

First-response SLA attainment

86.43 %

Tickets with a recorded first response at or below their business-time target divided by all eligible original tickets. The denominator includes recorded responses and unanswered tickets whose deadline passed by quarter-end.

First-response SLA misses

199 tickets

Among 1,467 eligible tickets, 147 responded above target and 52 remained unanswered past target.

Median time to first resolution

40.38 hours

Median across 1,353 tickets from receipt to first resolved status, excluding customer-wait intervals. Rate components are inapplicable.

Pre-resolution elapsed time in Assigned

88.41 %

Sum of elapsed hours in Assigned divided by all elapsed hours before first resolution, across tickets with a first resolution.

Monthly miss counts stayed at 66, 66 and 67 as the eligible ticket count rose.
Assigned accounted for 61,085.2 of 69,091.8 elapsed hours before first resolution.

Charts

How did first-response attainment change through Q2?

monthly_attainment · n = 3

Excluded 0

How did first-response attainment change through Q2?
Observation
April was 384/450 (85.33%), May 399/465 (85.81%), and June 485/552 (87.86%). tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort. Three monthly values use 1,467 tickets. Upstream exclusions total 33. The renderer excluded zero monthly values.
Domain interpretation
Monthly miss counts stayed at 66, 66 and 67 as the eligible ticket count rose.

How close were individual responses to their targets?

response_observations · n = 1415

Excluded 0

How close were individual responses to their targets?
Observation
1,415 recorded, eligible responses from tickets.jsonl lines 1–1500, each divided by its priority target. A value above 1 is late. The plot omits 15 linked duplicates, 18 pending tickets and 52 overdue unanswered tickets. The renderer excluded zero input points.
Domain interpretation
There were 147 recorded responses above target. Another 52 tickets counted as misses while still unanswered.

How widely did customer-wait-adjusted time to first resolution vary?

resolution_spread · n = 1353

Excluded 0

How widely did customer-wait-adjusted time to first resolution vary?
Observation
1,353 resolved tickets from tickets.jsonl lines 1–1500. Time is in elapsed hours. The median was 40.4 hours and the 90th percentile was 87.1 hours. Upstream exclusions are the 147 tickets lacking a first resolution. The renderer excluded zero input points.
Domain interpretation
The longest adjusted first resolution took 262.9 hours, at line 897.

Which recorded status accounted for the most time before first resolution?

resolution_stages · n = 4059

Excluded 0

Which recorded status accounted for the most time before first resolution?
Observation
1,353 tickets from tickets.jsonl lines 1–1500 contribute one elapsed-hour value per status, including zero for a stage with no time. There are 4,059 plotted values. Upstream exclusions are 147 tickets without first resolution. The renderer excluded zero input values.
Domain interpretation
Assigned accounted for 61,085.2 of 69,091.8 elapsed hours before first resolution.

Assumptions & limitations

  • Coverage spans all 91 KST calendar dates in Q2 2025. Count each ticket by its receipt date and use the file's recorded outcomes up to quarter-end.
  • First responses use 63 business dates: weekdays 09:00–18:00 KST, excluding May 5 and June 6. Targets are inclusive and priority-based.
  • For resolution, the stated duplicate exclusion was applied only to response SLA. Resolution timing includes all tickets with a first recorded resolution, including 13 linked duplicates. The 104 reopened tickets have their later work outside this timing measure.
  • Resolution attainment is unavailable because the policy targets are unknown. The adjusted-duration distribution uses the resolved cohort, and 147 tickets lacking resolution have no duration in it.
  • Assigned is elapsed time in a logged status, including time outside business hours. The ticket file provides no agent rosters or measured active work time. Use the P2 receipt-window comparison to identify where to review coverage and the Assigned intervals to locate the largest elapsed status.
  • The outside-hours attainment difference varies by priority. P2 was 78.28% outside hours and 94.87% during hours. P3 was 89.66% outside hours and 85.42% during hours. June included 156 eligible P1 tickets, compared with 36 in April and 36 in May. The comparisons reflect the observed mix.
  • Quality checks found zero malformed lines, repeated ticket IDs, exact repeated records, or timestamp parsing failures in the analyzed fields. The 15 duplicate links all point to originals. Event histories are chronological and agree with receipt and first resolution fields.
  • Of 1,500 records, 72 lack a first-response timestamp and 147 lack a first-resolution timestamp, affecting 147 distinct tickets. The 107 missing customer tiers and 1,327 missing CSAT values are outside the measures. The optional duplicate_of key is absent on 1,485 records.
  • The resolution histogram retains 37 adjusted durations above the upper 1.5-IQR fence. The reported median and 90th percentile both use the full resolved cohort.
  • A separate correlation view was omitted because the staffing comparison uses categorical intake windows and priorities. A separate status frequency chart was omitted because the delay question uses elapsed status time.

Ambiguity log

IDItemStatusAnswer
A01Business processresolvedMeasure from receipt to the first resolved event. Subtract intervals beginning in waiting_customer and ending at the next recorded event. The user chose the first resolved event even if the ticket reopened.
Evidence and options
question
Use the first or last recorded resolution?
file_evidence
  • tickets.jsonl lines 1–1500, $.events[*].status sequence
  • tickets.jsonl line 15 has a reopened event
candidates
  • First resolved event
  • Last resolved event
affects
  • Resolution timing
A02DecisionresolvedThe user will discuss next-quarter staffing using the Q2 SLA and delay findings.
Evidence and options
file_evidence
  • tickets.jsonl lines 1–1500
affects
  • Intake windows and group comparisons
A03Row meaningresolvedAnalyze one ticket per JSON line. Keep the event sequence within each ticket.
Evidence and options
file_evidence
  • tickets.jsonl lines 1–1500 have 1,500 distinct ticket_id values and nested event records
affects
  • All ticket counts
A04SLA thresholds and denominatorresolvedUser supplied P1/P2/P3/P4 first-response targets of 1/4/8/24 business hours. Count all eligible originals once.
Evidence and options
question
What first-response and resolution time targets apply?
file_evidence
  • tickets.jsonl line 1 has priority and response timestamps
candidates
  • Priority-based targets
affects
  • First-response SLA attainment
A05Time basisresolvedScore Q2 2025 KST arrivals at quarter-end. Use weekdays 09:00–18:00 KST, except May 5 and June 6, for the first-response clock. Resolution uses elapsed hours.
Evidence and options
file_evidence
  • tickets.jsonl lines 1 and 1500 delimit the Q2 KST receipt range
affects
  • Quarter cohort and duration calculations
A06ExceptionsresolvedUser confirmed excluding tickets marked duplicate_of from first-response SLA only. Those IDs link to original tickets in the file.
Evidence and options
question
Do tickets marked duplicate_of count separately?
file_evidence
  • tickets.jsonl line 161 has duplicate_of
candidates
  • Separate tickets
  • Exclude linked duplicates
affects
  • First-response SLA attainment
A07Missing valuesresolvedUser confirmed counting 54 overdue unanswered tickets before duplicate exclusions. The final eligible cohort contains 52. Exclude the 18 original tickets whose response targets remained open.
Evidence and options
question
Count overdue unanswered tickets as misses or use recorded responses only?
file_evidence
  • tickets.jsonl line 18 lacks first_response_at and its deadline passed
candidates
  • Include overdue unanswered misses
  • Use recorded responses only
affects
  • First-response SLA attainment
A08Join keysnot_applicableThe analysis uses one table. No external lookup or event-level join is needed.
Evidence and options
file_evidence
  • tickets.jsonl lines 1–1500
A09Resolution SLA targetsunresolvedUser reported that the resolution SLA targets are unknown.
Evidence and options
file_evidence
  • tickets.jsonl line 1 has resolved_at and event status without a target field
affects
  • Resolution SLA attainment

Data overview

datasets
  • id
    jsonl:1
    format
    jsonl
    read_ranges
    • tickets.jsonl lines 1–1500 (full UTF-8 read. One JSON object per line, no header.)
    rows
    1500
    columns
    12
row_grain
One ticket per line. Each ticket can have several nested status events. The JSONL suffix agrees with the decoded content.

Metrics

MetricValueDefinitionNumeratorDenominatorConditionSources
First-response SLA attainment86.43 %Tickets with a recorded first response at or below their business-time target divided by all eligible original tickets. The denominator includes recorded responses and unanswered tickets whose deadline passed by quarter-end.1,2681,467
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort
First-response SLA misses199 ticketsAmong 1,467 eligible tickets, 147 responded above target and 52 remained unanswered past target.
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort
Median time to first resolution40.38 hoursMedian across 1,353 tickets from receipt to first resolved status, excluding customer-wait intervals. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
Pre-resolution elapsed time in Assigned88.41 %Sum of elapsed hours in Assigned divided by all elapsed hours before first resolution, across tickets with a first resolution.61,085.1666666666769,091.81666666667
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
Priority · P185.09 %First-response attainment for this group. 34 missed, including 11 unanswered past deadline.194228
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with priority = P1
Priority · P282.61 %First-response attainment for this group. 52 missed, including 11 unanswered past deadline.247299
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with priority = P2
Priority · P388.51 %First-response attainment for this group. 61 missed, including 13 unanswered past deadline.470531
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with priority = P3
Priority · P487.29 %First-response attainment for this group. 52 missed, including 17 unanswered past deadline.357409
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with priority = P4
Assignee team · account_support82.57 %First-response attainment for this group. 61 missed, including 20 unanswered past deadline.289350
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with assignee_team = account_support
Assignee team · platform87.9 %First-response attainment for this group. 56 missed, including 15 unanswered past deadline.407463
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with assignee_team = platform
Assignee team · product_support87.61 %First-response attainment for this group. 41 missed, including 8 unanswered past deadline.290331
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with assignee_team = product_support
Assignee team · technical_support87.31 %First-response attainment for this group. 41 missed, including 9 unanswered past deadline.282323
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with assignee_team = technical_support
Channel · chat87.08 %First-response attainment for this group. 54 missed, including 18 unanswered past deadline.364418
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with channel = chat
Channel · email86.34 %First-response attainment for this group. 121 missed, including 26 unanswered past deadline.765886
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with channel = email
Channel · phone85.28 %First-response attainment for this group. 24 missed, including 8 unanswered past deadline.139163
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with channel = phone
Receipt window · Business hours89.62 %First-response attainment for this group. 44 missed, including 14 unanswered past deadline.380424
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Business hours
Receipt window · Outside business hours85.14 %First-response attainment for this group. 155 missed, including 38 unanswered past deadline.8881,043
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Outside business hours
Receipt month · 2025-0485.33 %First-response attainment for this group. 66 missed, including 15 unanswered past deadline.384450
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with month = 2025-04
Receipt month · 2025-0585.81 %First-response attainment for this group. 66 missed, including 18 unanswered past deadline.399465
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with month = 2025-05
Receipt month · 2025-0687.86 %First-response attainment for this group. 67 missed, including 19 unanswered past deadline.485552
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with month = 2025-06
Receipt window and priority · Business hours / P185.71 %First-response attainment for this group. 12 missed, including 6 unanswered past deadline.7284
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Business hours, priority = P1
Receipt window and priority · Business hours / P294.87 %First-response attainment for this group. 4 missed, including 1 unanswered past deadline.7478
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Business hours, priority = P2
Receipt window and priority · Business hours / P385.42 %First-response attainment for this group. 21 missed, including 4 unanswered past deadline.123144
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Business hours, priority = P3
Receipt window and priority · Business hours / P494.07 %First-response attainment for this group. 7 missed, including 3 unanswered past deadline.111118
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Business hours, priority = P4
Receipt window and priority · Outside business hours / P184.72 %First-response attainment for this group. 22 missed, including 5 unanswered past deadline.122144
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Outside business hours, priority = P1
Receipt window and priority · Outside business hours / P278.28 %First-response attainment for this group. 48 missed, including 10 unanswered past deadline.173221
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Outside business hours, priority = P2
Receipt window and priority · Outside business hours / P389.66 %First-response attainment for this group. 40 missed, including 9 unanswered past deadline.347387
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Outside business hours, priority = P3
Receipt window and priority · Outside business hours / P484.54 %First-response attainment for this group. 45 missed, including 14 unanswered past deadline.246291
  • tickets.jsonl lines 1–1500 filtered to the eligible first-response cohort with receipt = Outside business hours, priority = P4
Median gross time to first resolution45.38 hoursTicket-level quantile across 1,353 first resolutions. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
90th percentile gross time to first resolution93.16 hoursTicket-level quantile across 1,353 first resolutions. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
90th percentile adjusted time to first resolution87.14 hoursTicket-level quantile across 1,353 first resolutions. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
Median time in Assigned before first resolution39.82 hoursTicket-level quantile across 1,353 first resolutions. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
Total elapsed time in New521.73 hoursSum of time in this status before first resolution across 1,353 tickets, including tickets with zero time in the status. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
Total elapsed time in Assigned61,085.17 hoursSum of time in this status before first resolution across 1,353 tickets, including tickets with zero time in the status. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
Total elapsed time in Waiting for customer7,484.92 hoursSum of time in this status before first resolution across 1,353 tickets, including tickets with zero time in the status. Rate components are inapplicable.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
First resolutions with customer wait31.63 %Tickets with positive customer-wait time before their first resolution divided by tickets with a first resolution.4281,353
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved
Resolution SLA attainment%The resolution target is unknown. The numerator and denominator for attainment remain undefined.
  • tickets.jsonl lines 1–1500 with a first $.events[*].status of resolved

Reproducibility

filters
  • Use KST receipts in [2025-04-01 00:00, 2025-07-01 00:00). Convert offset-aware timestamps to the same timezone before cohorting and timing.
  • Remove duplicate_of records for response compliance. Count recorded responses and overdue unanswered as eligible. Keep still-within-target unanswered tickets outside the denominator.
  • For resolution, include tickets with a first resolved event. Subtract each interval starting with waiting_customer and ending at the next event, up to first resolution.
exclusions
  • scope
    First-response SLA and response charts
    source_refs
    • tickets.jsonl lines 161, 278, 328, 342, 533, 538, 547, 572, 607, 624, 762, 765, 866, 916, 920
    reason
    15 tickets linked to originals through duplicate_of. The original tickets are evaluated under the same first-response rules.
  • scope
    First-response SLA and response charts
    source_refs
    • tickets.jsonl lines 1434, 1457, 1459, 1470, 1475, 1478, 1482–1484, 1491, 1493–1500
    reason
    18 unanswered original tickets whose first-response deadlines remained open at quarter-end.
  • scope
    Recorded first-response chart
    source_refs
    • tickets.jsonl lines 18, 52, 68, 84, 113, 120, 157, 198, 229, 266, 269, 323, 388, 392, 401, 457, 528, 536–537, 564–565, 578, 606, 650, 674, 706, 718, 750–751, 784, 827, 849, 857, 945, 995, 1025, 1048, 1067, 1108, 1140, 1152, 1192, 1202, 1228, 1233, 1235, 1263, 1282, 1299, 1338, 1382, 1490
    reason
    52 eligible overdue tickets have no observed first-response duration. They contribute to the compliance denominator as misses.
  • scope
    Resolution metrics and charts
    source_refs
    • tickets.jsonl lines 9, 14, 18, 51–52, 68, 75, 84, 86, 96, 113, 120–121, 149, 154, 157, 173, 198, 203, 225, 229, 241, 266, 269, 272, 282, 319, 323–324, 331, 342, 388, 390, 392, 394, 401, 417, 455, 457, 471, 494, 496, 528, 532, 536–537, 555, 564–565, 578–579, 606, 609, 650, 661, 674, 684, 694–695, 706, 718, 728, 750–751, 765, 771, 777, 781, 784, 798, 804, 827, 849, 857, 861, 874, 903, 927, 945, 995, 1003, 1008, 1025, 1030, 1047–1048, 1067, 1092, 1094, 1099, 1108, 1116, 1140, 1151–1152, 1192, 1202, 1228, 1233, 1235, 1255, 1263, 1282, 1299, 1322, 1338, 1382, 1386, 1418, 1433–1434, 1444, 1454, 1457, 1459, 1462–1468, 1470–1472, 1475–1476, 1478–1480, 1482–1485, 1488–1500
    reason
    147 tickets have no first resolved event by quarter-end.
transforms
  • input
    tickets.jsonl
    transform
    Decode one JSON object per line and retain original line numbers
    output
    Q2 receipts
    before
    1500
    after
    1500
  • input
    Q2 receipts
    transform
    Exclude duplicate_of links from the first-response population
    output
    Original tickets
    before
    1500
    after
    1485
  • input
    Original tickets
    transform
    Determine eligibility at quarter-end
    output
    First-response SLA cohort
    before
    1485
    after
    1467
  • input
    First-response SLA cohort
    transform
    Select recorded first responses for raw chart
    output
    Observed first responses
    before
    1467
    after
    1415
  • input
    First-response SLA cohort
    transform
    Pool counts by KST receipt month
    output
    Monthly values
    before
    1467
    after
    3
  • input
    Q2 receipts
    transform
    Select and time first resolution
    output
    First resolutions
    before
    1500
    after
    1353
  • input
    First resolutions
    transform
    Emit New, Assigned and Waiting for customer hours per ticket
    output
    Status-duration values
    before
    1353
    after
    4059
sample_sizes
Q2 receipts
1500
first-response SLA
1467
recorded first responses
1415
first resolutions
1353
status durations
4059
source_locators
  • tickets.jsonl lines 1–1500
  • tickets.jsonl line 18 (overdue unanswered)
  • tickets.jsonl line 1500 (pending)
  • tickets.jsonl line 15 (reopened after first resolution)
  • tickets.jsonl line 2, $.events[2:4] (one customer-wait interval)
  • tickets.jsonl line 897 (longest adjusted time)

Code

# Run from eda-work with python3 -I analyze.py
import json
from collections import Counter
from pathlib import Path

import pandas as pd

SOURCE = Path("../tickets.jsonl")
ZONE = "Asia/Seoul"
START = pd.Timestamp("2025-04-01", tz=ZONE)
CUTOFF = pd.Timestamp("2025-07-01", tz=ZONE)
HOLIDAYS = {"2025-05-05", "2025-06-06"}
TARGET = {"P1": 60, "P2": 240, "P3": 480, "P4": 1440}
lines = SOURCE.read_text(encoding="utf-8").splitlines()
records = [json.loads(line) for line in lines]
d = pd.DataFrame(records, index=pd.Index(range(1, len(records) + 1), name="source_line"))
parse_failures = {}
for col in ["created_at", "first_response_at", "resolved_at"]:
    parsed = pd.to_datetime(d[col], utc=True, errors="coerce").dt.tz_convert(ZONE)
    parse_failures[col] = int((parsed.isna() & d[col].notna()).sum())
    d[col] = parsed
assert not any(parse_failures.values())
duplicate = d.duplicate_of.notna()
assert d.ticket_id.is_unique and d.ticket_id.notna().all()
assert d.loc[duplicate, "duplicate_of"].isin(d.loc[~duplicate, "ticket_id"]).all()
assert (d.created_at.ge(START) & d.created_at.lt(CUTOFF)).all()

# Build business intervals in KST and intersect them with each response clock.
days = pd.date_range(START, CUTOFF, freq="B", inclusive="left")
windows = [
    (day + pd.Timedelta(hours=9), day + pd.Timedelta(hours=18))
    for day in days if day.strftime("%Y-%m-%d") not in HOLIDAYS
]
def business_minutes(start, stop):
    return sum(max(0, (min(stop, end) - max(start, begin)).total_seconds()) / 60
               for begin, end in windows if start < end and stop > begin)

responded = d.first_response_at.notna()
assert d.loc[responded, "first_response_at"].ge(d.loc[responded, "created_at"]).all()
assert d.loc[responded, "first_response_at"].lt(CUTOFF).all()
d["target_min"] = d.priority.map(TARGET)
assert d.target_min.notna().all()
d["business_min"] = [
    business_minutes(a, b) for a, b in zip(d.created_at, d.first_response_at.fillna(CUTOFF))
]
d["late_unanswered"] = ~responded & d.business_min.ge(d.target_min)
d["eligible"] = ~duplicate & (responded | d.late_unanswered)
d["met"] = d.eligible & responded & d.business_min.le(d.target_min)
d["missed"] = d.eligible & ~d.met
d["month"] = d.created_at.dt.strftime("%Y-%m")
d["receipt"] = [
    "Business hours" if any(a <= t < b for a, b in windows) else "Outside business hours"
    for t in d.created_at
]
d["recorded"] = responded

# Use source event order. Each interval inherits the status at its start.
all_status = Counter()
kinds = ("new", "assigned", "waiting_customer")
stages = []
reopened = []
for line, row in d.iterrows():
    events = [(pd.Timestamp(event["at"]).tz_convert(ZONE), event["status"]) for event in row.events]
    all_status.update(status for _, status in events)
    assert events[0] == (row.created_at, "new")
    assert all(left[0] <= right[0] for left, right in zip(events, events[1:]))
    first = next((j for j, (_, status) in enumerate(events) if status == "resolved"), None)
    if any(status == "reopened" for _, status in events):
        reopened.append(line)
    if first is None:
        assert pd.isna(row.resolved_at)
        continue
    assert events[first][0] == row.resolved_at and row.resolved_at < CUTOFF
    hours = dict.fromkeys(kinds, 0.0)
    for (begin, status), (end, _) in zip(events[:first], events[1:first + 1]):
        hours[status] += (end - begin).total_seconds() / 3600
    gross = (row.resolved_at - row.created_at).total_seconds() / 3600
    assert abs(gross - sum(hours.values())) < 1e-8
    stages.append({
        "source_line": line, "gross_h": gross, **hours,
        "adjusted_h": gross - hours["waiting_customer"]
    })
resolved = pd.DataFrame(stages).set_index("source_line")
d = d.join(resolved, validate="one_to_one")
sla = d[d.eligible].copy()
raw = sla[sla.recorded].copy()
raw["target_multiple"] = raw.business_min / raw.target_min

def breakdown(columns):
    table = sla.groupby(columns, dropna=False).agg(
        eligible=("met", "size"), met=("met", "sum"), missed=("missed", "sum"),
        unanswered_misses=("late_unanswered", "sum"), recorded=("recorded", "sum")
    )
    table["percent"] = 100 * table.met / table.eligible
    return table

monthly = breakdown("month")
monthly.reset_index().assign(month_start=lambda g: g.month + "-01").to_csv("monthly.csv", index=False)
raw[["target_multiple"]].to_csv("response_observations.csv")
resolved[["adjusted_h"]].to_csv("resolution_observations.csv")
resolved[list(kinds)].rename(columns={
    "new": "New", "assigned": "Assigned", "waiting_customer": "Waiting for customer"
}).reset_index().melt(id_vars="source_line", var_name="status", value_name="elapsed_h").to_csv(
    "stage_observations.csv", index=False
)

if __name__ == "__main__":
    print("Missing fields:", pd.DataFrame(records).isna().sum().to_dict())
    print("Exact repeated records:", len(records) - len({json.dumps(r, sort_keys=True) for r in records}))
    print("Events:", all_status, "reopened tickets:", len(reopened))
    print("Scopes:", len(d), int(duplicate.sum()), len(sla), len(raw), len(resolved))
    print("Overall:", int(sla.met.sum()), int(sla.missed.sum()), int(sla.late_unanswered.sum()))
    for grouping in ["priority", "assignee_team", "channel", "receipt", "month",
                     ["receipt", "priority"], ["month", "priority"]]:
        print(breakdown(grouping).to_string())
    print("Resolution", resolved.describe(percentiles=[.25, .5, .75, .9]).to_string())
    print("Resolution sums", resolved.sum().to_dict())
    print("Positive waiting count", int(resolved.waiting_customer.gt(0).sum()))
    print("Resolution by team", d.groupby("assignee_team").adjusted_h.agg(["count", "median"]).to_string())
    print("Response multiples", raw.target_multiple.describe(percentiles=[.5,.9]).to_dict())
    print("Late answered response business hours", (raw.loc[raw.missed, "business_min"]/60).describe().to_dict())
    print("Highest miss slice", sla[sla.missed].groupby(["priority","assignee_team"]).size().nlargest(5).to_dict())
    print("Source examples", sla[sla.late_unanswered].index[0], int(resolved.assigned.idxmax()))

# Render each figure with python3 -I ../eda-skill/scripts/plots.py --spec plot-<id>.json --outdir delivery/figures

# Plot specifications (one per input table)
# plot-monthly_attainment.json
# {"source": {"path": "monthly.csv", "header": true}, "charts": [{"id": "monthly_attainment", "type": "line_time", "time": "month_start", "value": "percent", "title": "First-response SLA attainment by receipt month", "x_label": "Receipt month (KST)", "y_label": "Eligible tickets that met target", "y_unit": "%"}]}
# plot-resolution_spread.json
# {"source": {"path": "resolution_observations.csv", "header": true}, "charts": [{"id": "resolution_spread", "type": "histogram", "column": "adjusted_h", "bins": 26, "title": "Time to first resolution after customer waits", "x_label": "Receipt to first resolution, excluding customer waits", "x_unit": "hours", "y_label": "Tickets"}]}
# plot-resolution_stages.json
# {"source": {"path": "stage_observations.csv", "header": true}, "charts": [{"id": "resolution_stages", "type": "grouped_boxplot", "group": "status", "value": "elapsed_h", "title": "Time spent in each status before first resolution", "x_label": "Recorded event status", "y_label": "Elapsed time per ticket", "y_unit": "hours"}]}
# plot-response_observations.json
# {"source": {"path": "response_observations.csv", "header": true}, "charts": [{"id": "response_observations", "type": "scatter", "x": "source_line", "y": "target_multiple", "title": "Recorded first-response times relative to target", "x_label": "Original JSONL line", "y_label": "Business time divided by target", "y_unit": "times target"}]}