def detect_stops(dates, network, **param): """ Main function to be run to learn the mixture distribution from the TSpot Input: tspots_data: list of list of TSpot. Each list of TSpot represents a trajectory provided by the PIF network: network object """ learned_mixtures = {} tspots_data = [ttob_seq for date in dates for ttob_seq in pip_fun.getDayTSpotsInterpolated(date, network)] tspots_cut_link = [pip_fun.seqGroupBy(tspots, keyf=lambda tsp:tsp.spot.linkId) for tspots in tspots_data] tspots_groups_per_link = pip_fun.groupby([link_tspots for traj_tspots in tspots_cut_link for link_tspots in traj_tspots], lambda tspots:tspots[0].spot.linkId) for lid, link_obs in tspots_groups_per_link: stopping_obs = ([detect_stops_on_link_traj(traj, **param) if len(traj) >= 2 else None for traj in link_obs]) non_stop_mix = compute_tt_from_tspots( [traj for i, traj in enumerate(link_obs) if stopping_obs[i] is False], lid, network, avg_ff_tt=None, **param) stop_mix = compute_tt_from_tspots( [traj for i, traj in enumerate(link_obs) if stopping_obs[i] is True], lid, network, avg_ff_tt=non_stop_mix[0], **param) mixt_dist = compute_mixture(non_stop_mix, stop_mix, param['non_stopping_default']) learned_mixtures[lid] = mixt_dist return learned_mixtures