def __init__(self, alias): self.backend_id = get_backend_id_by_name("DS1") try: self.KB = DKB.get_by_alias(alias) except Exception: self.KB = DKB() self.KB.cloud_backend_id = self.backend_id self.KB.make_persistent(alias="DKB") self.objectsDKB = DKB.get_by_alias(alias) self.backend_id = get_backend_id_by_name("DS1")
def analyze_pollution(input_path, output_file): import os import uuid pollution_file_name = "pollution_" + str( uuid.uuid4()).split("-")[-1] + ".csv" if os.path.exists(pollution_file_name): os.remove(pollution_file_name) from CityNS.classes import Event, Object, EventsSnapshot, DKB kb = DKB.get_by_alias("DKB") obj_refs = set() i = 0 with open(pollution_file_name, "w") as f: f.write("VehID, LinkID, Time, Vehicle_type, Av_link_speed\n") for snap in kb.kb: for obj_ref in snap.objects_refs: if obj_ref not in obj_refs: obj_refs.add(obj_ref) obj = Object.get_by_alias(obj_ref) obj_type = obj.type if obj_type in ["car", "bus"]: obj_type = obj_type.title() elif obj_type == "truck": obj_type = "HDV" else: continue for event in obj.events_history: f.write( f"{obj_ref}, {20939 + i % 2}, {event.timestamp}, {obj_type}, 50\n" ) # TODO: link_id # needs to be obtained from object i += 1 os.system( f"Rscript --vanilla /home/nvidia/CLASS/class-app/phemlight/PHEMLight_advance.R {input_path} $PWD/{pollution_file_name}" f" {output_file}") # TODO: R script path is hardcoded
def main(): try: KBob = DKB.get_by_alias("DKB") except Exception: KBob = DKB() KBob.make_persistent(alias="DKB") minutes_to_sleep = 15 while True: print("Checking Events Snapshot received...") kb = KBob.kb last_timestamp = 0 if len(kb) > 0: last_timestamp = next(reversed(sorted(list(kb.keys())))) print( f"Number of snapshots {len(list(kb.keys()))} and number of objects {len(list(KBob.objects.keys()))} and " f"last timestamp {last_timestamp}") """ for timestamp in list(kb.keys()): ts = timestamp eventSnap = kb[timestamp] current_snap_alias = eventSnap.snap_alias print("Snapshot " + current_snap_alias + " found.") for event in eventSnap.events: obj = event.detected_object print(obj) print("#################") """ time.sleep(minutes_to_sleep * 60) if len(kb) > 0: KBob.remove_old_snapshots_and_objects(last_timestamp, False)
def __init__(self, alias="DKB"): print("in DataclayObjectManager.__init__") self.backend_id = get_backend_id_by_name("DS1") try: self.KB = DKB.get_by_alias(alias) except Exception: self.KB = DKB() self.KB.cloud_backend_id = self.backend_id self.KB.make_persistent(alias="DKB")
def main(): import sys import time from dataclay.api import init, register_dataclay, finish from dataclay.exceptions.exceptions import DataClayException init() from CityNS.classes import DKB # register_dataclay("192.168.7.32", 11034) try: DKB.get_by_alias("DKB") except DataClayException: DKB().make_persistent("DKB") start_time = time.time() execute_trackers() print("ExecTime: " + str(time.time() - start_time)) print("Exiting Application...") finish()
def main(): import sys import time from dataclay.api import init, finish from dataclay.exceptions.exceptions import DataClayException mqtt_wait = False if len(sys.argv) == 2: mqtt_wait = (sys.argv[1] != "False") init() from CityNS.classes import DKB, ListOfObjects # Register MQTT client to subscribe to MQTT server in 192.168.7.42 if mqtt_wait: client = register_mqtt() client.loop_start() # initialize all computing units in all workers num_cus = 8 for i in range(num_cus): init_task() compss_barrier() # Publish to the MQTT broker that the execution has started if mqtt_wait: publish_mqtt(client) try: kb = DKB.get_by_alias("DKB") except DataClayException: kb = DKB() list_objects = ListOfObjects() list_objects.make_persistent() kb.list_objects = list_objects kb.make_persistent("DKB") start_time = time.time() # execute_trackers(["192.168.50.103"], kb) execute_trackers([("/tmp/pipe_yolo2COMPSs", "/tmp/pipe_COMPSs2yolo")], kb) # pipe_paths = [("/tmp/pipe_yolo2COMPSs", "/tmp/pipe_COMPSs2yolo"), ("/tmp/pipe_write", "/tmp/pipe_read")] # print("ExecTime: " + str(time.time() - start_time)) # print("ExecTime per Iteration: " + str((time.time() - start_time) / NUM_ITERS)) if mqtt_wait: while CD_PROC < NUM_ITERS: pass print("Exiting Application...") finish()
def __init__(self, alias="DKB"): print("in DataclayObjectManager.__init__") self.backend_id = get_backend_id_by_name("DS1") print("1") try: print(2) self.KB = DKB.get_by_alias(alias) print(3) except Exception: print(4) self.KB = DKB() print(5) self.KB.cloud_backend_id = self.backend_id print(6) self.KB.make_persistent(alias="DKB") print(7) print("after DataclayObjectManager.__init__")
def persist_info(trackers, count, dummy): import uuid from dataclay.exceptions.exceptions import DataClayException init() from CityNS.classes import Event, Object, EventsSnapshot, DKB kb = DKB.get_by_alias("DKB") classes = ["person", "car", "truck", "bus", "motor", "bike", "rider", "traffic light", "traffic sign", "train"] snapshot_alias = "events_" + str(count) snapshot = EventsSnapshot(snapshot_alias) print(f"Persisting {snapshot_alias}") snapshot.make_persistent(alias=snapshot_alias) objects = [] # dataclay_cloud = register_dataclay("192.168.7.32", 11034) for index, tracker in enumerate(trackers): vel_pred = tracker.predList[-1].vel if len(tracker.predList) > 0 else -1.0 yaw_pred = tracker.predList[-1].yaw if len(tracker.predList) > 0 else -1.0 lat, lon = pixel2GPS(tracker.traj[-1].x, tracker.traj[-1].y) event = Event(uuid.uuid4().int, int(datetime.now().timestamp() * 1000), float(lon), float(lat)) print(f"Registering object alias {tracker.id}") object_alias = "obj_" + str(index) try: event_object = Object.get_by_alias(object_alias) except DataClayException as e: event_object = Object(tracker.id, classes[tracker.cl], vel_pred, yaw_pred) print(f"Persisting {object_alias}") event_object.make_persistent(alias=object_alias) event_object.add_event(event) # event_object.federate(dataclay_cloud) snapshot.add_object_refs(object_alias) objects.append(event_object) kb.add_events_snapshot(snapshot) # trigger_openwhisk(snapshot_alias) """ try: snapshot.federate(dataclay_cloud) except DataClayException as e: print(e) """ return dummy, objects, snapshot
event = Event() event.initialize(eventObject, row["timestamp"], float(row["speed"]), float(row["yaw"]), float(row["lon"]), float(row["lat"]), row['x'], row['y'], row['w'], row['h']) eventObject.geohash = row["geohash"][0:7] eventsSnapshot.timestamp = row["timestamp"] eventsSnapshot.add_event(event) eventObject.add_event(event) # import pdb;pdb.set_trace() eventsSnapshot.make_persistent("events_" + str(name)) KB.add_events_snapshot(eventsSnapshot) if __name__ == "__main__": try: # import pdb;pdb.set_trace() KB = DKB.get_by_alias("DKB") # KB.reset_dkb() except Exception: KB = DKB() # KBob.cloud_backend_id = backend_id KB.make_persistent(alias="DKB") # import pdb;pdb.set_trace() createDCObjects(KB) finish() exit(0)