<commit_before>from common.base_object import Base_object
from common.sys_types import et

class Element(Base_object):

    table_name = "elements"
    COL_MODULE_ID, COL_REG,  = 3, 4, #numery kolumn
    column_headers_and_types = Base_object.column_headers_and_types + [['module_id', 'integer'], ['register', 'integer']] 

    ID = 0
    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 = []   
        self.new_val_flag = False

    def subscribe(self, who):
        self.objects_to_notify.append(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)])

if __name__ == "__main__":
    from common.sys_types import et
    for i in range(4):
        el = Element(et.ds, 'element')
        print (str(el))




























<commit_msg>1) All classes are now in one file.<commit_after>from common.base_object import Base_object
from common.sys_types import et
from math import floor

class Element(Base_object):

    table_name = "elements"
    COL_MODULE_ID, COL_REG,  = 3, 4, #numery kolumn
    column_headers_and_types = Base_object.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 = []   
        self.new_val_flag = False

    def subscribe(self, who):
        self.objects_to_notify.append(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 Input_element(Element):

    types = set((et.ds, et.dht_hum, et.dht_temp, et.pir, et.rs, et.ls, et.switch))
    items = {}

    def __init__(self, *args):
        """arguments: type name """
        super().__init__(*args) # inicjalizuj type, name
        Input_element.items[self.id] = self     
        self.prev_value = None
        self.unit = None  

    def __str__(self, ):
        return  "".join([super().__str__(), "\tprev val: ", str(self.prev_value), ])

class Output_element(Element):
 
    types = set((et.led, et.heater, et.ventilator, et.blind))

    defualt_priority = 10
    items = {}
    def __init__(self, *args):
        super().__init__(*args)
        Output_element.items[self.id] = self 
        self.desired_value = None
        self.setter_priority = Output_element.defualt_priority   #bardzo niski priorytet. kazy moze go zmienic

    def set_desired_value(self, priority, val):
        if val > 0:
            if priority <= self.setter_priority:
                self.setter_priority = priority
                self.desired_value = val
                return True
        elif val == 0:# przy wylaczeniu kazdy moze ustawic element
            self.setter_priority = Output_element.defualt_priority
            self.desired_value = 0 
            return False


    def __str__(self, ):
        return  "".join([super().__str__(), "\tdesired_value: ", str(self.desired_value)])#str(self.desired_value), "\tmodule id: ", str(self.module_id), "\tport id: ", str(self.reg_id)])

    def elements_str():
        string = "\n"
        for element in Output_element.items.values():
            el_str = str(element) 
            string += el_str + "\n"

        return string

class Blind(Output_element):
    table_name = "blinds"
    column_headers_and_types = Element.column_headers_and_types + [['direction', 'text'], ['other_blind', 'integer']] 

    COL_DIRECTION, COL_OTHER_BLIND = 5, 6
    items = {}
    def __init__(self, *args):
        super().__init__(*args[0:self.COL_DIRECTION])
        Blind.items[self.id] = self
        self.direction = args[self.COL_DIRECTION]
        self.other_blind = args[self.COL_OTHER_BLIND] # if blind is up then it is down and the other way around

    def set_desired_value(self, priority, val):
        if super(Blind, self).set_desired_value(priority, 1): # if setter has right priority to turn on blind
            self.other_blind.desired_value = 0    # other blind motor is turned off as well ot avoid shortcut
            return True
        return False


if __name__ == "__main__":
    pass

from common.sys_types import et
types = set((et.ds, et.dht_hum, et.dht_temp, et.pir, et.rs, et.ls, et.switch))
num_types = set()

while types:
    num_types.add(types.pop().value)

num_types






























{'fraction_non_alphanumeric': 0.1212482607831445, 'fraction_numerical': 0.0045716557344464325, 'mean_word_length': 2.638467100506146, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6313282', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1609, 'n_words': 370}