# IndustrialTracker ## Databse model ### Device Main device object used as base for dependency injection - id - number - name - string - type - (Relation)->DeviceType - enabled - boolean ### DeviceType Device type definition - id - number - name - string ### Reading Reading object used to store data from Device - id - number - device - (Relation)->Device - reading_time - date - energy - number - air - number - running - boolean - ... place for more data eventually ### PLC PLC object used to store configuration of PLC - id - number - ip - string - port - number - db_number - number - energy_offset - number - air_offset - number - running_offset - number - ... place for more offsets definition ### PAC PAC object used to store configuration of PAC - id - number - ip - string - port - number ... something I missed ### Scheduler - id - number - name - string - interval_seconds - number - next_run - date ... something I missed ## Workflow Entire application should be configurable via databse. Main config of dbs connections, seq connection should be in `config.ini` file. Maintain support to multiple dbs providers (mssql, postgresql) > WARNING: `config.ini` contains sensitive data, so it should be excluded from git repository. ### Main process `main.py` Place where: - logger is initialized - database service is initialized - read service is initialized - scheduler service is initialized ### Scheduler process/service `scheduler.py` Module that is responsible for scheduled operations. Scheduler should be able to: - have name - set on object creation, it will be used as identifier of scheduler - run multiple instances of itself - Raw class of `Scheduler` should have methods for controlling other schedulers. - `Scheduler` object should have methods for controlling scheduler itself. - Function that it will be calling should be somehow passed to scheduler. When scheduler is run, it: - gets all devices from database (Device) - for each device that is enable, at first, check if it is accessible (by pinging) - if yes, then it gets data from device (via read_service) and saves it to database (Reading) ### Read process/service `read_service.py` > Read process should be unified for all devices and handled by dependency injection. Abstract class for dependency injection is declared in `readers/device_reader.py`. Each device type has it's own reader class that implements pinging function and reading function. * PLC reader is implemented in `readers/plc_reader.py` * PAC reader is implemented in `readers/pac_reader.py` #### PLC reader Utilizes `python-snap7` library to communicate with PLC. #### PAC reader > TODO: PAC reader is not implemented yet. Utilizes `---` library to communicate with PAC. ### Database process/service `database_service.py` Singleton class that implements all database operations. > Most use cases should be in scheduler process where readed data are going to be saved to database.