class DataclayObjectManager: KB = None 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 getAllObjects(self): # import pdb;pdb.set_trace() return self.KB.get_objects(events_length_max=QUAD_REG_LEN_DICT, events_length_min=QUAD_REG_MIN_DICT) def getObject(self, oid): obj_id, class_id = oid.split(":") obj_id = uuid.UUID(obj_id) class_id = uuid.UUID(class_id) return getRuntime().get_object_by_id(obj_id, hint=self.backend_id, class_id=class_id) def storeResult(self, obj, fx, fy, ft, tp_timestamp, frame_tp): obj.add_prediction(fx,fy,ft, tp_timestamp, frame_tp) def getResult(self, oid): obj = self.getObject(oid) return obj.trajectory_px, obj.trajectory_py, obj.trajectory_pt
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)
class DataclayObjectManager: KB = None 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 get_dummy_objects(self): return [42] # return [['cbe71526-d6bd-435e-a989-83152aa11fe1:9c928e62-75e6-4e19-a5d3-5a465f06c9f3', [], [], [], 'dnpz7ck', [[35.031355404187224, 35.031352428636616, 35.031350444100944, 35.03134904392341, 35.031347991189904, 35.03134714609026, 35.031359071211966, 35.03136996353651, 35.031377201183496, 35.03138157725674, 35.0313841908153, 35.03138589644434, 35.031388673149465, 35.031390453384425, 35.03139001789305, 35.03139147862476, 35.0313923821388, 35.03139294286909, 35.03137328746597, 35.031383245337736, 35.03136961404745, 35.03138078235282, 35.031387682265766, 35.03139177380347, 35.0313940679391, 35.031394127084155, 35.03139408957237, 35.03139401477817, 35.031393921003044, 35.031393812347424, 35.031393688759835, 35.031393549036835, 35.031391826434934, 35.0313922160606, 35.03139236920287, 35.03139235917077, 35.03139327282966, 35.03139377323227, 35.03137688555011, 35.031364597121055], [-78.93070694989784, -78.93070416833498, -78.93070250784389, -78.9307014219754, -78.93070060866096, -78.93069990244442, -78.93071352067842, -78.93072559270428, -78.93073264134397, -78.93073564687593, -78.93073664603195, -78.93073689390744, -78.9307377505122, -78.93073790926208, -78.93073696668392, -78.93073725845566, -78.93073724966709, -78.93073711262944, -78.93072040093806, -78.93072782937313, -78.9307162895327, -78.93072484764825, -78.93072995611352, -78.93073285346166, -78.93073438151778, -78.93073479603959, -78.93073508230964, -78.93073528413723, -78.9307354197485, -78.93073549959415, -78.93073553128248, -78.93073552083315, -78.93073474314168, -78.93073502422342, -78.93073511200889, -78.9307350691187, -78.9307352389141, -78.93073517996584, -78.93072147725161, -78.93071154473795], [1622024047624, 1622024047664, 1622024047704, 1622024047744, 1622024047784, 1622024047824, 1622024047864, 1622024047904, 1622024047944, 1622024047984, 1622024048024, 1622024048064, 1622024048104, 1622024048144, 1622024048184, 1622024048224, 1622024048264, 1622024048304, 1622024048344, 1622024048384, 1622024048424, 1622024048464, 1622024048504, 1622024048544, 1622024048584, 1622024048624, 1622024048664, 1622024048704, 1622024048744, 1622024048784, 1622024048824, 1622024048864, 1622024048904, 1622024048944, 1622024048984, 1622024049024, 1622024049064, 1622024049104, 1622024049144, 1622024049184]], '2405_14', 283, 27, 20]] def getAllObjectsIDs(self): res = [] for obj in self.getAllObjects(): res.append((obj[0], obj[7])) return res def getAllObjects(self): res = [] objects = self.KB.get_objects(events_length_max=QUAD_REG_LEN_DICT, events_length_min=QUAD_REG_MIN_DICT) for obj in objects: lobj = list(obj) lobj[5] = [list(obj[5][0]), list(obj[5][1]), list(obj[5][2])] res.append(lobj) return res def getObject(self, oid): obj_id, class_id = oid.split(":") obj_id = uuid.UUID(obj_id) class_id = uuid.UUID(class_id) return getRuntime().get_object_by_id(obj_id, hint=self.backend_id, class_id=class_id) def storeResult(self, obj, fx, fy, ft, tp_timestamp, frame_tp): print( f"converting to regular lists? {type(fx)} {type(fy)} {type(ft)} ") obj.add_prediction(fx, fy, ft, tp_timestamp, frame_tp) def getResult(self, oid): obj = self.getObject(oid) return obj.trajectory_px, obj.trajectory_py, obj.trajectory_pt
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_task(): import uuid from CityNS.classes import DKB, Event, Object, EventsSnapshot, ListOfObjects, FederationInfo kb = DKB() kb.make_persistent("FAKE_" + str(uuid.uuid4())) kb.get_objects_from_dkb() snap = EventsSnapshot("FAKE_SNAP_" + str(uuid.uuid4())) snap.make_persistent("FAKE_SNAP_" + str(uuid.uuid4())) snap.get_objects_refs() event = Event(None, None, None, None, None, None, None) event.make_persistent("FAKE_EVENT_" + str(uuid.uuid4())) obj = Object("FAKE_OBJ_" + str(uuid.uuid4()), "FAKE", 0, 0, 0, 0) obj.make_persistent("FAKE_OBJ_" + str(uuid.uuid4())) obj.get_events_history(20) list_objs = ListOfObjects() list_objs.make_persistent("FAKE_LISTOBJ_" + str(uuid.uuid4())) list_objs.get_or_create("FAKE_LISTOBJ_" + str(uuid.uuid4()), "FAKE", 0, 0, 0, 0) federation_info = FederationInfo([snap]) federation_info.make_persistent() federation_info.objects_per_snapshot # to load dataclay class and libraries
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)
class DataclayObjectManager: objectsDKB = None 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 get_dummy_objects(self): return [([ 35.03100107347143, 35.03101945302576, 35.03104596715896, 35.03108061587101, 35.03112339916193 ], [ -78.93056656648699, -78.93057797939056, -78.93059476964628, -78.93061693725413, -78.93064448221412 ], [ 1622024043464, 1622024044464, 1622024045464, 1622024046464, 1622024047464 ], 'dnpz7ch', '2405_11', 'car', 309)] def getAllObjects(self, with_tp=True, connected=None, with_event_history=False): return self.objectsDKB.get_objects([], False, with_tp, connected) def getAllObjectsIDs(self): res = [] for obj in self.objectsDKB.get_objects([], False, True, False): obj_id = getRuntime().get_object_id_by_alias(obj[4]) class_id = 'b79a0fd1-ac91-41fe-b5c6-ff0a5b993a83' # obj_id = uuid.UUID(obj_id) # class_id = uuid.UUID(class_id) # res.append(f'{str(obj_id)}:{class_id}') # res.append(obj[4]) print(res) return [ '0bd030a1-b220-451b-91e2-491e440e9824:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '6c2cfffd-305c-4fcc-a17a-617a87e132c8:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '6bbff6d3-1717-4d2d-a3e4-b10323b13114:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '34082340-8c92-4d20-ad89-06e82c73ad84:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '2d7d973c-843c-447a-bc74-7875baafd9c0:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'b1dd4284-151b-4450-9fa3-512e10dbe8d4:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'facbae07-3ace-4f37-8842-456e4cd8690e:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'd4b23a92-00c3-4c2b-88f0-53db534d4996:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'fb480175-5760-47f8-b5e3-cf84086b5a0b:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'a10d0c53-9fba-4bfa-bf5b-1149f2b7d241:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'fd12a19f-d166-47fe-9554-51bcd62cbe32:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'ce7dc91c-d19e-420d-af9f-688b39f4095f:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'b5c76764-6063-47c0-8beb-478f5e54d722:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '342c1146-2a9c-4b10-886e-600a46eb8657:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '68d921fc-2e5d-4aff-882e-34a4ca2ed674:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '9dc4914b-0894-4a21-a9fa-e10648830c42:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'f238215c-785a-4ded-86d7-eda82104ef86:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '326b6e4d-d6cc-421a-88f0-7a8d2afad3ea:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '3023b5ea-8000-40a1-8924-d5548005d294:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', 'da54ed26-580a-49f5-83a5-f998aa3e3c19:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c', '4aba55b7-d7a7-4b15-b280-7788504d6567:649420f0-98bb-4a7f-b9e9-cfb3a5d1683c' ] def getObject(self, oid): obj_id, class_id = oid.split(":") obj_id = uuid.UUID(obj_id) class_id = uuid.UUID(class_id) return getRuntime().get_object_by_id(obj_id, hint=self.backend_id, class_id=class_id) def alertCollision(self, v_main, v_other, col): print(f"----------------------------------------") print(f"WARNING!!! Possible collision detected") print(f" v_main: {v_main} v_other: {v_other}") print(f" x: {col[0]} y: {col[1]} t: {col[2]}") print(f"----------------------------------------")