.. module:: fever 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 (:class:`str` with name and two last names separated by space ``' '``) - a variable number of temperature measures (:class:`float`) The file :download:`fev1.csv ` and :download:`fev2.csv ` are examples: .. literalinclude:: fev1.csv :language: python .. literalinclude:: fev2.csv :language: python **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 (:class:`float`) - the first last name of the patient (:class:`str`) - the second last name of the patient (:class:`str`) - the first name of the patient (:class:`str`) - a variable number of temperature measures (:class:`float`) The file :download:`fev1+2.csv ` is an example: .. literalinclude:: fev1+2.csv :language: python Implement the following Python functions in the module :mod:`fever` (file :file:`fever.py`): The first function is: .. py:function:: fever_merge(fn1, fn2, fnout): **given** ``fn1``, ``fn2``, ``fnout``, three :class:`str` with textfile names, where ``fn1``, ``fn2`` are names of files with patients data in *Format A*. does two things: #. **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. #. **returns** an :class:`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 :download:`fev1+2.csv ` above. Doctests are available at the :download:`fever_merge.test ` file. ------------------------------------------------------------------------------------------------------------- The second function is: .. py:function:: 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 :download:`fev1+2ord.csv ` above. .. literalinclude:: fev1+2ord.csv :language: python Doctests are available at the :download:`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: .. py:function:: pat_list(fn): **given** ``fn`` :class:`str` with the name of file with patients data in *Format A*. **returns** a :class:`list` of lists, each with the patient data in *Format B*. The second function: .. py:function:: pat_write(L, fnout): **given** - a :class:`list` of lists, each with the patient data in *Format B*. - ``fn``, :class:`str` with the name of file to write patients data in *Format A*. does 2 things: #. **writes** a file called fnout with the info in ``L``. #. **returns** an :class:`int` with the number of patients processed i.e. the number of patients in the output file.