Skip to content
Snippets Groups Projects
Commit 9378662c authored by Lan Dam's avatar Lan Dam
Browse files

processing.py: modify load_data() to load more than one dir; modify...

processing.py: modify load_data() to load more than one dir; modify detect_data_type due to bug when more than one data_types are detected
parent 0a7dbdc5
No related branches found
No related tags found
1 merge request!122allow to select multi folder to load
...@@ -4,8 +4,6 @@ channels, datatype ...@@ -4,8 +4,6 @@ channels, datatype
""" """
import os import os
import json
import re
import traceback import traceback
from pathlib import Path from pathlib import Path
from typing import List, Set, Optional, Dict, Tuple from typing import List, Set, Optional, Dict, Tuple
...@@ -28,8 +26,8 @@ from sohstationviewer.controller.util import ( ...@@ -28,8 +26,8 @@ from sohstationviewer.controller.util import (
from sohstationviewer.view.util.enums import LogType from sohstationviewer.view.util.enums import LogType
def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str], def load_data(data_type: str, tracking_box: QTextBrowser,
list_of_rt130_paths: List[Path], list_of_dir: List[str], list_of_rt130_paths: List[Path],
req_wf_chans: List[str] = [], req_soh_chans: List[str] = [], req_wf_chans: List[str] = [], req_soh_chans: List[str] = [],
read_start: Optional[float] = None, read_start: Optional[float] = None,
read_end: Optional[float] = None) -> DataTypeModel: read_end: Optional[float] = None) -> DataTypeModel:
...@@ -43,7 +41,7 @@ def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str], ...@@ -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 data_type: type of data read
:param tracking_box: widget to display tracking info :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 list_of_rt130_paths: list of rt130 directories selected by users
:param req_wf_chans: requested waveform channel list :param req_wf_chans: requested waveform channel list
:param req_soh_chans: requested soh 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], ...@@ -54,25 +52,15 @@ def load_data(data_type: str, tracking_box: QTextBrowser, dir_list: List[str],
""" """
data_object = None data_object = None
if list_of_rt130_paths == []: if list_of_rt130_paths == []:
for d in dir_list: try:
if data_object is None: data_object = DataTypeModel.create_data_object(
try: data_type, tracking_box, list_of_dir, [],
data_object = DataTypeModel.create_data_object( req_wf_chans=req_wf_chans, req_soh_chans=req_soh_chans,
data_type, tracking_box, d, [], read_start=read_start, read_end=read_end)
req_wf_chans=req_wf_chans, req_soh_chans=req_soh_chans, except Exception:
read_start=read_start, read_end=read_end) fmt = traceback.format_exc()
except Exception: msg = f"Data can't be read due to error: {str(fmt)}"
fmt = traceback.format_exc() display_tracking_info(tracking_box, msg, LogType.WARNING)
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)
else: else:
try: try:
...@@ -175,14 +163,13 @@ def detect_data_type(list_of_dir: List[str]) -> Optional[str]: ...@@ -175,14 +163,13 @@ def detect_data_type(list_of_dir: List[str]) -> Optional[str]:
dir_data_type_dict[d] = ("Unknown", '_') dir_data_type_dict[d] = ("Unknown", '_')
else: else:
dir_data_type_dict[d] = (data_type, chan) dir_data_type_dict[d] = (data_type, chan)
data_type_list = {d[0] for d in dir_data_type_dict.values()} data_type_list = {d[0] for d in dir_data_type_dict.values()}
if len(data_type_list) > 1: if len(data_type_list) > 1:
dir_data_type_str = json.dumps(dir_data_type_dict) dir_data_type_str = ', '. join(list(data_type_list))
dir_data_type_str = re.sub(r'\{|\}|"', '', dir_data_type_str)
dir_data_type_str = re.sub(r'], ', ']\n', dir_data_type_str)
msg = (f"There are more than one types of data detected:\n" msg = (f"There are more than one types of data detected:\n"
f"{dir_data_type_str}\n\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) raise Exception(msg)
elif data_type_list == {'Unknown'}: elif data_type_list == {'Unknown'}:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment