def historic_co2_get_average():
    logging.debug("Received request /historic/co2/average")
    startTime = time.monotonic()
    try:
        returnValue = HistoricCO2Model.get_average()
        data = HistoricCO2Model.average_json(returnValue)
        elapsedTime = time.monotonic() - startTime
        logging.debug("co 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))
Exemple #2
0
	def get_average():
		# init
		foundPressure = None
		foundHumidities = None
		foundCo2 = None
		foundTemperatures = None

		# Execution (4 connection, could be more efficient but query time is hardly an issue)
		foundPressure = HistoricPressureModel.get_average()
		foundHumidities = HistoricHumidityModel.get_average()
		foundCo2 = HistoricCO2Model.get_average()
		foundTemperatures = HistoricTemperatureModel.get_average()

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

		# Clean and return
		return returnObj