dev: добавлены обработчики ошибок при чтении файлов + добавлено автоматическое закрытие окон
This commit is contained in:
parent
ccfb6b9fcb
commit
9faa35f514
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,4 +6,5 @@
|
|||||||
/venv
|
/venv
|
||||||
*.txt
|
*.txt
|
||||||
*.svg
|
*.svg
|
||||||
/test.py
|
/test.py
|
||||||
|
/output
|
||||||
|
|||||||
BIN
pixmap.png
BIN
pixmap.png
Binary file not shown.
|
Before Width: | Height: | Size: 65 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,7 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import traceback
|
||||||
|
import sys
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
# FIXME: костыль для выключения предупреждения "replace deprecated"
|
# FIXME: костыль для выключения предупреждения "replace deprecated"
|
||||||
pd.set_option('future.no_silent_downcasting', True)
|
pd.set_option('future.no_silent_downcasting', True)
|
||||||
@ -18,6 +21,15 @@ class DataConverter(BaseDataConverter):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def convert_data(self, files: list[str]) -> None:
|
def convert_data(self, files: list[str]) -> None:
|
||||||
dataframes = [pd.read_csv(file) if file != '' else None for file in files]
|
try:
|
||||||
converted_dataframes = list(map(self._replace_bool, dataframes))
|
dataframes = [pd.read_csv(file) if file != '' else None for file in files]
|
||||||
self._mediator.notify(self, converted_dataframes)
|
converted_dataframes = list(map(self._replace_bool, dataframes))
|
||||||
|
except:
|
||||||
|
# Get the traceback object
|
||||||
|
tb = sys.exc_info()[2]
|
||||||
|
tbinfo = traceback.format_tb(tb)[0]
|
||||||
|
pymsg = "Traceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
|
||||||
|
logger.error(pymsg)
|
||||||
|
converted_dataframes = [None]
|
||||||
|
finally:
|
||||||
|
self._mediator.notify(self, converted_dataframes)
|
||||||
|
|||||||
@ -7,19 +7,28 @@ from utils.base.base import BaseDirectoryMonitor
|
|||||||
class DirectoryMonitor(BaseDirectoryMonitor):
|
class DirectoryMonitor(BaseDirectoryMonitor):
|
||||||
|
|
||||||
def _init_state(self):
|
def _init_state(self):
|
||||||
self._files = [os.path.join(self._directory_path, file) for file in os.listdir(self._directory_path)]
|
|
||||||
|
self._files = [
|
||||||
|
os.path.join(self._directory_path, file)
|
||||||
|
for file in os.listdir(self._directory_path)
|
||||||
|
if file.lower().endswith('.csv')
|
||||||
|
]
|
||||||
|
|
||||||
self.update_timer.timeout.connect(self._monitor)
|
self.update_timer.timeout.connect(self._monitor)
|
||||||
logger.info("Monitor initiated!")
|
logger.info("Monitor initiated!")
|
||||||
|
|
||||||
def _monitor(self):
|
def _monitor(self):
|
||||||
files = [os.path.join(self._directory_path, file) for file in os.listdir(self._directory_path)]
|
current_files = [
|
||||||
new_files = sorted(list(filter(lambda x: x not in self._files, files)))
|
os.path.join(self._directory_path, file)
|
||||||
|
for file in os.listdir(self._directory_path)
|
||||||
|
if file.lower().endswith('.csv')
|
||||||
|
]
|
||||||
|
new_files = sorted(list(filter(lambda x: x not in self._files, current_files)))
|
||||||
if new_files:
|
if new_files:
|
||||||
logger.info(f"New files detected: {new_files}")
|
logger.info(f"New files detected: {new_files}")
|
||||||
self._mediator.notify(self, new_files)
|
self._mediator.notify(self, new_files)
|
||||||
self._files = files
|
self._files = current_files
|
||||||
if not files:
|
if not current_files:
|
||||||
self._files = []
|
self._files = []
|
||||||
|
|
||||||
def update_settings(self, data: list[dict]) -> None:
|
def update_settings(self, data: list[dict]) -> None:
|
||||||
@ -28,8 +37,13 @@ class DirectoryMonitor(BaseDirectoryMonitor):
|
|||||||
_, system_params = data
|
_, system_params = data
|
||||||
self._directory_path = system_params['trace_storage_path'][0]
|
self._directory_path = system_params['trace_storage_path'][0]
|
||||||
self._update_time = system_params['monitor_update_period'][0]
|
self._update_time = system_params['monitor_update_period'][0]
|
||||||
self._init_state()
|
|
||||||
self.start()
|
if not os.path.exists(self._directory_path):
|
||||||
|
logger.error(f"Путь {self._directory_path} не существует.")
|
||||||
|
raise FileNotFoundError(f"Путь {self._directory_path} не существует.")
|
||||||
|
else:
|
||||||
|
self._init_state()
|
||||||
|
self.start()
|
||||||
else:
|
else:
|
||||||
_, system_params = data
|
_, system_params = data
|
||||||
self._directory_path = system_params['trace_storage_path'][0]
|
self._directory_path = system_params['trace_storage_path'][0]
|
||||||
@ -37,22 +51,8 @@ class DirectoryMonitor(BaseDirectoryMonitor):
|
|||||||
|
|
||||||
def update_plots(self):
|
def update_plots(self):
|
||||||
if self._files is not None:
|
if self._files is not None:
|
||||||
print(self._files)
|
|
||||||
self._mediator.notify(self, self._files)
|
self._mediator.notify(self, self._files)
|
||||||
|
|
||||||
def force_all_dir(self):
|
|
||||||
files = os.listdir(self._directory_path)
|
|
||||||
self._files = files
|
|
||||||
all_files = []
|
|
||||||
for x in self._files:
|
|
||||||
path = os.path.join(self._directory_path, x)
|
|
||||||
all_files.append(path)
|
|
||||||
if all_files:
|
|
||||||
logger.info(f"Plotting all files: {all_files}")
|
|
||||||
self._mediator.notify(self, all_files)
|
|
||||||
else:
|
|
||||||
logger.info(f"Failed pushing {str(all_files)}")
|
|
||||||
|
|
||||||
def custom_csv_extract_only(self, path: str):
|
def custom_csv_extract_only(self, path: str):
|
||||||
self.stop()
|
self.stop()
|
||||||
self._files.append(path)
|
self._files.append(path)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -5,7 +5,7 @@ from PyQt5.QtCore import Qt
|
|||||||
from PyQt5.QtGui import QPixmap
|
from PyQt5.QtGui import QPixmap
|
||||||
|
|
||||||
from utils.base.base import BaseMainWindow, BaseController
|
from utils.base.base import BaseMainWindow, BaseController
|
||||||
from gui.settings_window import settingsWindow
|
from gui.settings_window import SystemSettings, OperatorSettings
|
||||||
from gui.reportGui import ReportSettings
|
from gui.reportGui import ReportSettings
|
||||||
|
|
||||||
class MainWindow(BaseMainWindow):
|
class MainWindow(BaseMainWindow):
|
||||||
@ -17,8 +17,8 @@ class MainWindow(BaseMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
def _init_startUI(self) -> None:
|
def _init_startUI(self) -> None:
|
||||||
self.operSettings = settingsWindow("params/operator_params.json", 'Operator', self._transfer_settings)
|
self.operSettings = OperatorSettings("params/operator_params.json", 'Operator', self._transfer_settings)
|
||||||
self.sysSettings = settingsWindow("params/system_params.json", 'System', self._transfer_settings)
|
self.sysSettings = SystemSettings("params/system_params.json", 'System', self._transfer_settings)
|
||||||
self.repSettings = ReportSettings()
|
self.repSettings = ReportSettings()
|
||||||
self.tabWidget = QtWidgets.QTabWidget()
|
self.tabWidget = QtWidgets.QTabWidget()
|
||||||
|
|
||||||
@ -157,6 +157,12 @@ class MainWindow(BaseMainWindow):
|
|||||||
tab_count = self.tabWidget.count()
|
tab_count = self.tabWidget.count()
|
||||||
for i in range(0, tab_count):
|
for i in range(0, tab_count):
|
||||||
self._close_tab(i)
|
self._close_tab(i)
|
||||||
|
|
||||||
|
def closeEvent(self, a0):
|
||||||
|
self.operSettings.close()
|
||||||
|
self.sysSettings.close()
|
||||||
|
self.repSettings.close()
|
||||||
|
super().closeEvent(a0)
|
||||||
|
|
||||||
def _show_settings(self) -> None:
|
def _show_settings(self) -> None:
|
||||||
self.operSettings.show()
|
self.operSettings.show()
|
||||||
|
|||||||
@ -176,7 +176,16 @@ class settingsWindow(QWidget):
|
|||||||
self._data[key].extend([float(last_value) if key != "trace_storage_path" else last_value] * additional_count)
|
self._data[key].extend([float(last_value) if key != "trace_storage_path" else last_value] * additional_count)
|
||||||
|
|
||||||
|
|
||||||
|
class SystemSettings(settingsWindow):
|
||||||
|
def __init__(self, path, name, upd_func):
|
||||||
|
super().__init__(path, name, upd_func)
|
||||||
|
self._num_points.setVisible(False)
|
||||||
|
|
||||||
|
def _expand(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class OperatorSettings(settingsWindow):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Binary file not shown.
@ -364,6 +364,8 @@ class BaseIdealDataBuilder(OptAlgorithm):
|
|||||||
time = i/self.mul
|
time = i/self.mul
|
||||||
X1, X2, V1, V2, F = func(time)
|
X1, X2, V1, V2, F = func(time)
|
||||||
data.append({"time":time, "Position FE":X1*1000,"Position ME":X2*1000, "Rotor Speed FE":V1*1000, "Rotor Speed ME":V2*1000, "Force":F})
|
data.append({"time":time, "Position FE":X1*1000,"Position ME":X2*1000, "Rotor Speed FE":V1*1000, "Rotor Speed ME":V2*1000, "Force":F})
|
||||||
|
X1, X2, V1, V2, F = func(end_timestamp)
|
||||||
|
data.append({"time":end_timestamp, "Position FE":X1*1000,"Position ME":X2*1000, "Rotor Speed FE":V1*1000, "Rotor Speed ME":V2*1000, "Force":F})
|
||||||
return pd.DataFrame(data)
|
return pd.DataFrame(data)
|
||||||
|
|
||||||
def get_closingDF(self) -> pd.DataFrame:
|
def get_closingDF(self) -> pd.DataFrame:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user