def get_latest_by_lat_long(self): with app.app_context(): latest_db_records = [] bike_details = mongo.db.BikeData pipeline = [{ u"$group": { u"_id": { u"lat": u"$lat", u"long": u"$long" } } }] bike_all = dumps(bike_details.aggregate(pipeline)) bike_all = json.loads(bike_all) for i in range(len(bike_all)): query = {} query["lat"] = bike_all[i]['_id']['lat'] query["long"] = bike_all[i]['_id']['long'] temp = json.loads( dumps( bike_details.find(query).sort( "_id", pymongo.DESCENDING).limit(1))) if temp[0]['available_bikes'] == 16: # cache.set("isAlertPresent", True, timeout=None) notifier = Notifier() notifier.dispatch_notification("test notification", "to-admin") newDict = {} newDict['lat'] = temp[0]['lat'] newDict['long'] = temp[0]['long'] newDict['type'] = 'bike' newDict['status'] = 'New' newDict['timestamp'] = str(datetime.datetime.now()) AlertsDataInteractions().insert_alerts(newDict) latest_db_records.append(temp[0]) return latest_db_records
def get_alerts(self): with app.app_context(): latest_db_records = [] alerts_details = mongo.db.Alerts pipeline = [{ u"$group": { u"_id": { u"lat": u"$lat", u"long": u"$long" } } }] alerts_all = dumps(alerts_details.aggregate(pipeline)) alerts_all = json.loads(alerts_all) for i in range(len(alerts_all)): query = {} query["lat"] = alerts_all[i]['_id']['lat'] query["long"] = alerts_all[i]['_id']['long'] temp = json.loads( dumps( alerts_details.find(query).sort( "_id", pymongo.DESCENDING).limit(1))) latest_db_records.append(temp[0]) return latest_db_records
def get_latest_by_lat_long(self): with app.app_context(): latest_db_records = [] pollution_details = mongo.db.BreezoMeter pipeline = [{ u"$group": { u"_id": { u"lat": u"$lat", u"long": u"$long" } } }] poll_all = dumps(pollution_details.aggregate(pipeline)) poll_all = json.loads(poll_all) for i in range(len(poll_all)): query = {} query["lat"] = poll_all[i]['_id']['lat'] query["long"] = poll_all[i]['_id']['long'] temp = json.loads( dumps( pollution_details.find(query).sort( "_id", pymongo.DESCENDING).limit(1))) latest_db_records.append(temp[0]) return latest_db_records
def get_latest_analysis_data_by_lat_long(self): with app.app_context(): latest_db_records = [] traffic_details = mongo.db.TrafficAnalysisData pipeline = [{ u"$group": { u"_id": { u"lat": u"$lat", u"long": u"$long" } } }] traffic_all = dumps(traffic_details.aggregate(pipeline)) traffic_all = json.loads(traffic_all) for i in range(len(traffic_all)): query = {} query["lat"] = traffic_all[i]['_id']['lat'] query["long"] = traffic_all[i]['_id']['long'] temp = json.loads( dumps( traffic_details.find(query).sort( "_id", pymongo.DESCENDING).limit(1))) latest_db_records.append(temp[0]) return latest_db_records
def insert_bike_data(self, data): with app.app_context(): bike_details = mongo.db.BikeData return bike_details.insert(data)
def get_latest_by_lat_long(self): with app.app_context(): luasstop_details = mongo.db.LuasStops latest_db_records = json.loads(dumps(luasstop_details.find())) return latest_db_records
def insert_luasstop_data(self, data): with app.app_context(): luasstop_details = mongo.db.LuasStops return luasstop_details.insert(data)
def insert_busstop_data(self, data): with app.app_context(): busstop_details = mongo.db.BusStops return busstop_details.insert(data)
def update_alert(self, data): with app.app_context(): alert_details = mongo.db.Alerts query = {"_id": ObjectId("" + data["_id"]["$oid"] + "")} newValues = {"$set": {"status": "forwarded"}} return alert_details.update_one(query, newValues, False)
def insert_alerts(self, data): with app.app_context(): alert_details = mongo.db.Alerts return alert_details.insert(data)
def get_all_objects(self): with app.app_context(): pollution_details = mongo.db.BreezoMeter poll_all = dumps(pollution_details.find()) poll_all = ast.literal_eval(poll_all) return poll_all
def insert_poll_data(self, data): with app.app_context(): pollution_details = mongo.db.BreezoMeter return pollution_details.insert(data)
def get_latest_by_lat_long(self): with app.app_context(): irishrailstop_details = mongo.db.IrishRailStops latest_db_records = json.loads(dumps(irishrailstop_details.find())) return latest_db_records
def insert_irishrailstop_data(self, data): with app.app_context(): irishrailstop_details = mongo.db.IrishRailStops return irishrailstop_details.insert(data)
def insert_traffic_analysis_data(self, data): with app.app_context(): traffic_analysis_details = mongo.db.TrafficAnalysisData return traffic_analysis_details.insert(data)