This Python script analyses LEGION per-entity output, recording when one or more tracked entities come within a specified distance (e.g.;one metre, one-&-a-half metres, or two metres) of any of their neighbours. LEGION per-entity data should be saved as comma-separated values (*.CSV), rather than extensible markup language (*.XML), and contain:
The script then loads all the CSV data at once, splits them into individual time steps and analyses them all. Given an Entity ID to track, it looks for that entity in each time step and if it finds it, performs a distance check against all of its neighbours. If any entities are closer than the specified distance limit, their details (ID, distance, origin, destination, etc.) are recorded. This output is then saved as a Python data structure that can be loaded in a different session for further analysis. It is then also possible to re-filter this data with a stricter distance limit, find the total time the tracked entity was in contact with each of its neighbours, and more.
The script can also be run for a range of different IDs, or a specified number of randomly sampled IDs. This is equivalent to the above procedure being repeated multiple times. A utility function also allows the user to export the Accessible Space boundaries from a LEGION Model (*.LGM) file. This is needed so that, during the distance check, entities on opposite sides of thin walls are not mistakenly counted as being too close to each other.