def get_average_by_range(start, end): # 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_by_range(start, end) foundHumidities = HistoricHumidityModel.get_average_by_range(start, end) foundCo2 = HistoricCO2Model.get_average_by_range(start, end) foundTemperatures = HistoricTemperatureModel.get_average_by_range(start, end) # Build object returnObj = HistoricSensorModel( foundPressure, foundHumidities, foundCo2, foundTemperatures) # Clean and return return returnObj
def historic_co2_get_average_in_range(): logging.debug("Received request /historic/co2/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 = HistoricCO2Model.get_average_by_range(start, end) data = HistoricCO2Model.average_json(returnValue) elapsedTime = time.monotonic() - startTime logging.debug("co2 get average by 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))