def create_aggregated(steps, dataset): paths: Dict[str, List[List['Step']]] = preprocess_data(steps, dataset, 60) compute_avg_length(paths) print('Parsing places and flows...') [places, flows] = get_supergraph(paths, dataset) print('Number of users:', len(flows)) people_count = get_people_count(places) flow_magnitude = get_flow_magnitude(flows) print('Number of places:', len(people_count), '\tNumber of flows:', len(flow_magnitude)) cluster_places: List['ClusterPlace'] = [] cluster_flows: List['ClusterFlow'] = [] radius_meter, min_measures = 300, 15 print('Creating clusters with radius', radius_meter, 'm and at least', min_measures, 'points...') (cplaces, cflows) = get_clusters(places, flows, radius_meter, min_measures) if len(cflows) > 0: cluster_places = filter_clusters(cplaces, cflows) cluster_flows = cflows print('Post-filtering number of ClusterPlace:', len(cluster_places), '\tNumber of ClusterFlow:', len(cluster_flows), '\n') clusters_gjson = create_geojson_clusters(cluster_places) print('Exporting data to', gjson_dir_path + options.date + '_aggplaces.geojson...') ClusterPoint.export(clusters_gjson, gjson_dir_path + options.date + "_aggplaces.geojson") flows_gjson = create_geojson_lines(cluster_flows) print('Exporting data to', gjson_dir_path + options.date + '_aggflows.geojson...') ClusterLine.export(flows_gjson, gjson_dir_path + options.date + "_aggflows.geojson")
def create_filtered(steps, dataset): paths: Dict[str, List[List['Step']]] = preprocess_data(steps, dataset, 60) compute_avg_length(paths) print('Parsing places and flows...') [places, flows] = get_supergraph(paths, dataset) print('Number of users:', len(flows)) people_count = get_people_count(places) flow_magnitude = get_flow_magnitude(flows) print('Number of places:', len(people_count), '\tNumber of flows:', len(flow_magnitude)) cluster_places: List['ClusterPlace'] = [] for p in places: cluster_places.append(ClusterPlace(42, p.lon, p.lat, weight=1)) cluster_flows: List['ClusterFlow'] = [] for user_flow in flows: for f in user_flow: cluster_flows.append( ClusterFlow(42, 53, f.coord_first, f.coord_last, mag=1)) clusters_gjson = create_geojson_clusters(cluster_places) print('Exporting data to', gjson_dir_path + options.date + '_filteredplaces.geojson...') ClusterPoint.export( clusters_gjson, gjson_dir_path + options.date + "_filteredplaces.geojson") flows_gjson = create_geojson_lines(cluster_flows) print('Exporting data to', gjson_dir_path + options.date + '_filteredflows.geojson...') ClusterLine.export( flows_gjson, gjson_dir_path + options.date + "_filteredflows.geojson")
def export_gjson(cluster_places, cluster_flows, src: str, thresh): clusters_gjson = create_geojson_clusters(cluster_places) print( 'Exporting data to', gjson_dir_path + src + '_' + str(thresh) + '_clusterplaces.geojson...') ClusterPoint.export( clusters_gjson, gjson_dir_path + src + '_' + str(thresh) + "_clusterplaces.geojson") flows_gjson = create_geojson_lines(cluster_flows) print( 'Exporting data to', gjson_dir_path + src + '_' + str(thresh) + '_clusterflows.geojson...') ClusterLine.export( flows_gjson, gjson_dir_path + src + '_' + str(thresh) + "_clusterflows.geojson")
# Computing minimum agony and corresponding ranks print('\nComputing minimum agony and corresponding ranks for A-B graph...') graph_agony = 0 for arc in sorted(arcs_AtoB, key = lambda k: k.weight, reverse = True): # Arcs sorted by weight for optimization arc.compute_agony(base_stations_AtoB) graph_agony += arc.agony print('... Done. Graph agony:', graph_agony) print('\nComputing minimum agony and corresponding ranks for B-A graph...') graph_agony = 0 for arc in sorted(arcs_BtoA, key = lambda k: k.weight, reverse = True): # Arcs sorted by weight for optimization arc.compute_agony(base_stations_BtoA) graph_agony += arc.agony print('... Done. Graph agony:', graph_agony) # Exporting to GeoJSON files bs_geojson = create_geojson_points(base_stations_AtoB) print('Exporting data to', gjson_dir_path+'pointsAB.geojson...') BSPoint.export(bs_geojson, gjson_dir_path + "pointsAB.geojson") al_geojson = create_geojson_lines(arcs_AtoB) print('Exporting data to', gjson_dir_path+'arclinesAB.geojson...') ArcLine.export(al_geojson, gjson_dir_path + "arclinesAB.geojson") bs_geojson = create_geojson_points(base_stations_BtoA) print('Exporting data to', gjson_dir_path+'pointsBA.geojson...') BSPoint.export(bs_geojson, gjson_dir_path + "pointsBA.geojson") al_geojson = create_geojson_lines(arcs_BtoA) print('Exporting data to', gjson_dir_path+'arclinesBA.geojson...') ArcLine.export(al_geojson, gjson_dir_path + "arclinesBA.geojson")