Patients Temperatures

Let’s consider files that record the body temperatures for a number of respiratory diseases patients (which b.t.w. has been this year’s Marató de TV theme). The info in the files has the following format: each line of the file corresponds to a patient and contains the following data fields separated by coma (','):

  • The average of the patient’s temperatures rounded to 1 decimals (float).

  • The patient’s name of the patient (str).

  • A variable number of temperature measures (float rounde to 1 decimal).

The file patients.csv is an example:

38.6,Blanca-Nieves-Frias,37.6,38.2,38.8,38.9,38.9,39.0
37.1,Pere-Gil-Julivert,36.5,36.6,36.5,36.8,36.5,37.5
36.8,Mar-Tellez-Querdat,36.7,36.5,36.9,37.5,36.2
38.6,Lola-Marsa-Lada,39.4,38.9,39.0,39.1,38.3,37.1
37.4,Enric-Marco-Gol,37.0,37.3,38.4,38.9,36.6,35.9
37.7,Jordi-Torres-Pipes,38.2,38.1,37.5,36.8,36.5
37.7,Dolores-Fuertes-deCabeza,38.2,38.1,39.0,36.5,36.8
38.6,Ricard-Lamata-Feliz,39.4,38.9,39.0,39.1,39.3,37.1
37.5,Inmaculada-Delano-Moreno,36.9,36.5,36.8,37.5,38.5,38.9
37.4,Aitor-Menta-Morena,38.8,38.2,38.1,36.5,36.8,35.9

We need to filter the temperatures below a given threshold. Specificly, we need a new file with the same info, order and format of the given patients file but:

  1. The temperatures below the threshold must be deleted.

  2. The average temperatures must be recalculated accordingly.

  3. The patiens with all temperatures below the threshold must be deleted.

To this purpose please implement the following Python function in the module pat_temp (file pat_temp.py):

The first function is:

filter_pat_temp(fn, fnout, tempth)

such that

given

  • fn, fnout, str with textfile names with patients data in the format described above.

  • tempth, float.

does two things:

  1. writes a file named fnout resulting from filtering the temperatures by the threshold tempth in the way described above.

  2. returns an int with the number of patients in the output file.

For example the call filter_pat_temp('patients.csv', 'patients-380.csv', 38.0) should return 8 and write a file called 'patients-380.csv' with the following info:

38.8,Blanca-Nieves-Frias,38.2,38.8,38.9,38.9,39.0
38.9,Lola-Marsa-Lada,39.4,38.9,39.0,39.1,38.3
38.6,Enric-Marco-Gol,38.4,38.9
38.2,Jordi-Torres-Pipes,38.2,38.1
38.4,Dolores-Fuertes-deCabeza,38.2,38.1,39.0
39.1,Ricard-Lamata-Feliz,39.4,38.9,39.0,39.1,39.3
38.7,Inmaculada-Delano-Moreno,38.5,38.9
38.4,Aitor-Menta-Morena,38.8,38.2,38.1

Doctests are available at the filter_pat_temp.test file and the files used in those tests area available at patients-380.ref, patients-390.ref, patients-393.ref, patients-395.ref.


Note

To implement this function is recommended (but not mandatory) to previosly implement, test and call the following auxiliar functions:

The first function would be:

filter_tempL(tempL, tempth)

given

  • tempL a list of str representing patient temperatures.

  • tempth a float representing a temperature threshold.

returns a list of the temperatures in tempL converted to float such that a greater or equal than tempth.

The second function would be:

convert_tempL(tempL)

given

  • tempL a list of float representing patient temperatures.

returns

  • a list of str with the temperatures of tempL in the same order converted to str.