Ejemplo n.º 1
0
def humidity_get_average():
	logging.debug("Received request /humidities/average")
	startTime = time.monotonic()
	try:
		returnValue = HumidityModel.get_average()
		data = HumidityModel.average_json(returnValue)
		elapsedTime = time.monotonic() - startTime
		logging.debug("humidity get average request time: " + str(round(elapsedTime,5))+ " seconds")
		return res(200, data=data, timeUTC=datetime.utcnow())
	except mariadb.Error as e:
		abort(500, str(e))
Ejemplo n.º 2
0
    def delete_by_range(start, end):
        # Init
        returnValue = True

        # Execution
        PressureModel.delte_by_range(start, end)
        HumidityModel.delte_by_range(start, end)
        CO2Model.delete_by_range(start, end)
        TemperatureModel.delete_by_range(start, end)

        # Clean and return
        return returnValue
Ejemplo n.º 3
0
    def delete_all():
        # Init
        returnValue = True

        # Execution
        PressureModel.delete_all()
        HumidityModel.delete_all()
        CO2Model.delete_all()
        TemperatureModel.delete_all()

        # Clean and return
        return returnValue
Ejemplo n.º 4
0
def humidity_get_average_in_range():
	logging.debug("Received request /humidities/average/range")
	startTime = time.monotonic()
	try:
		start = req.args.get('start')
		if start is None:
			start = '2020-01-01T00:00:00'

		end = req.args.get('end')
		if end is None:
			end = datetime.utcnow()

		returnValue = HumidityModel.get_average_by_range(start,end)
		data = HumidityModel.average_json(returnValue)
		elapsedTime = time.monotonic() - startTime
		logging.debug("humidity get average in range request time: " + str(round(elapsedTime,5))+ " seconds")
		return res(200, data=data, timeUTC=datetime.utcnow())
	except mariadb.Error as e:
		abort(500, str(e))
Ejemplo n.º 5
0
 def to_average_json(self):
     logging.debug("Formatting SensorModel to average json")
     json = {
         'type': 'All sensor average',
         'attributes': {
             'pressure': PressureModel.average_json(self.pressures),
             'humidity': HumidityModel.average_json(self.humidities),
             'co2': CO2Model.average_json(self.co2),
             'temperature': TemperatureModel.average_json(self.temperatures)
         }
     }
     return json
Ejemplo n.º 6
0
def humidity_get_newest():
	logging.debug("Received request /humidities/newest")
	startTime = time.monotonic()
	try:
		returnValue = HumidityModel.get_newest()
		if returnValue is None:
			abort(404)
		data = returnValue.to_json()
		elapsedTime = time.monotonic() - startTime
		logging.debug("humidity get newest request time: " + str(round(elapsedTime,5))+ " seconds")
		return res(200, data=data, timeUTC=datetime.utcnow())
	except mariadb.Error as e:
		abort(500, str(e))
Ejemplo n.º 7
0
def humidity_get_all():
	logging.debug("Received request /humidities")
	startTime = time.monotonic()
	try:
		dataArray = []
		humArray = HumidityModel.get_all()
		for tempModel in humArray:
			dataArray.append(tempModel.to_json())
		elapsedTime = time.monotonic() - startTime
		logging.debug("humidity get all request time: " + str(round(elapsedTime,5))+ " seconds")
		return res(200, data=dataArray, timeUTC=datetime.isoformat())
	except mariadb.Error as e:
		abort(500, str(e))
Ejemplo n.º 8
0
    def get_all():
        # init
        foundPressure = []
        foundHumidities = []
        foundCo2 = []
        foundTemperatures = []

        # Execution (4 connection, could be more effecient but query time is hardly an issue)
        foundPressure = PressureModel.get_all()
        foundHumidities = HumidityModel.get_all()
        foundCo2 = CO2Model.get_all()
        foundTemperatures = TemperatureModel.get_all()

        # Build object
        returnObj = SensorModel(foundPressure, foundHumidities, foundCo2,
                                foundTemperatures)

        # Clean and return
        return returnObj
Ejemplo n.º 9
0
    def get_average_by_range(start, end):
        # init
        foundPressure = None
        foundHumidities = None
        foundCo2 = None
        foundTemperatures = None

        # Execution (4 connection, could be more effecient but query time is hardly an issue)
        foundPressure = PressureModel.get_average_by_range(start, end)
        foundHumidities = HumidityModel.get_average_by_range(start, end)
        foundCo2 = CO2Model.get_average_by_range(start, end)
        foundTemperatures = TemperatureModel.get_average_by_range(start, end)

        # Build object
        returnObj = SensorModel(foundPressure, foundHumidities, foundCo2,
                                foundTemperatures)

        # Clean and return
        return returnObj
Ejemplo n.º 10
0
def humidity_get_by_search():
	logging.debug("Received request /humidities/search")
	startTime = time.monotonic()
	try:
		start = req.args.get('start')
		if start is None:
			start = '2020-01-01T00:00:00'

		end = req.args.get('end')
		if end is None:
			end = datetime.utcnow()

		dataArray = []
		humArray = HumidityModel.get_by_search(start,end)
		for tempModel in humArray:
			dataArray.append(tempModel.to_json())
		elapsedTime = time.monotonic() - startTime
		logging.debug("humidity get by search request time: " + str(round(elapsedTime,5))+ " seconds")
		return res(200, data=dataArray, timeUTC=datetime.utcnow())
	except mariadb.Error as e:
		abort(500, str(e))