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 (:class:`float`). - The patient's name of the patient (:class:`str`). - A variable number of temperature measures (:class:`float` rounde to 1 decimal). The file :download:`patients.csv ` is an example: .. literalinclude:: patients.csv :language: python 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: #. The temperatures below the threshold must be deleted. #. The average temperatures must be recalculated accordingly. #. The patiens with all temperatures below the threshold must be deleted. To this purpose please implement the following Python function in the module :mod:`pat_temp` (file :file:`pat_temp.py`): The first function is: .. py:function:: filter_pat_temp(fn, fnout, tempth) such that **given** - ``fn``, ``fnout``, :class:`str` with textfile names with patients data in the format described above. - ``tempth``, :class:`float`. does two things: #. **writes** a file named ``fnout`` resulting from filtering the temperatures by the threshold ``tempth`` in the way described above. #. **returns** an :class:`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: .. literalinclude:: patients-380.ref :language: python Doctests are available at the :download:`filter_pat_temp.test ` file and the files used in those tests area available at :download:`patients-380.ref `, :download:`patients-390.ref `, :download:`patients-393.ref `, :download:`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 :class:`list` of :class:`str` representing patient temperatures. - ``tempth`` a :class:`float` representing a temperature threshold. **returns** a :class:`list` of the temperatures in ``tempL`` converted to :class:`float` such that a greater or equal than ``tempth``. The second function would be: ``convert_tempL(tempL)`` **given** - ``tempL`` a :class:`list` of :class:`float` representing patient temperatures. **returns** - a :class:`list` of :class:`str` with the temperatures of ``tempL`` in the same order converted to :class:`str`.