Features

User Consumption Reports

app.user.route.getStatistics()[source]

Returns consumption data for all devices for a given month in a year — :param - in: query

name: month schema:

required: false type: integer format: int32

description: the month for which the statistics are wanted style: form explode: true

Parameters
  • in (-) –

    query name: year schema:

    required: false type: integer format: int32

    description: the year for which the statistics are wanted style: form explode: true

  • responses

    “200”:

    description: a list of consumption data for each device content:

    application/json

    ”400”:

    description: Invalid request

app.user.route.getUnoptimizedDevices()[source]

Returns which devices can be optimized for a better energy consumption —

Parameters
  • name (-) –

    month in: query description: the month for which the statistics are wanted required: false style: form explode: true schema:

    type: integer format: int32

  • name

    year in: query description: the year for which the statistics are wanted required: false style: form explode: true schema:

    type: integer format: int32

  • responses

    “200”:

    description: a list of consumption data for each device with energy reduction tips content:

    application/json:
    schema:

    $ref: ‘#/components/schemas/UnoptimizedDevice’

    ”400”:

    description: Invalid request

Device Usage Statistics

app.device.route.addDevice()[source]

Add device to database —

Parameters

header

  • name, in

in: name description: Device required: false style: simple explode: false

responses:
“200”:

description: Newly added device content:

application/json:

app.device.route.addDeviceData()[source]

Insert device data in database —

Parameters
  • id

    name in: header description: Device id required: false style: simple explode: false schema:

    type: number format: int32

  • time

    name in: header description: Time and Date required: false style: simple explode: false schema:

    type: string format: YYYY-MM-DD HH:MM:SS

  • value

    name in: header description: Consumption value required: false style: simple explode: false schema:

    type: number format: int32

responses:
“200”:

description: True or False if the device data has been inserted successfully content:

application/json:

app.device.route.deleteDevice()[source]

Delete device from database —

Parameters

id

name in: query description: Device id required: false style: form explode: true schema:

type: number format: int32

responses:
“200”:

description: True or False if the device has been deleted successfully content:

application/json:

app.device.route.generate_train_data()[source]

Generates the data for training the ML model —

app.device.route.getAnomalyCheck()[source]

Returns True if the consumption profile of a given device in an interval of 6 hours is annormal —

Parameters
  • timestamp

    name in: query description: the start date of the 6 hour period for which the consumption is tested required: false style: form explode: true schema:

    type: string format: YYYY-MM-DD HH:MM:SS

  • device_id

    name in: query description: the device id for which the prediction is made required: false style: form explode: true schema:

    type: integer format: int32

  • responses

    “200”:

    description: True, if the consumption is very different from the predicted consumption, False otherwise content:

    application/json:
    schema:

    type: boolean

    ”403”:

    description: Invalid parameters

app.device.route.getDevice()[source]

Return a specific device —

Parameters

id

name in: query description: Device id required: false style: form explode: true schema:

type: number format: int32

responses:
“200”:

description: Device details content:

application/json:

app.device.route.getDeviceConsumptionPrediction()[source]

Returns the predicted consumption for a device in a given timeframe —

Parameters
  • start_time

    name in: query description: the start date of the given timeframe required: false style: form explode: true schema:

    type: string format: YYYY-MM-DD HH:MM:SS

  • end_time

    name in: query description: the end date of the given timeframe required: false style: form explode: true schema:

    type: string format: YYYY-MM-DD HH:MM:SS

  • device_id

    name in: query description: the device id for which the prediction is made required: false style: form explode: true schema:

    type: integer format: int32

responses:
“200”:

description: The predicted consumption, in kW content:

application/json:
schema:

type: integer

“400”:

description: Bad argument

app.device.route.getDeviceData()[source]

Get device data —

Parameters
  • id

    name in: query description: Device id required: false style: form explode: true schema:

    type: number format: int32

  • page

    name in: query description: Page id required: false style: form explode: true schema:

    type: number format: int32

  • per_page

    name in: query description: Items per page required: false style: form explode: true schema:

    type: number format: int32

responses:
“200”:

description: Device details content:

application/json:

app.device.route.getDevices() → <module ‘json’ from ‘/home/docs/.pyenv/versions/3.7.9/lib/python3.7/json/__init__.py’>[source]

Returns all devices registered in database —

responses:
“200”:

description: All devices from database

app.device.route.predictIsDeviceLeftRunning()[source]

Returns if the device is presumed left running without a real need —

parameters:
name: -device_id

in: query description: the device id for which the prediction is made required: false style: form explode: true schema:

type: integer format: int32

responses:
“200”:

description: A boolean, True or False, if the device is left running or not content:

application/json:
schema:

type: boolean

“400”:

description: Bad argument

app.device.route.updateDevice()[source]

Update device —

Parameters

device – name in: header description: Device required: false style: simple explode: false

responses:
“200”:

description: Newly updated device content:

application/json:

Device Scheduler

class app.mqtt.device_scheduler.DeviceScheduler(app: flask.app.Flask, config)[source]

The mqtt client associated with the flask webserver

It manages the current state of the devices and their scheduling

parse_device_settings(device, state: app.mqtt.device_scheduler.ScheduleState)[source]

Update a state object based on given device settings

scheduler_loop(state: app.mqtt.device_scheduler.ScheduleState)[source]

Main scheduler infinite loop

start_scheduler()[source]

Parses each device settings for each user, calls required handlers

and then starts the (infinite) publisher loop, for each different user

class app.mqtt.device_scheduler.ScheduleHandlers[source]

Collection of all (default) schedule-related handlers

Rules for implementing a handler:

  1. every handler must receive as first argument the current state

  2. for multithreading safety, lock before using info from (the) state object

alarm(seconds, repeats, device_uuid, condition='always_true', content_generator='default_content')[source]

General-purpose alarm

call = {'alarm': <function ScheduleHandlers.alarm>, 'always_true': <function ScheduleHandlers.<lambda>>, 'default_content': <function ScheduleHandlers.<lambda>>, 'global_shutdown': <function ScheduleHandlers.global_shutdown>, 'global_startup': <function ScheduleHandlers.global_startup>, 'ping_alive': <function ScheduleHandlers.<lambda>>, 'power_schedule_tracker': <function ScheduleHandlers.power_schedule_tracker>, 'schedule_tracker': <function ScheduleHandlers.schedule_tracker>}

Function dispatcher

global_shutdown()[source]

Global shutdown broadcast

global_startup()[source]

Global startup broadcast

power_schedule_tracker(device_uuid)[source]

Enforces ACPI schedule for a specific device

schedule_tracker(device_uuid)[source]

Enforces schedule for a specific device

class app.mqtt.device_scheduler.ScheduleState[source]

Class for representing scheduler internal state

info

Dictionary to represent current state

notify()[source]

Notify wakeup condition

queue

FIFO queue that accumulates requests from every module of this app

it is usually populated by ScheduleHandlers or, for example, anomaly detection routines

wakeup

Variable that, when notified, wakes up the scheduler