diff --git a/sohstationviewer/controller/processing.py b/sohstationviewer/controller/processing.py index 7eaa504cb3dca8afc1501aad5cd3aa0c6d4ee284..95c38ee640dadaa591559309ccf8cdb8e921f2d4 100644 --- a/sohstationviewer/controller/processing.py +++ b/sohstationviewer/controller/processing.py @@ -4,8 +4,6 @@ channels, datatype """ import os -import json -import re import traceback from pathlib import Path from typing import List, Set, Optional, Dict, Tuple @@ -28,8 +26,8 @@ from sohstationviewer.controller.util import ( from sohstationviewer.view.util.enums import LogType -def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str], - list_of_rt130_paths: List[Path], +def load_data(data_type: str, tracking_box: QTextBrowser, + list_of_dir: List[str], list_of_rt130_paths: List[Path], req_wf_chans: List[str] = [], req_soh_chans: List[str] = [], read_start: Optional[float] = None, read_end: Optional[float] = None) -> DataTypeModel: @@ -43,7 +41,7 @@ def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str], :param data_type: type of data read :param tracking_box: widget to display tracking info - :param dir_list: list of directories selected by users + :param list_of_dir: list of directories selected by users :param list_of_rt130_paths: list of rt130 directories selected by users :param req_wf_chans: requested waveform channel list :param req_soh_chans: requested soh channel list @@ -54,25 +52,15 @@ def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str], """ data_object = None if list_of_rt130_paths == []: - for d in dir_list: - if data_object is None: - try: - data_object = DataTypeModel.create_data_object( - data_type, tracking_box, d, [], - req_wf_chans=req_wf_chans, req_soh_chans=req_soh_chans, - read_start=read_start, read_end=read_end) - except Exception: - fmt = traceback.format_exc() - msg = f"Dir {d} can't be read due to error: {str(fmt)}" - display_tracking_info(tracking_box, msg, LogType.WARNING) - - # if data_object.has_data(): - # continue - # If no data can be read from the first dir, throw exception - # raise Exception("No data can be read from ", d) - # TODO: will work with select more than one dir later - # else: - # data_object.readDir(d) + try: + data_object = DataTypeModel.create_data_object( + data_type, tracking_box, list_of_dir, [], + req_wf_chans=req_wf_chans, req_soh_chans=req_soh_chans, + read_start=read_start, read_end=read_end) + except Exception: + fmt = traceback.format_exc() + msg = f"Data can't be read due to error: {str(fmt)}" + display_tracking_info(tracking_box, msg, LogType.WARNING) else: try: @@ -175,14 +163,13 @@ def detect_data_type(list_of_dir: List[str]) -> Optional[str]: dir_data_type_dict[d] = ("Unknown", '_') else: dir_data_type_dict[d] = (data_type, chan) + data_type_list = {d[0] for d in dir_data_type_dict.values()} if len(data_type_list) > 1: - dir_data_type_str = json.dumps(dir_data_type_dict) - dir_data_type_str = re.sub(r'\{|\}|"', '', dir_data_type_str) - dir_data_type_str = re.sub(r'], ', ']\n', dir_data_type_str) + dir_data_type_str = ', '. join(list(data_type_list)) msg = (f"There are more than one types of data detected:\n" f"{dir_data_type_str}\n\n" - f"Please have only data that related to each other.") + f"Please have only one data type for each loading.") raise Exception(msg) elif data_type_list == {'Unknown'}: