def handle_graph_endpoint(board_id=None, graph_type=None, start=None, end=None, last_available=None): boards = database.get_board(app.config["db"]) board_desc = dict((board.board_id, board.board_desc) for board in boards) last_metrics = database.get_last_metric(app.config["db"], board_ids=board_id, sensor_type=graph_type) output = list() for last_metric in last_metrics: output.append({"id": last_metric.board_id, "desc": board_desc[last_metric.board_id], "data": []}) metrics = database.get_metric( app.config["db"], board_ids=last_metric.board_id, sensor_type=graph_type, start=start, end=end ) if not metrics and last_available: metrics = database.get_metric( app.config["db"], board_ids=last_metric.board_id, sensor_type=graph_type, last_available=last_available ) for metric in metrics: data = (metric.last_update, float(metric.sensor_data)) output[-1]["data"].append(data) return output
def handle_board_endpoint(board_id=None, sensor_type=None, start=None, end=None): boards = database.get_board(app.config["db"], board_ids=board_id) board_ids = [board.board_id for board in boards] board_desc = dict((board.board_id, board.board_desc) for board in boards) last_metrics = database.get_last_metric( app.config["db"], board_ids=board_ids, start=start, end=end, sensor_type=sensor_type ) output = dict() for metric in last_metrics: output.setdefault( metric.board_id, {"id": metric.board_id, "desc": board_desc[metric.board_id], "data": {}, "last_update": 0} ) output[metric.board_id]["data"][metric.sensor_type] = metric.sensor_data if output[metric.board_id]["last_update"] < metric.last_update: output[metric.board_id]["last_update"] = metric.last_update return output
def _get_boards(self, db): boards = database.get_board(db) self.boards_map = dict((board.board_id, board.board_desc) for board in boards)