# Path: code/api/enums.py
# JSON_TYPES = {
#     INIT: "init",
#     PROPOSE: "propose",
#     PREVOTE: "prevote",
#     VOTE: "vote",
# }
# 
# Path: code/api/utils.py
# def jsonify(data, allow_all_origin=False):
#     from flask import Response, jsonify as json_ify
#     res = json_ify(data)
#     assert isinstance(res, Response)
#     origin = request.environ.get('HTTP_ORIGIN')
#     if not origin:
#         origin = request.environ.get('ORIGIN')
#     # end if
#     if allow_all_origin:
#         res.headers["Access-Control-Allow-Origin"] = '*'
#     elif origin and origin in ORIGIN_LIST:
#         res.headers["Access-Control-Allow-Origin"] = origin
#     # end if
#     return res
# 
# Path: code/api/database.py
# VALUE_TYPE = float
# MSG_TYPE_TYPE = int
# NODE_TYPE = int
# SEQUENCE_TYPE = int
# MSG_TYPE_CLASS_MAP = {
#     INIT: DBInitMessage,
#     PROPOSE: DBProposeMessage,
#     PREVOTE: DBPrevoteMessage,
#     VOTE: DBVoteMessage,
#     # ...
#     ACKNOWLEDGE: DBAcknowledge,
# }
# class DBMessage(db.Entity):
# class DBInitMessage(DBMessage):
# class DBProposeMessage(DBMessage):
# class DBPrevoteMessage(DBMessage):
# class DBVoteMessage(DBMessage):
# class DBAcknowledge(DBMessage):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
# def to_db(msg):


from datetime import datetime
from DictObject import DictObject
from flask import Flask, request
from luckydonaldUtils.logger import logging
from pony import orm
from .enums import JSON_TYPES
from .utils import jsonify
from .database import to_db, db, DBVoteMessage, DBMessage, DBInitMessage, DBPrevoteMessage, DBProposeMessage, DBAcknowledge, \
    MSG_TYPE_CLASS_MAP
from node.enums import INIT  # noqa # pylint: disable=unused-import
from node.messages import Message  # noqa # pylint: disable=unused-import
from werkzeug.debug import DebuggedApplication
    node_list = set()
    event_list = list()
    date_min = None
    date_max = None
    node_events = DBMessage.select_by_sql("""
      SELECT * FROM DBmessage WHERE date >= NOW() - '60 seconds'::INTERVAL
    """)
    for node_event in node_events:
        event_dict = DictObject.objectify({
             "id": {},  # for deduplication in the GUI
             "action": None, # "send" or "acknowledge"
             "type": None,
             "nodes": {},
             "timestamps": {},
             "data": {}
         })
        node_list.add(node_event.node)  # update node list
        if date_min is None or node_event.date < date_min:
            date_min = node_event.date
        # end if
        if date_max is None or node_event.date > date_max:
            date_max = node_event.date
        # end if
        if isinstance(node_event, DBAcknowledge):
            received_msg = Message.from_dict(node_event.raw)
            event_dict.id["receive"] = node_event.id
            event_dict.action = "acknowledge"
            event_dict.nodes["send"] = received_msg.node
            event_dict.nodes["receive"] = node_event.node
            event_dict.timestamps["receive"] = generate_date_data(node_event.date)

# Path: code/api/enums.py
# JSON_TYPES = {
#     INIT: "init",
#     PROPOSE: "propose",
#     PREVOTE: "prevote",
#     VOTE: "vote",
# }
# 
# Path: code/api/utils.py
# def jsonify(data, allow_all_origin=False):
#     from flask import Response, jsonify as json_ify
#     res = json_ify(data)
#     assert isinstance(res, Response)
#     origin = request.environ.get('HTTP_ORIGIN')
#     if not origin:
#         origin = request.environ.get('ORIGIN')
#     # end if
#     if allow_all_origin:
#         res.headers["Access-Control-Allow-Origin"] = '*'
#     elif origin and origin in ORIGIN_LIST:
#         res.headers["Access-Control-Allow-Origin"] = origin
#     # end if
#     return res
# 
# Path: code/api/database.py
# VALUE_TYPE = float
# MSG_TYPE_TYPE = int
# NODE_TYPE = int
# SEQUENCE_TYPE = int
# MSG_TYPE_CLASS_MAP = {
#     INIT: DBInitMessage,
#     PROPOSE: DBProposeMessage,
#     PREVOTE: DBPrevoteMessage,
#     VOTE: DBVoteMessage,
#     # ...
#     ACKNOWLEDGE: DBAcknowledge,
# }
# class DBMessage(db.Entity):
# class DBInitMessage(DBMessage):
# class DBProposeMessage(DBMessage):
# class DBPrevoteMessage(DBMessage):
# class DBVoteMessage(DBMessage):
# class DBAcknowledge(DBMessage):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
#     def to_db(cls, msg):
#     def from_db(self):
# def to_db(msg):


# Path: code/api/main.py
from datetime import datetime
from DictObject import DictObject
from flask import Flask, request
from luckydonaldUtils.logger import logging
from pony import orm
from .enums import JSON_TYPES
from .utils import jsonify
from .database import to_db, db, DBVoteMessage, DBMessage, DBInitMessage, DBPrevoteMessage, DBProposeMessage, DBAcknowledge, \
    MSG_TYPE_CLASS_MAP
from node.enums import INIT  # noqa # pylint: disable=unused-import
from node.messages import Message  # noqa # pylint: disable=unused-import
from werkzeug.debug import DebuggedApplication

    node_list = set()
    event_list = list()
    date_min = None
    date_max = None
    node_events = DBMessage.select_by_sql("""
      SELECT * FROM DBmessage WHERE date >= NOW() - '60 seconds'::INTERVAL
    """)
    for node_event in node_events:
        event_dict = DictObject.objectify({
             "id": {},  # for deduplication in the GUI
             "action": None, # "send" or "acknowledge"
             "type": None,
             "nodes": {},
             "timestamps": {},
             "data": {}
         })
        node_list.add(node_event.node)  # update node list
        if date_min is None or node_event.date < date_min:
            date_min = node_event.date
        # end if
        if date_max is None or node_event.date > date_max:
            date_max = node_event.date
        # end if
        if isinstance(node_event, DBAcknowledge):
            received_msg = Message.from_dict(node_event.raw)
            event_dict.id["receive"] = node_event.id
            event_dict.action = "acknowledge"
            event_dict.nodes["send"] = received_msg.node
            event_dict.nodes["receive"] = node_event.node
            event_dict.timestamps["receive"] = generate_date_data(node_event.date)

            event_dict.type = JSON_TYPES[received_msg.type]