def get_record_with_mac_floorid_and_hour(mac, floor_id, hour): _, mydb = mdb.connect() record_dict = {} for key, value in mydb[floor_id].find_one({"_id" : mac}).items(): if hour in key: record_dict[key] = value return record_dict
def get_record_with_floorid(floor_id): _, mydb = mdb.connect() record_dict = {} cursor = mydb[floor_id].find({}) for document in cursor: record_dict[document["_id"]] = document return record_dict
def delete_danger_zone(): _, mydb = mdb.connect() id_zone = request.args.get('id_zone') mydb["dangerZones"].delete_one({"_id" : id_zone}) return "Done", 200
def get_record_with_mac(mac): _, mydb = mdb.connect() record_dict = {} for collection in mydb.list_collection_names(): collection_data = mydb[collection].find_one({"_id" : mac}) if collection_data: collection_data["_id"] = collection record_dict[collection] = collection_data return record_dict
def get_record_with_floorid_date_and_hour(floor_id, date, hour): _, mydb = mdb.connect() record_dict = {} cursor = mydb[floor_id].find({date + "-" + hour : { "$exists" : True } }) for document in cursor: collection_data = {} collection_data["_id"] = document["_id"] collection_data[date + "-" + hour] = document[date + "-" + hour] record_dict[document["_id"]] = collection_data return record_dict
def get_record_with_mac_and_hour(mac, hour): _, mydb = mdb.connect() record_dict = {} for collection in mydb.list_collection_names(): collection_data = {} for key, value in mydb[collection].find_one({"_id" : mac}).items(): if hour in key: collection_data[key] = value if collection_data: collection_data["_id"] = collection record_dict[collection] = collection_data return record_dict
def get_danger_zones(): _, mydb = mdb.connect() id_zone = request.args.get('id_zone') if id_zone is None: cursor = mydb["dangerZones"].find({}) zones = {} for document in cursor: zones[document["_id"]] = document return jsonify(zones) else: return jsonify(mydb["dangerZones"].find_one({"_id" : id_zone}))
def get_record_with_floorid_and_hour(floor_id, hour): _, mydb = mdb.connect() record_dict = {} cursor = mydb[floor_id].find({}) for document in cursor: collection_data = {} for key, value in document.items(): if hour in key: collection_data[key] = value collection_data["_id"] = document["_id"] if collection_data: record_dict[document["_id"]] = collection_data return record_dict
def get_record_with_date_and_hour(date, hour): _, mydb = mdb.connect() record_dict = {} for collection in mydb.list_collection_names(): collection_data = {} cursor = mydb[collection].find({ date + "-" + hour : { "$exists" : True }}) for document in cursor: document_data = {} document_data["_id"] = document["_id"] document_data[date + "-" + hour] = document[date + "-" + hour] if document_data: collection_data[document_data["_id"]] = document_data if collection_data: record_dict[collection] = collection_data return record_dict
def get_record_with_mac_date_and_hour(mac, date, hour): _, mydb = mdb.connect() record_dict = {} for collection in mydb.list_collection_names(): collection_data = mydb[collection].find_one({"_id" : mac}) if date + "-" + hour in collection_data: data = collection_data[date + "-" + hour] collection_data = {} collection_data[collection] = data else: collection_data = {} if collection_data: collection_data["_id"] = collection record_dict[collection] = collection_data return record_dict
def get_record_with_hour(hour): _, mydb = mdb.connect() record_dict = {} for collection in mydb.list_collection_names(): collection_data = {} cursor = mydb[collection].find({}) for document in cursor: document_data = {} for key, value in document.items(): if hour in key: document_data["_id"] = document["_id"] document_data[key] = value if document_data: collection_data[document_data["_id"]] = document_data if collection_data: record_dict[collection] = collection_data return record_dict
def danger(): _, mydb = mdb.connect() id_zone = request.args.get('id_zone') building = request.args.get('building') floor = request.args.get('floor') data = request.args.get('data') if id_zone is None or building is None or floor is None or data is None: print(id_zone) print(building) print(floor) print(data) return "Error in given data", 400 data = data.split(" ") if len(data) % 4 != 0: return "Error in given data", 400 zone_db = mydb["dangerZones"] zone_data = { "_id" : id_zone, "floor" : floor, "building" : building } for i in range(0, len(data), 4): line = { "start_x" : data[i], "start_y" : data[i + 1], "end_x" : data[i + 2], "end_y" : data[i + 3] } zone_data["line_" + str(i // 4)] = line try: zone_db.insert_one(zone_data) except: return "Zone already exists", 400 return "Done", 200
def modyfy_danger_zone(): _, mydb = mdb.connect() id_zone = request.args.get('id_zone') building = request.args.get('building') floor = request.args.get('floor') data = request.args.get('data') if id_zone is None or building is None or floor is None or data is None: print(id_zone) print(building) print(floor) print(data) return "Error in given data", 400 data = data.split() if len(data) % 4 != 0: return "Error in given data", 400 zone_data = { "_id" : id_zone, "floor" : floor, "building" : building } for i in range(0, len(data), 4): line = { "start_x" : data[i], "start_y" : data[i + 1], "end_x" : data[i + 2], "end_y" : data[i + 3] } zone_data["line_" + str(i)] = line mydb["dangerZones"].find_one_and_update({"_id": id_zone}, {"$set": zone_data}) return "Done", 200
def get_record_with_mac_floorid_date_and_hour(mac, floor_id, date, hour): _, mydb = mdb.connect() record_dict = {} record_dict[date + "-" + hour] = mydb[floor_id].find_one({"_id" : mac})[date + "-" + hour] return record_dict
def get_record_with_mac_and_floorid(mac, floor_id): _, mydb = mdb.connect() record_dict = {} record_dict = mydb[floor_id].find_one({"_id" : mac}) return record_dict
from vainilla import connect_db def getRealTimeLocation(): localtime = time.localtime(time.time()) m = str(localtime[1]) if localtime[1] > 9 else '0' + str(localtime[1]) sec = '00' if localtime[5] < 30 else '30' mins = str(localtime[4]) if localtime[4] > 9 else '0' + str(localtime[4]) hour = str(localtime[3]) if localtime[3] > 9 else '0' + str(localtime[3]) formatTime = hour + ':' + mins + ':' + sec formatDate = m + '/' + str(localtime[2]) + '/' + str(localtime[0]) return formatDate + '-' + formatTime #mydb = pymongo.MongoClient('mongodb://localhost:27017/ternium').vainilla _, mydb = connect_db.connect() while 1: r = requests.get('http://10.190.154.230/api/location/v3/clients', auth=('cmxapi', 'Cmx4p1')) for client in r.json(): print(client['deviceId']) print([ client['locationCoordinate']['x'], client['locationCoordinate']['y'] ]) collection = mydb[client['locationMapHierarchy']] doc = collection.find_one({'_id': client['deviceId']}) try: