diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/common/architecture.py b/src/common/architecture.py index 581ab11..28c3a4a 100644 --- a/src/common/architecture.py +++ b/src/common/architecture.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -from src.common.scheduler import Scheduler +from common.scheduler import Scheduler @dataclass class Architecture: diff --git a/src/common/budget.py b/src/common/budget.py index 3e4286d..0e6a6fb 100644 --- a/src/common/budget.py +++ b/src/common/budget.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -from assignment.simulator.src.scheduler import Scheduler +from common.scheduler import Scheduler @dataclass class Budget: diff --git a/src/common/csvreader.py b/src/common/csvreader.py new file mode 100644 index 0000000..e700aa2 --- /dev/null +++ b/src/common/csvreader.py @@ -0,0 +1,62 @@ +import pandas as pd +import os + +from common.architecture import Architecture +from common.budget import Budget +from common.scheduler import Scheduler +from common.utils import get_project_root + +def read_architectures(csv:str)-> list[Architecture]: + """ + Reads the architecture information from a CSV file and returns a list of Architecture objects. + + Args: + csv (str): Path to the CSV file. Can be either an absolute path or a relative path from the project root. + + Returns: + list[Architecture]: List of Architecture objects parsed from the CSV file. + """ + csv = _get_csv_path(csv) + + df = pd.read_csv(csv) + + architectures = [] + for _, row in df.iterrows(): + architecture = Architecture( + core_id=row['core_id'], + speed_factor=row['speed_factor'], + scheduler=Scheduler[row['scheduler']] + ) + architectures.append(architecture) + + return architectures + +def read_budgets(csv:str)-> list[Budget]: + csv = _get_csv_path(csv) + + df = pd.read_csv(csv) + + for _,row in df.iterrows(): + budget = Budget( + component_id=row['component_id'], + scheduler=Scheduler[row['scheduler']], + budget=row['budget'], + period=row['period'], + core_id=row['core_id'], + priority=row['priority'] + ) + budgets.append(budget) + +def _get_csv_path(csv:str) -> str: + if os.path.exists(csv): + return csv + + csv = os.path.join(get_project_root(),csv) + if os.path.exists(csv): + return csv + + raise FileNotFoundError( + f"File {csv} does not exist. " + "Pass to the function an absolute path or a relative path from the project root. " + "For example 'data/testcases/1-tiny-test-case/architecture.csv" + ) \ No newline at end of file diff --git a/src/common/utils.py b/src/common/utils.py new file mode 100644 index 0000000..ff1f837 --- /dev/null +++ b/src/common/utils.py @@ -0,0 +1,7 @@ +import os + +def get_project_root() -> str: + """ + Get the root directory of the project. + """ + return os.path.dirname(os.path.dirname(os.path.abspath(__file__))) \ No newline at end of file diff --git a/src/simulator.py b/src/simulator.py new file mode 100644 index 0000000..e72531a --- /dev/null +++ b/src/simulator.py @@ -0,0 +1,13 @@ +from common.csvreader import read_architectures + +def main(): + # Example usage + csv_path = 'data/testcases/1-tiny-test-case/architecture.csv' + architectures = read_architectures(csv_path) + for architecture in architectures: + print(architecture) + + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/simulator/__init__.py b/src/simulator/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/simulator/main.py b/src/simulator/main.py deleted file mode 100644 index e69de29..0000000