Skip to content

Commit

Permalink
remove unused path_builder code
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenzie-grimes-noaa committed Oct 20, 2023
1 parent 5093fdf commit cc0f66c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
38 changes: 0 additions & 38 deletions python/idsse_common/idsse/common/path_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def parse_dir(self, dir_: str) -> dict:
Returns:
dict: Lookup of all information identified and extracted
"""
# return self._parse(dir_, self.dir_fmt)
return self._parse_times(dir_, self.dir_fmt)

def parse_filename(self, filename: str) -> dict:
Expand All @@ -197,7 +196,6 @@ def parse_filename(self, filename: str) -> dict:
Returns:
dict: Lookup of all information identified and extracted
"""
# return self._parse(filename, self.filename_fmt)
filename = os.path.basename(filename)
return self._parse_times(filename, self.filename_fmt)

Expand All @@ -210,7 +208,6 @@ def parse_path(self, path: str) -> dict:
Returns:
dict: Lookup of all information identified and extracted
"""
# return self._parse(path, self.path_fmt)
return self._parse_times(path, self.path_fmt)

def get_issue(self, path: str) -> datetime:
Expand Down Expand Up @@ -365,38 +362,3 @@ def parse_args(key: str, value: str, result: Dict):
parse_args(res.group(), vals[i][res.span()[0]:], time_args)

return time_args

def _parse(self, string: str, format_str: str) -> Dict:
def get_between(query_str: str, pre_off: str, post_off: str) -> Tuple[str, str]:
idx1 = query_str.index(pre_off) + len(pre_off)
idx2 = query_str.index(post_off, idx1)
return query_str[idx1:idx2], query_str[idx2:]

def parse_args(key: str, value: str, result: Dict):
for arg in key.split('{')[1:]:
var_name, var_size = arg.split(':')
var_type = var_size[-2:-1]
var_size = int(var_size[:-2])
match var_type:
case 'd':
result[var_name] = int(value[:var_size])
case _:
raise ValueError(f'Unknown format type: {var_type}')
key = key[var_size:]
value = value[var_size:]

constants = [part for part in re.split(r'{.*?}', format_str) if part]

arg_lookup = {}
for i in range(1, len(constants)):
pre = constants[i-1]
post = constants[i]
format_between, format_str = get_between(format_str, pre, post)
string_between, string = get_between(string, pre, post)
arg_lookup[format_between] = string_between

time_args = {}
for key, value in arg_lookup.items():
parse_args(key, value, time_args)

return time_args
13 changes: 12 additions & 1 deletion python/idsse_common/test/test_path_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,22 @@ def test_get_valid_returns_none_if_args_empty():
def test_get_valid_from_time_args_calculates_based_on_lead(path_builder: PathBuilder):
parsed_dict = path_builder.parse_path(EXAMPLE_FULL_PATH)
result_valid: datetime = PathBuilder.get_valid_from_time_args(parsed_args=parsed_dict)

assert result_valid == EXAMPLE_VALID


def test_get_lead_from_time_args(path_builder: PathBuilder):
parsed_dict = path_builder.parse_path(EXAMPLE_FULL_PATH)
lead_result: timedelta = PathBuilder.get_lead_from_time_args(parsed_dict)
assert lead_result.seconds == EXAMPLE_LEAD.minute * 60


def test_calculate_issue_from_valid_and_lead():
parsed_dict = {}
parsed_dict['valid.year'] = 1970
parsed_dict['valid.month'] = 10
parsed_dict['valid.day'] = 3
parsed_dict['valid.hour'] = 14
parsed_dict['lead.hour'] = 2

result_issue = PathBuilder.get_issue_from_time_args(parsed_args=parsed_dict)
assert result_issue == EXAMPLE_ISSUE

0 comments on commit cc0f66c

Please sign in to comment.