feat: добавил смотрителя директории с графиками
This commit is contained in:
parent
78fa10d897
commit
a38d949712
@ -1,4 +1,4 @@
|
||||
{
|
||||
"trace_storage_path": "/home/andrei/Desktop/bla",
|
||||
"monitor_update_period": 100
|
||||
"monitor_update_period": 0.1
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
loguru==0.7.2
|
||||
numpy==2.1.3
|
||||
pandas==2.2.3
|
||||
PyQt5==5.15.11
|
||||
|
@ -3,4 +3,4 @@ from typing import NamedTuple
|
||||
|
||||
class ConfigSchema(NamedTuple):
|
||||
trace_storage_path: str
|
||||
monitor_update_period: int
|
||||
monitor_update_period: int | float
|
||||
|
53
src/controller/base.py
Normal file
53
src/controller/base.py
Normal file
@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from PyQt5.QtCore import QThread
|
||||
|
||||
|
||||
class BaseMediator:
|
||||
def __init__(self, monitor: BaseDirectoryMonitor):
|
||||
self._monitor = monitor
|
||||
self._monitor.mediator = self
|
||||
|
||||
def notify(self, files: list[str]):
|
||||
...
|
||||
|
||||
|
||||
class BaseDirectoryMonitor(QThread):
|
||||
def __init__(self,
|
||||
directory_path: str,
|
||||
update_time: int,
|
||||
mediator: Optional[BaseMediator] = None):
|
||||
super().__init__()
|
||||
|
||||
self._directory_path = directory_path
|
||||
self._update_time = update_time
|
||||
self._mediator = mediator
|
||||
|
||||
self._files: list[str] = []
|
||||
|
||||
@property
|
||||
def directory_path(self) -> str:
|
||||
return self._directory_path
|
||||
|
||||
@property
|
||||
def update_time(self) -> int:
|
||||
return self._update_time
|
||||
|
||||
@property
|
||||
def files(self) -> list[str]:
|
||||
return self._files
|
||||
|
||||
@property
|
||||
def mediator(self) -> BaseMediator:
|
||||
return self._mediator
|
||||
|
||||
@mediator.setter
|
||||
def mediator(self, mediator: BaseMediator) -> None:
|
||||
self._mediator = mediator
|
||||
|
||||
def _init_state(self):
|
||||
files = os.listdir(self._directory_path)
|
||||
self._files = files
|
13
src/controller/mediator.py
Normal file
13
src/controller/mediator.py
Normal file
@ -0,0 +1,13 @@
|
||||
from controller.base import BaseMediator
|
||||
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class Mediator(BaseMediator):
|
||||
|
||||
def notify(self, files: list[str]):
|
||||
for file in files:
|
||||
# TODO: create dataframe
|
||||
# TODO: create plot widget
|
||||
# TODO: send plot widget to controller
|
||||
logger.info(f"File handled: {file}")
|
24
src/controller/monitor.py
Normal file
24
src/controller/monitor.py
Normal file
@ -0,0 +1,24 @@
|
||||
from time import sleep
|
||||
import os
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from controller.base import BaseDirectoryMonitor
|
||||
|
||||
|
||||
class DirectoryMonitor(BaseDirectoryMonitor):
|
||||
|
||||
def run(self):
|
||||
self._init_state()
|
||||
logger.info("Monitor initiated")
|
||||
|
||||
while True:
|
||||
files = os.listdir(self._directory_path)
|
||||
new_files = sorted(list(filter(lambda x: x not in self._files, files)))
|
||||
if new_files:
|
||||
logger.info(f"New files detected: {new_files}")
|
||||
self._mediator.notify(new_files)
|
||||
self._files = files
|
||||
if not files:
|
||||
self._files = []
|
||||
sleep(self._update_time)
|
@ -5,6 +5,8 @@ from os import path
|
||||
|
||||
from gui.mainGui import MainWindow
|
||||
from cfg.schema import ConfigSchema
|
||||
from controller.monitor import DirectoryMonitor
|
||||
from controller.mediator import Mediator
|
||||
|
||||
|
||||
def read_json(filepath: str) -> dict:
|
||||
@ -19,6 +21,9 @@ def read_json(filepath: str) -> dict:
|
||||
def main():
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
config = ConfigSchema(**read_json("config/config.json"))
|
||||
monitor = DirectoryMonitor(config.trace_storage_path, config.monitor_update_period)
|
||||
mediator = Mediator(monitor)
|
||||
monitor.start()
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
Loading…
Reference in New Issue
Block a user