def leafCover(self, loc): """ find a leaf node that cover the location """ queue = deque() queue.append(self.root) while len(queue) > 0: curr = queue.popleft() _box = curr.n_box if curr.n_isLeaf is True: if is_rect_cover(_box, loc): return curr else: # if not leaf queue.extend(curr.children)
def get(self, geocast_id): """ Override the standard GET """ global all_data, eps parts = geocast_id.split('/') dataset = parts[0] print parts t = map(float, parts[1].split(',')) print dataset, t # if task not in region if not is_rect_cover(all_data[dataset][1], t): self.write(json.dumps({"error": "invalid task"})) return q, q_log = geocast(all_data[dataset][0], t, float(eps)) no_workers, workers, Cells, no_hops, coverage, no_hops2 = post_geocast(t, q, q_log) performed, worker, dist = performed_tasks(workers, Params.MTD, t, True) x_min, y_min, x_max, y_max = [], [], [], [] worker_counts, utilities, distances, compactnesses, areas = [], [], [], [], [] if worker is not None: worker = worker.tolist() corner_points = Set([]) for cell in Cells: x_min.append(cell[0].n_box[0][0]) y_min.append(cell[0].n_box[0][1]) x_max.append(cell[0].n_box[1][0]) y_max.append(cell[0].n_box[1][1]) worker_counts.append(cell[0].n_count) utilities.append([cell[2][1], cell[2][2]]) compactnesses.append(cell[2][3]) distances.append(float("%.3f" % distance_to_rect(t[0], t[1], cell[0].n_box))) distances.append(float("%.3f" % distance_to_rect(t[0], t[1], cell[0].n_box))) areas.append(float("%.3f" % rect_area(cell[0].n_box))) corner_points = corner_points | rect_vertex_set(cell[0].n_box) points = list(corner_points) x = make_circle(points) if x is not None: cx, cy, r = x print cx, cy, r else: cx, cy, r = 0, 0, 0 no_hops2 = math.ceil(no_hops2) if performed: self.write( json.dumps({"is_performed": performed, "notified_workers": {"no_workers": no_workers, "x_coords": workers[0].tolist(), "y_coords": workers[1].tolist()}, "geocast_query": {"no_cell": len(Cells), "compactness": q_log[-1][3], "x_min_coords": x_min, "y_min_coords": y_min, "x_max_coords": x_max, "y_max_coords": y_max, "worker_counts": worker_counts, "utilities": utilities, "compactnesses": compactnesses, "distances": distances, "areas": areas}, "spatial_task": {"location": t}, "volunteer_worker": {"location": worker, "distance": dist}, "hop_count": no_hops2, "bounding_circle": [cx, cy, r]}, sort_keys=False) ) else: self.write( json.dumps({"is_performed": False, "notified_workers": {"no_workers": no_workers, "x_coords": workers[0].tolist(), "y_coords": workers[1].tolist()}, "geocast_query": {"no_cell": len(Cells), "x_min_coords": x_min, "y_min_coords": y_min, "x_max_coords": x_max, "y_max_coords": y_max, "worker_counts": worker_counts, "utilities": utilities, "compactnesses": compactnesses, "distances": distances, "areas": areas}, "spatial_task": {"location": t}, "volunteer_worker": {"location": worker, "distance": dist}, "hop_count": no_hops2, "bounding_circle": [cx, cy, r]}, sort_keys=False) ) # logging if Params.GEOCAST_LOG: info = GeocastInfo(int(performed), t, Cells) log_str = str(info.logging()) + "\n" geocast_log("geocast_server", log_str, eps)