Skip to content

Commit

Permalink
Adjust the processing order of tfm tables (#251)
Browse files Browse the repository at this point in the history
This PR adjusts the processing order of tfm tables to bring it closer to Veda and adds `model.data_modules` to enable #240 .
Contribute to #41
  • Loading branch information
olejandro authored Dec 14, 2024
1 parent be71a7a commit 4323d60
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 121 deletions.
16 changes: 15 additions & 1 deletion xl2times/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from xl2times.utils import max_workers

from . import excel, transforms, utils
from .datatypes import Config, EmbeddedXlTable, TimesModel
from .datatypes import Config, DataModule, EmbeddedXlTable, TimesModel

logger = utils.get_logger()

Expand Down Expand Up @@ -485,6 +485,20 @@ def run(args: argparse.Namespace) -> str | None:

model.files.update([Path(path).stem for path in input_files])

processing_order = ["base", "subres", "trade", "demand", "scen", "syssettings"]
for data_module in processing_order:
model.data_modules = model.data_modules + sorted(
[
item
for item in {
DataModule.module_name(path)
for path in input_files
if DataModule.module_type(path) == data_module
}
if item is not None
]
)

if args.only_read:
tables = convert_xl_to_times(
input_files,
Expand Down
11 changes: 7 additions & 4 deletions xl2times/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ def module_name(cls, path: str) -> str | None:
module_type = cls.determine_type(path)
match module_type:
case DataModule.base | DataModule.sets | DataModule.lma | DataModule.demand | DataModule.trade | DataModule.syssettings:
return module_type.name
return module_type.name.upper()
case DataModule.subres:
return re.sub("_trans$", "", PurePath(path).stem.lower())
return re.sub(
"^SUBRES_", "", re.sub("_TRANS$", "", PurePath(path).stem.upper())
)
case DataModule.scen:
return re.sub("^SCEN_", "", PurePath(path).stem.upper())
case None:
return None
case _:
return PurePath(path).stem


@dataclass
Expand Down Expand Up @@ -234,6 +236,7 @@ class TimesModel:
units: DataFrame = field(default_factory=DataFrame)
start_year: int = field(default_factory=int)
files: set[str] = field(default_factory=set)
data_modules: list[str] = field(default_factory=list)

@property
def external_regions(self) -> set[str]:
Expand Down
Loading

0 comments on commit 4323d60

Please sign in to comment.