From 740350eacdbb12e7976d7f47e5874c58b3763d3f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 15 Jul 2024 20:06:48 +0200 Subject: [PATCH] chore(code): Refactor data processing into module --- pyproject.toml | 2 +- src/{ => extract}/load_data.py | 2 +- src/{matrix.py => extract/raw_to_extracted_csv.py} | 9 ++++++--- src/{ => extract}/yml.py | 0 4 files changed, 8 insertions(+), 5 deletions(-) rename src/{ => extract}/load_data.py (95%) rename src/{matrix.py => extract/raw_to_extracted_csv.py} (81%) rename src/{ => extract}/yml.py (100%) diff --git a/pyproject.toml b/pyproject.toml index 4ad578a..60e8767 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ cmd = "nvim" [tool.poe.tasks.extract] help = "Extract the csv data from raw yaml files" shell = """ -python src/matrix.py > 02-data/processed/extracted.csv +python src/extract/raw_to_extracted_csv.py > 02-data/processed/extracted.csv """ [tool.poe.tasks.milestone] help = "Extract, render, commit and version a finished artifact" diff --git a/src/load_data.py b/src/extract/load_data.py similarity index 95% rename from src/load_data.py rename to src/extract/load_data.py index 7cb5d8f..fe41d36 100644 --- a/src/load_data.py +++ b/src/extract/load_data.py @@ -5,7 +5,7 @@ from pathlib import Path from pandas import DataFrame, read_csv try: - import src.yml as yaml # for quarto document scripts + import src.extract.yml as yaml # for quarto document scripts except ModuleNotFoundError: import yml as yaml # for directly running the package diff --git a/src/matrix.py b/src/extract/raw_to_extracted_csv.py similarity index 81% rename from src/matrix.py rename to src/extract/raw_to_extracted_csv.py index d4072d5..d71f1e5 100644 --- a/src/matrix.py +++ b/src/extract/raw_to_extracted_csv.py @@ -8,6 +8,10 @@ try: except ModuleNotFoundError: from model import validity # for directly running the package +try: + import src.process.load_data as load +except ModuleNotFoundError: + import load_data as load def extract(df: DataFrame, file: Path | StringIO) -> None: ( @@ -21,12 +25,11 @@ if __name__ == "__main__": import os import sys - import load_data if len(sys.argv) == 2: - df = load_data.from_yml(Path(sys.argv[1])) + df = load.from_yml(Path(sys.argv[1])) else: - df = load_data.from_yml() + df = load.from_yml() output = StringIO() extract(df, output) diff --git a/src/yml.py b/src/extract/yml.py similarity index 100% rename from src/yml.py rename to src/extract/yml.py