SLA breaches by ticket priority
A managed-services company promises resolution within a number of hours per priority. The monthly review needs the median resolution time and the number of breaches. Data: support.csv, tickets opened between April and June 2025.
ticket_id: unique codepriority: P1 (most urgent) to P4opened: timestampYYYY-MM-DD HH:MMclosed: timestamp in the same format, empty while the ticket is still open
Task: line 1 holds four integer SLA limits in hours for P1, P2, P3, P4 (separated by spaces). Line 2 is an opening month YYYY-MM or ALL. Resolution time is closed - opened in hours (use datetime). A ticket is breached if its resolution time is strictly greater than the limit. For P1, P2, P3, P4 in this order print P1: closed=C open=O median=Mh breached=B where M is the median resolution time of closed tickets (statistics.median, 1 decimal) or n/a if none closed; or P1: no tickets when the priority has no tickets in the selection.
Files your program can read
ticket_id,priority,opened,closed S9001,P3,2025-06-03 12:39,2025-06-05 00:12 S9002,P1,2025-05-15 15:54,2025-05-15 22:41 S9003,P3,2025-05-18 15:27,2025-05-19 20:21 S9004,P2,2025-05-05 18:44,2025-05-06 04:05 S9005,P3,2025-06-24 16:04,2025-06-28 00:24 S9006,P3,2025-05-26 10:54,2025-05-29 17:02 S9007,P3,2025-06-26 08:57,2025-06-29 03:05 ...
Open them by name, for example open("support.csv").
Sample test
Input
4 24 72 120 ALL
Expected output
P1: closed=33 open=2 median=3.5h breached=14 P2: closed=57 open=9 median=13.2h breached=9 P3: closed=79 open=5 median=49.0h breached=18 P4: closed=32 open=3 median=97.1h breached=10
Your answer is also checked against 5 hidden tests.
Need a hint?
Subtracting two datetime objects gives a timedelta; total_seconds() / 3600 turns it into hours.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
