Patients Fever

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). We are receiveing the info in one format (let’s call it FormatA) and we need to put it in a different format (let’s call it FormatB):

Format A: Each line of the file corresponds to a patient and contains the following data fields separated by coma (','):
  • the fullname of the patient (str with name and two last names separated by space ' ')

  • a variable number of temperature measures (float)

The file fev1.csv and fev2.csv are examples:

Blanca Nieves Frias,37.6,38.2,38.8,38.9,38.9,39.0
Pere Gil Julivert,36.5,36.6,36.5,36.8,36.5,39.5
Mar Tellez Berlat,36.7,36.5,36.9,37.5,36.2
Lola Marturi San,39.4,38.9,39.0,39.1,38.3,37.1
Enric Marco Gol,37.0,37.3,38.4,39.0,36.6,35.9
Jordi Torres Pipes,38.2,38.1,39.0,36.5,36.8
Dolores Fuertes deCabeza,38.2,38.1,39.0,36.5,36.8
Ricard Lamata Feliz,39.4,38.9,39.0,39.1,38.3,37.1
Inmaculada Delano Moreno,36.9,36.5,36.8,37.5,38.5,39.0
Aitor Menta Ita,39.0,38.2,38.1,36.5,36.8,35.9

Format B: 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 first last name of the patient (str)

  • the second last name of the patient (str)

  • the first name of the patient (str)

  • a variable number of temperature measures (float)

The file fev1+2.csv is an example:

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

Implement the following Python functions in the module fever (file fever.py):

The first function is:

fever_merge(fn1, fn2, fnout):

given fn1, fn2, fnout, three str with textfile names, where fn1, fn2 are names of files with patients data in Format A.

does two things:

  1. writes a fille named fnout with the information of fn1 and fn2 together in Format B. The order of the patients is: first the patients of fn1 followed by those in fn2, all apearing in the same order as in the input files.

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

For example the call fever_merge('fev1.csv', 'fev2.csv', 'fev1+2.csv) should return 10 and create the file fev1+2.csv above.

Doctests are available at the fever_merge.test file.


The second function is:

fever_merge_sort(fn1, fn2, fnout):

that does exactly the same except the the patients must be ordered as follows:

  • Criteria #1: Decreasing order of the average temperature.

  • Criteria #2: Alphabetical order.

For example the call fever_merge_sort('fev1.csv', 'fev2.csv', 'fev1+2ord.csv) should return 10 and create the following file fev1+2ord.csv above.

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

Doctests are available at the fever_merge_sort.test file.


Note

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

The first function:

pat_list(fn):

given fn str with the name of file with patients data in Format A.

returns a list of lists, each with the patient data in Format B.

The second function:

pat_write(L, fnout):

given

  • a list of lists, each with the patient data in Format B.

  • fn, str with the name of file to write patients data in Format A.

does 2 things:

  1. writes a file called fnout with the info in L.

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