Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed src/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion src/common/architecture.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

from src.common.scheduler import Scheduler
from common.scheduler import Scheduler

@dataclass
class Architecture:
Expand Down
2 changes: 1 addition & 1 deletion src/common/budget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

from assignment.simulator.src.scheduler import Scheduler
from common.scheduler import Scheduler

@dataclass
class Budget:
Expand Down
62 changes: 62 additions & 0 deletions src/common/csvreader.py
Original file line number Diff line number Diff line change
@@ -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"
)
7 changes: 7 additions & 0 deletions src/common/utils.py
Original file line number Diff line number Diff line change
@@ -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__)))
13 changes: 13 additions & 0 deletions src/simulator.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file removed src/simulator/__init__.py
Empty file.
Empty file removed src/simulator/main.py
Empty file.
Loading