def get_components(graph): if graph.number_of_nodes() > 5: # try: for cluster in clusterUsingMCLClustering(graph): yield cluster # except: yield graph.nodes() else: yield graph.nodes()
def iterateSpots(): locationsToCheck = set(list(locationsForUsIterator(minUniqueUsersCheckedInTheLocation))) graph = nx.Graph() for e in locationToLocationCollection.find(): d = e['_id'].split() l1, l2 = ' '.join(d[:2]), ' '.join(d[2:]) if l1 in locationsToCheck and l2 in locationsToCheck and e['d']<=graphNodesDistanceInMiles: graph.add_edge(l1.replace(' ', '_'), l2.replace(' ', '_'), {'w': e['u']}) for locations in nx.connected_components(graph): if len(locations)>=minimumLocationsPerSpot: clusters = clusterUsingMCLClustering(graph.subgraph(locations), inflation=20) print graph.subgraph(locations).number_of_nodes(), graph.subgraph(locations).number_of_edges(), len(clusters) for cluster in clusters: if len(cluster)>=minimumLocationsPerSpot: yield getKMLForCluster([c.replace('_', ' ') for c in cluster])