ExpertData Analysis50 points

Waiting-time percentiles by hospital site

A health regulator reports the 50th, 90th and 99th percentile waiting times per hospital site, because averages hide long waits. Two files must be joined.

  • patients.csv: patient_id, department, arrival_hour, wait_min
  • departments.csv: department, site (hospital name), beds

Task: line 1 of the input is a site name (exactly as in departments.csv), line 2 holds integer percentiles separated by spaces, for example 50 90. Pool the waits of all patients whose department belongs to that site and sort them. The percentile p uses linear interpolation: position pos = (n - 1) x p / 100, lo = floor(pos), hi = min(lo + 1, n - 1), value w[lo] + (w[hi] - w[lo]) x (pos - lo). Print Patients: n then one line Pp: value per requested percentile in the given order, value with 2 decimals (for example P90: 88.40). If the site has no patients print only No data.

Files your program can read

patients.csv261 lines
patient_id,department,arrival_hour,wait_min
P3001,Dermatology,16,47
P3002,Orthopaedics,16,42
P3003,Cardiology,16,57
P3004,Paediatrics,12,38
P3005,Maternity,12,17
P3006,Oncology,15,11
P3007,Emergency,16,11
...
departments.csv9 lines
department,site,beds
Emergency,St Mary Central,12
Radiology,St Mary Central,17
Cardiology,St Mary Central,22
Orthopaedics,Riverside General,27
Paediatrics,Riverside General,32
Oncology,Riverside General,37
Dermatology,Kingsway Clinic,42
...

Open them by name, for example open("patients.csv").

Sample test

Input

St Mary Central
50 90

Expected output

Patients: 100
P50: 46.50
P90: 103.00

Your answer is also checked against 4 hidden tests.