# Path: backend/components/clock.py
# class Clock:
#     """Holds actual time. 
#     Notifies about actual time
#     Notifies about week day"""
# 
#     _is_initialized = False
#     _instance = None
# 
#     def __new__(cls, *args, **kwargs):
#         if not cls._instance:
#             cls._instance = super().__new__(cls, *args, **kwargs)
#         return cls._instance
# 
#     def __init__(self, ):
#         if not Clock._is_initialized:
#             Clock._is_initialized = True
#             self.objects_to_notify_weekday = set()
#             self.objects_to_notify_time = set()
# 
#             self.now = None
#             self.minute = None
#             self.weekday = None
# 
#             self.system_start = time.time()
# 
#     def subscribe_for_weekday(self, who):
#         self.objects_to_notify_weekday.add(who)
# 
#     def subscribe_for_minute(self, who):
#         self.objects_to_notify_time.add(who)
# 
#     def notify_minute(self):
#         self.minute = self.now.minute
#         for _object in self.objects_to_notify_time:
#             _object.notify(self.now)
# 
#     def notify_weekday(self):
#         self.weekday = self.now.weekday()
#         for _object in self.objects_to_notify_weekday:
#             _object.notify(self.weekday)
# 
#     def evaluate_time(self, ):
#         """Evaluates current time. If minutes or day changes it notifies related objects"""
#         self.now = datetime.datetime.now()
#         
#         if self.now.minute != self.minute:
#             self.notify_minute()
# 
#         if self.weekday != self.now.weekday():
#             self.notify_weekday()
# 
#     def get_seconds(self):
#         return time.time() - self.system_start
# 
#     def get_millis(self):
#         return (time.time() - self.system_start)*1000
# 
#     def restart(self):
#         self.system_start = time.time()
# 
# Path: backend/components/element.py
# class Element(BaseComponent):
# 
#     table_name = "elements"
#     COL_MODULE_ID, COL_REG,  = 3, 4,
#     column_headers_and_types = BaseComponent.column_headers_and_types + [['module_id', 'integer'], ['register', 'integer']]
# 
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(args[0], Et(args[1]), args[2])  # inicjalizuj id type, name
#         Element.items[self.id] = self        
#         self.value = None
#         self.module_id = args[Element.COL_MODULE_ID]
#         self.reg_id = args[Element.COL_REG]
#         self.objects_to_notify = set()
#         self.new_val_flag = False
# 
#     def subscribe(self, who):
#         self.objects_to_notify.add(who)
# 
#     def notify_objects(self, ):
#         for _object in self.objects_to_notify:
#             _object.notify(self.value)
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tvalue: ", str(self.value)])
# 
# class OutputElement(Element):
#  
#     types = {Et.led, Et.heater, Et.ventilator, Et.blind}
# 
#     defualt_priority = 15
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(*args)
#         OutputElement.items[self.id] = self
#         self.desired_value = 0
#         self.setter_priority = OutputElement.defualt_priority  # Default priority can be overriden by everybody
# 
#     def set_desired_value(self, value, priority, set_flag=False):
# 
#         if priority <= self.setter_priority:
#             self.desired_value = value
# 
#             if set_flag:
#                 self.setter_priority = priority
#             else: 
#                 self.setter_priority = self.defualt_priority
# 
#             return True
# 
#         else:
#             return False
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tdesired_value: ", str(self.desired_value)])
# 
#     @staticmethod
#     def str():
#         string = "\n"
#         for element in OutputElement.items.values():
#             el_str = str(element) 
#             string += el_str + "\n"
# 
#         return string


import operator
from backend.components.clock import Clock
from backend.components.element import Element, OutputElement

    def __repr__(self,):
        return "El id: {} done: {}".format(self.el_id, self.done)


class Dependancy:

    table_name = 'dependancy'

    column_headers_and_types = [['id', 'integer primary key'], 
                                ['name', 'text'],
                                ['dep_str', 'text']]

    cond_start = '['  # flag of condition start
    cond_stop = ']'
    effect_start_t = '{'  # flag of effect start
    effect_stop_t = '}'
    cond_marker = '!'  # flag used by cause parser to mark conditions places.
    cause_effect_sep = 'then'  # separates cause and effects
    time_marker = 't'
    day_marker = 'd'
    element_marker = 'e'

    day_dict = {'mon': 0,
                'tue': 1,
                'wed': 2,
                'thu': 3,
                'fri': 4,
                'sat': 5,
                'sun': 6, }

# Path: backend/components/clock.py
# class Clock:
#     """Holds actual time. 
#     Notifies about actual time
#     Notifies about week day"""
# 
#     _is_initialized = False
#     _instance = None
# 
#     def __new__(cls, *args, **kwargs):
#         if not cls._instance:
#             cls._instance = super().__new__(cls, *args, **kwargs)
#         return cls._instance
# 
#     def __init__(self, ):
#         if not Clock._is_initialized:
#             Clock._is_initialized = True
#             self.objects_to_notify_weekday = set()
#             self.objects_to_notify_time = set()
# 
#             self.now = None
#             self.minute = None
#             self.weekday = None
# 
#             self.system_start = time.time()
# 
#     def subscribe_for_weekday(self, who):
#         self.objects_to_notify_weekday.add(who)
# 
#     def subscribe_for_minute(self, who):
#         self.objects_to_notify_time.add(who)
# 
#     def notify_minute(self):
#         self.minute = self.now.minute
#         for _object in self.objects_to_notify_time:
#             _object.notify(self.now)
# 
#     def notify_weekday(self):
#         self.weekday = self.now.weekday()
#         for _object in self.objects_to_notify_weekday:
#             _object.notify(self.weekday)
# 
#     def evaluate_time(self, ):
#         """Evaluates current time. If minutes or day changes it notifies related objects"""
#         self.now = datetime.datetime.now()
#         
#         if self.now.minute != self.minute:
#             self.notify_minute()
# 
#         if self.weekday != self.now.weekday():
#             self.notify_weekday()
# 
#     def get_seconds(self):
#         return time.time() - self.system_start
# 
#     def get_millis(self):
#         return (time.time() - self.system_start)*1000
# 
#     def restart(self):
#         self.system_start = time.time()
# 
# Path: backend/components/element.py
# class Element(BaseComponent):
# 
#     table_name = "elements"
#     COL_MODULE_ID, COL_REG,  = 3, 4,
#     column_headers_and_types = BaseComponent.column_headers_and_types + [['module_id', 'integer'], ['register', 'integer']]
# 
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(args[0], Et(args[1]), args[2])  # inicjalizuj id type, name
#         Element.items[self.id] = self        
#         self.value = None
#         self.module_id = args[Element.COL_MODULE_ID]
#         self.reg_id = args[Element.COL_REG]
#         self.objects_to_notify = set()
#         self.new_val_flag = False
# 
#     def subscribe(self, who):
#         self.objects_to_notify.add(who)
# 
#     def notify_objects(self, ):
#         for _object in self.objects_to_notify:
#             _object.notify(self.value)
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tvalue: ", str(self.value)])
# 
# class OutputElement(Element):
#  
#     types = {Et.led, Et.heater, Et.ventilator, Et.blind}
# 
#     defualt_priority = 15
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(*args)
#         OutputElement.items[self.id] = self
#         self.desired_value = 0
#         self.setter_priority = OutputElement.defualt_priority  # Default priority can be overriden by everybody
# 
#     def set_desired_value(self, value, priority, set_flag=False):
# 
#         if priority <= self.setter_priority:
#             self.desired_value = value
# 
#             if set_flag:
#                 self.setter_priority = priority
#             else: 
#                 self.setter_priority = self.defualt_priority
# 
#             return True
# 
#         else:
#             return False
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tdesired_value: ", str(self.desired_value)])
# 
#     @staticmethod
#     def str():
#         string = "\n"
#         for element in OutputElement.items.values():
#             el_str = str(element) 
#             string += el_str + "\n"
# 
#         return string


# Path: backend/components/dependancy.py
import operator
from backend.components.clock import Clock
from backend.components.element import Element, OutputElement


    def __repr__(self,):
        return "El id: {} done: {}".format(self.el_id, self.done)


class Dependancy:

    table_name = 'dependancy'

    column_headers_and_types = [['id', 'integer primary key'], 
                                ['name', 'text'],
                                ['dep_str', 'text']]

    cond_start = '['  # flag of condition start
    cond_stop = ']'
    effect_start_t = '{'  # flag of effect start
    effect_stop_t = '}'
    cond_marker = '!'  # flag used by cause parser to mark conditions places.
    cause_effect_sep = 'then'  # separates cause and effects
    time_marker = 't'
    day_marker = 'd'
    element_marker = 'e'

    day_dict = {'mon': 0,
                'tue': 1,
                'wed': 2,
                'thu': 3,
                'fri': 4,
                'sat': 5,
                'sun': 6, }

    clock = Clock()