def cluster_dict(self): self.tour_dict = [0] * self.num_clusters if not self.data: self.tour_dict = [] self.self_loops_tour_dict = [] return for i in range(self.num_clusters): a = {'sections' : self.clusters[i]} self.tour_dict[i] = a for i in range(self.num_clusters): start_places = [] end_places = [] for t in self.tour_dict[i]["sections"]: start = esdpq.get_place(t.start_place) end = esdpq.get_place(t.end_place) start_places.append(start) end_places.append(end) self.tour_dict[i]["start_places"] = start_places self.tour_dict[i]["end_places"] = end_places for i in range(self.num_locations): bin = self.bins[i] for b in bin: cluster = b[1] label = b[0] self.tour_dict[cluster][label] = i for i in range(self.num_clusters): cluster = self.tour_dict[i] start_coords = self.locs[cluster['start']] end_coords = self.locs[cluster['end']] self.tour_dict[i]['start_coords'] = start_coords self.tour_dict[i]['end_coords'] = end_coords self.self_loops_tour_dict = copy.deepcopy(self.tour_dict) for i in range(len(self.tour_dict)-1, -1, -1): cluster = self.tour_dict[i] if cluster['start'] == cluster['end'] and len(self.tour_dict) > 1: self.tour_dict.remove(cluster) newlocs = [] for cluster in self.tour_dict: if cluster['start'] not in newlocs: newlocs.append(cluster['start']) if cluster['end'] not in newlocs: newlocs.append(cluster['end']) for i in range(len(self.tour_dict)): self.tour_dict[i]['start'] = newlocs.index(self.tour_dict[i]['start']) self.tour_dict[i]['end'] = newlocs.index(self.tour_dict[i]['end'])
def _addIfNotExists(self, place_id): """ Adds the place specified by the given place_id to the place list and the place map and returns it :param place_id: :return: """ import emission.storage.decorations.place_queries as esdp if place_id not in self.id_map: place = esdp.get_place(self.trips[0].start_place) self.places.append(place) self.id_map[place_id] = place return place else: return self.id_map[place_id]
def _addIfNotExists(self, place_id): """ Adds the place specified by the given place_id to the place list and the place map and returns it :param place_id: :return: """ import emission.storage.decorations.place_queries as esdp if place_id not in self.id_map: logging.debug("place id %s is not in the map, searching in database" % place_id) place = esdp.get_place(place_id) self.places.append(place) self.id_map[place_id] = place logging.debug("retrieved object %s and added to id_map" % place) return place else: return self.id_map[place_id]
def _addIfNotExists(self, place_id): """ Adds the place specified by the given place_id to the place list and the place map and returns it :param place_id: :return: """ import emission.storage.decorations.place_queries as esdp if place_id not in self.id_map: logging.debug( "place id %s is not in the map, searching in database" % place_id) place = esdp.get_place(place_id) self.places.append(place) self.id_map[place_id] = place logging.debug("retrieved object %s and added to id_map" % place) return place else: return self.id_map[place_id]