Exemplo n.º 1
0
def historic_temperatures_reset_in_range():
    logging.debug("Received request /historic/temperatures/reset/range")
    startTime = time.monotonic()
    try:
        # Requires a simple pw
        pw = req.args.get("pw")
        logging.debug("pw arg is: " + str(pw))
        if pw != "A7G2V9":
            abort(403)

        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))

        HistoricTemperatureModel.delete_by_range(start, end)
        elapsedTime = time.monotonic() - startTime
        logging.debug("temperature reset in range request time: " +
                      str(round(elapsedTime, 5)) + " seconds")
        return res(204, timeUTC=datetime.utcnow())
    except mariadb.Error as e:
        abort(500, str(e))
Exemplo n.º 2
0
	def delete_by_range(start, end):
		# Init
		returnValue = True

		# Execution
		HistoricPressureModel.delete_by_range(start, end)
		HistoricHumidityModel.delete_by_range(start, end)
		HistoricCO2Model.delete_by_range(start, end)
		HistoricTemperatureModel.delete_by_range(start, end)

		# Clean and return
		return returnValue
Exemplo n.º 3
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))
Exemplo n.º 4
0
	def delete_all():
		# Init
		returnValue = True

		# Execution
		HistoricPressureModel.delete_all()
		HistoricHumidityModel.delete_all()
		HistoricCO2Model.delete_all()
		HistoricTemperatureModel.delete_all()

		# Clean and return
		return returnValue
Exemplo n.º 5
0
def historic_temperatures_get_by_search():
    logging.debug("Received request /historic/temperatures/search")
    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))

        dataArray = []
        temperatureArray = HistoricTemperatureModel.get_by_search(start, end)
        for tempModel in temperatureArray:
            dataArray.append(tempModel.to_json())
        elapsedTime = time.monotonic() - startTime
        logging.debug("temperature get by search request time: " +
                      str(round(elapsedTime, 5)) + " seconds")
        return res(200, data=dataArray, timeUTC=datetime.utcnow())
    except mariadb.Error as e:
        logging.exception(e)
        abort(500, str(e))
Exemplo n.º 6
0
def historic_temperatures_reset():
    logging.debug("Received request /historic/temperatures/reset")
    startTime = time.monotonic()
    try:
        # Requires a simple pw
        pw = req.args.get("pw")
        logging.debug("pw arg is: " + str(pw))
        if pw != "A7G2V9":
            abort(403)

        HistoricTemperatureModel.delete_all()
        elapsedTime = time.monotonic() - startTime
        logging.debug("temperature reset request time: " +
                      str(round(elapsedTime, 5)) + " seconds")
        return res(204, timeUTC=datetime.utcnow())
    except mariadb.Error as e:
        abort(500, str(e))
Exemplo n.º 7
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
Exemplo n.º 8
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))
Exemplo n.º 9
0
def historic_temperatures_get_newest():
    logging.debug("Received request /historic/temperatures/newest")
    startTime = time.monotonic()
    try:
        returnValue = HistoricTemperatureModel.get_newest()
        if returnValue is None:
            abort(404)
        data = returnValue.to_json()
        elapsedTime = time.monotonic() - startTime
        logging.debug("temperature 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))
Exemplo n.º 10
0
def historic_temperatures_get_all():
    logging.debug("Received request /historic/temperatures")
    startTime = time.monotonic()
    try:
        dataArray = []
        temperatureArray = HistoricTemperatureModel.get_all()
        for tempModel in temperatureArray:
            dataArray.append(tempModel.to_json())
        elapsedTime = time.monotonic() - startTime
        logging.debug("temperature get all request time: " +
                      str(round(elapsedTime, 5)) + " seconds")
        return res(200, data=dataArray, timeUTC=datetime.utcnow())
    except mariadb.Error as e:
        abort(500, str(e))
Exemplo n.º 11
0
	def get_all():
		# init
		foundPressure = []
		foundHumidities = []
		foundCo2 = []
		foundTemperatures = []

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

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

		# Clean and return
		return returnObj
Exemplo n.º 12
0
	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