Skip to content

Commit

Permalink
Add return type, change names and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
olejandro committed Nov 25, 2024
1 parent 3962730 commit c293838
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions xl2times/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class DataModule(str, Enum):
trade = "SuppXLS/Trades/ScenTrade_*.*"

@classmethod
def is_module_type(cls, path):
def _find_type_(cls, path: str) -> Enum | None:
for data_module in cls:
if any(
PurePath(path.lower()).match(pattern.lower().strip())
Expand All @@ -94,8 +94,16 @@ def is_module_type(cls, path):
return None

@classmethod
def is_submodule_type(cls, path):
match cls.is_module_type(path):
def module_type(cls, path: str) -> str | None:
module_type = cls._find_type_(path)
if module_type:
return module_type.name
else:
return None

@classmethod
def submodule(cls, path: str) -> str | None:
match cls._find_type_(path):
case DataModule.base | DataModule.subres:
if PurePath(path.lower()).match("*_trans.*"):
return "trans"
Expand All @@ -107,8 +115,8 @@ def is_submodule_type(cls, path):
return "main"

@classmethod
def is_module_name(cls, path):
module_type = cls.is_module_type(path)
def module_name(cls, path: str) -> str | None:
module_type = cls._find_type_(path)
match module_type:
case DataModule.base | DataModule.sets | DataModule.lma | DataModule.demand | DataModule.trade | DataModule.syssettings:
return module_type.name
Expand Down
6 changes: 3 additions & 3 deletions xl2times/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ def include_tables_source(
def include_table_source(table: EmbeddedXlTable):
df = table.dataframe.copy()
df["source_filename"] = Path(table.filename).stem
df["data_module_type"] = DataModule.is_module_type(table.filename)
df["data_submodule"] = DataModule.is_submodule_type(table.filename)
df["data_module_name"] = DataModule.is_module_name(table.filename)
df["data_module_type"] = DataModule.module_type(table.filename)
df["data_submodule"] = DataModule.submodule(table.filename)
df["data_module_name"] = DataModule.module_name(table.filename)
return replace(table, dataframe=df)

return [include_table_source(table) for table in tables]
Expand Down

0 comments on commit c293838

Please sign in to comment.