.. module:: transit Transit Frequencies =================== A company specialized in managing large shopping malls aims at avoiding crowded areas anywhere in the mall in order to comply with customers security standards. To that aim it is interested on an information system for automatic detection of areas in the mall where the customers transit is high. The system projected is composed of the following subsystems: - *The Sensors Network*: A number of sensors properly distributed throughout the sections in the mall where customers are passing. - *the Customers App*: An app installed in all customers mobile phones that will send a signal to the sensor when the customer enters that section. - *The Information System*: It gets information about the routes taken by each customer that visited the mall. This information is stored in the so-called **trajectory dictionary** where: - The key is the *Customer Id* (:class:`str`) - The value is a list of the sensor points (each point is represented as an :class:`int`) for which the customer has passed. Every pair of consecutive points determines a *section*. See the example below. The first entry in the dictionary ``trajD`` says that the customer associated with the ``'H11'`` has walked from point 1 to 5, and then from 5 o 7 and from 7 to 9 and so on. .. literalinclude:: gen_transitD.test :language: python :start-after: --iniex :end-before: --fiex Now, we define a **transit dictionary** as a :class:`dict` where: - The key is a :class:`tuple` with pair of points ``(i, j)`` where ``i < j`` determining a *section*. - The corresponding value is *transit index* of that section, namely the number of times that a customer passed through that section **either way** (hence walking from ``i`` to `j` and from `j` to `i` are both counted under the key ``(i, j)``. Given our purpose and this available information, please implement the following Python functions in the :mod:`transit` module (:file:`transit.py` file) the following functions. The first function is: .. py:function:: gen_transitD(trajD) such that **given** ``trajD``, :class:`dict`, a *trajectory dictionary* as described above **returns** a :class:`dict` with the *transit dictionary* corresponding to ``trajD`` as defined above For example, given the previous input, the outputs produced should be: .. literalinclude:: gen_transitD.test :language: python :start-after: --ini-res :end-before: --fi-res Doctests are available at the :download:`gen_transitD.test ` file. -------------------------------------------------------------------------------------------------------------- The second function is: .. py:function:: gen_high_transitL(trajD, n) such that **given** - a *transit dictionary* as described above - ``n`` a :class:`int` , ``n >= 0`` **returns** a :class:`list` with all sections where the transit has been higher than `n`. The section in this list must be decreasingly ordered by the *transit index* of the section. Those with the same index must be increasingly ordered by the points of the section (the first one first and the second for those who have the same first point). For example, given the dictionary .. literalinclude:: gen_high_transitL.test :language: python :start-after: --ini-ex :end-before: --fi-ex the function should return .. literalinclude:: gen_high_transitL.test :language: python :start-after: --ini-res :end-before: --fi-res Doctests are available at the :download:`gen_high_transitL.test ` file.