Patients¶
A file contains a record of the body temperatures of several patients staying in a hospital. The Each line of the file corresponds to a patient and contains the name of the patient (str) followed by a (possibly different) number of measured temperatures (float) all separated by coma (',') . The file patients.txt contains the following example:
Josefa Marquez,37.6,38.2,38.8,38.9,38.9 Joan Oliva,36.5,36.6,36.5,36.8,36.5 Peret Manau,37.3,38.4,36.5,36.6,36.8 Josep Petit,38.2,38.1,36.5,36.8,35.9 Margarida Flor,36.7,36.5,36.9,37.5,36.2 Maria Montserrat,39.4,38.9,39.1,38.3,37.1 Lluis Perez,36.9,36.5,36.8,36.5,37.0 Puri Garcia,37.0,37.3,38.4,36.6,35.9 Joana Marques,38.2,38.1,36.5,36.8,35.9
We need to filter the patients whose average temperature (rounded to 2 decimals) falls inside a given closed interval.
Implement the following Python function in the module patients11 (file patients11.py):
- filter_fever_interval(pat_fn, pat_in_fn, pat_out_fn, low_b, up_b)¶
such that
and does two things:
1. writes two files: one namedpat_in_fnwith the information about the patients whose average temperature is in the real numbers closed interval[low_b, up_b]and another namedpat_out_fnwith those patients whose average temperature is strictly outside the interval. The format details of these files are as follows:
The patients must appear in the same order as in the
pat_fnfile.For each patient the must be a line with: all h@s measures, the name, and the average temperature rounded to 2 decimal, all separated by coma (‘,’).
2. returns threeintwith: the number of patients processed, the number of patients inside, and the number of patients outside the interval.
For example the call filter_fever_interval('patients.txt', 'patients-in-37.0-38.0.txt', 'patients-out-37.0-38.0.txt', 37.0, 38.0) should return (9, 4, 5) and create the files patients-in-37.0-38.0.txt and patients-out-37.0-38.0.txt that contain the following texts:
37.3,38.4,36.5,36.6,36.8,Peret Manau,37.12 38.2,38.1,36.5,36.8,35.9,Josep Petit,37.1 37.0,37.3,38.4,36.6,35.9,Puri Garcia,37.04 38.2,38.1,36.5,36.8,35.9,Joana Marques,37.1
and
37.6,38.2,38.8,38.9,38.9,Josefa Marquez,38.48 36.5,36.6,36.5,36.8,36.5,Joan Oliva,36.58 36.7,36.5,36.9,37.5,36.2,Margarida Flor,36.76 39.4,38.9,39.1,38.3,37.1,Maria Montserrat,38.56 36.9,36.5,36.8,36.5,37.0,Lluis Perez,36.74
Note
Notice that the temperatures average must be rounded to 2 decimals before comparing it to low_b and up_b values.
Doctests are available at the filter_fever_interval-test.txt file.