예제 #1
0
def historic_temperatures_get_average():
    logging.debug("Received request /historic/temperatures/average")
    startTime = time.monotonic()
    try:
        returnValue = HistoricTemperatureModel.get_average()
        data = HistoricTemperatureModel.average_json(returnValue)
        elapsedTime = time.monotonic() - startTime
        logging.debug("temperature 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))
예제 #2
0
	def to_average_json(self):
		logging.debug("Formatting SensorModel to average json")
		json = {
			'type': 'All historic sensor average',
			'attributes': {
				'pressure': HistoricPressureModel.average_json(self.pressures),
				'humidity': HistoricHumidityModel.average_json(self.humidities),
				'co2': HistoricCO2Model.average_json(self.co2),
				'temperature': HistoricTemperatureModel.average_json(self.temperatures)
			}
		}
		return json
예제 #3
0
def historic_temperatures_get_average_in_range():
    logging.debug("Received request /historic/temperatures/average/range")
    startTime = time.monotonic()
    try:
        start = req.args.get('start')
        if start is None:
            start = '2020-01-01T00:00:00'
        logging.debug("Start arg is: " + str(start))

        end = req.args.get('end')
        if end is None:
            end = datetime.utcnow()
        logging.debug("End arg is: " + str(end))

        returnValue = HistoricTemperatureModel.get_average_by_range(start, end)
        data = HistoricTemperatureModel.average_json(returnValue)
        elapsedTime = time.monotonic() - startTime
        logging.debug("temperature 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))