def registerFlight(): session = request.environ.get("beaker.session") username = session["username"] tailId = request.json["tailId"] flightDate = datetime.datetime.strptime(request.json["departure"], "%m/%d/%Y %I:%M %p") departTz = pytz.timezone(request.json["timezone"]) localized = departTz.localize(flightDate) normalized = localized.astimezone(pytz.utc) obj = { "tailId": tailId, "departureTime": normalized, "departureStr": flightDate.strftime("%Y-%m-%d %H:%M"), "departureDay": normalized.strftime("%Y-%m-%d"), "status": "INIT", "searchCount": 0, "user": username, } emuDb = mongoConnect("localhost", 27017, "emu", "accounts") result = emuDb.find_one({"username": username}, {"_id": 0}) result["flights"].append(obj) emuDb.update( {"username": username}, {"$set": {"flights": result["flights"], "lastActive": datetime.datetime.now()}} ) preflight = mongoConnect("localhost", 27017, "emu", "preflights") preflight.insert(obj) return {"success": True}
def kafka_consumer(): #Path of the classes file path_names = 'data/YOLO/rehoboam.names' #Path of the Avro scheme path_avro = "data/scheme.avsc" #Read the class file and transform in dictionary with open(path_names) as f: names_dict = {i: line.split('\n')[0] for i,line in enumerate(f)} #Connection to the Mongo collection to write in mongo_collection = mongoConnect() #Load the tf model saved_model_loaded = tf.saved_model.load( config['weights_tf'], tags=[tag_constants.SERVING]) infer = saved_model_loaded.signatures['serving_default'] #logging.basicConfig(level=logging.INFO) #Read the Avro schema and create the Kafka consumer schema = avro.schema.parse(open(path_avro, "r").read()) reader = DatumReader(schema) consumer = KafkaConsumer('input_image', bootstrap_servers=['localhost:9094', 'localhost:9095'], group_id="rehoboam", value_deserializer=lambda m: decode_avro(m, reader)) for msg in consumer: #Inicialize a dictionary with the class and the number of apperence to 0 default_document = {i: 0 for i in sorted(names_dict.values(), key=lambda x: x)} #Transform the bytes to image img = io.BytesIO(msg.value['image']) img_pil = Image.open(img) img_cv2 = np.array(img_pil) #Call the model to detect the classes scores, classes = detect( parameters=config, infer_model=infer, image=img_cv2) real_classes = [i for i,j in zip(classes[0], scores[0]) if j > 0.0] unique, count = np.unique(real_classes, return_counts=True) result_dict = {names_dict[i]: int(j) for i,j in zip(unique, count)} #Store the number of incidences in the default dictionary for k,v in result_dict.items(): default_document[k] = v result = { 'district_id': int(msg.value['district']), 'camera_id': int(msg.value['camera']), 'timestamp': datetime.now(), 'results': default_document } #Save it in Mongo mongo_collection.insert_one(result).inserted_id consumer.commit()
def showFlights(): session = request.environ.get("beaker.session") username = session["username"] flights = [] emuDb = mongoConnect("localhost", 27017, "emu", "accounts") result = emuDb.find_one({"username": username}, {"_id": 0}) for flight in result["flights"]: if flight["departureTime"] > datetime.datetime.now(): flights.append(flight) flights.sort(key=lambda x: x["departureStr"]) return {"flights": flights}
def showAccount(): session = request.environ.get('beaker.session') username = session['username'] emuDb = mongoConnect("localhost", 27017, "emu", "accounts") result = emuDb.find_one( {'username':username}, {'_id':0}) obj = { 'username': result['username'], 'firstActive': result['firstActive'].strftime('%Y-%m-%d %H:%M'), 'lastActive': result['lastActive'].strftime('%Y-%m-%d %H:%M') } return { 'account': obj }
input_topic = "input_image" topic_list = [] consumer = KafkaConsumer( bootstrap_servers=['localhost:9094', 'localhost:9095'], group_id="rehoboam") if input_topic not in consumer.topics(): topic_list.append( NewTopic(name=input_topic, num_partitions=2, replication_factor=2)) admin_client.create_topics(new_topics=topic_list, validate_only=False) # Font for the html style font = 'Arial' # Connection to the Mongo collection to write in mongo_col = mongoConnect() # Read the class file and transform in dictionary with open(path_names) as f: names_dict = {i: line.split('\n')[0] for i, line in enumerate(f)} # Read the CSV file with the data of the cameras and transform it to Pandas dataframe cameras_df = pd.read_excel(path_data, sheet_name='cameras') cameras_df = cameras_df.set_index('id_district', drop=True) cameras_df = cameras_df[cameras_df['readable'] == 1] # Malaga's university logo UMA_LOGO = "https://www.uma.es/servicio-comunicacion/navegador_de_ficheros/Marcas-UMA/descargar/Marca%20Universidad%20de%20M%C3%A1laga/marcauniversidaddemalagaVERTICAL.png" # ============================================================================== # Forms menus