1+ import pandas as pd
2+ import os
3+
4+ from common .architecture import Architecture
5+ from common .budget import Budget
6+ from common .scheduler import Scheduler
7+ from common .utils import get_project_root
8+
9+ def read_architectures (csv :str )-> list [Architecture ]:
10+ """
11+ Reads the architecture information from a CSV file and returns a list of Architecture objects.
12+
13+ Args:
14+ csv (str): Path to the CSV file. Can be either an absolute path or a relative path from the project root.
15+
16+ Returns:
17+ list[Architecture]: List of Architecture objects parsed from the CSV file.
18+ """
19+ csv = _get_csv_path (csv )
20+
21+ df = pd .read_csv (csv )
22+
23+ architectures = []
24+ for _ , row in df .iterrows ():
25+ architecture = Architecture (
26+ core_id = row ['core_id' ],
27+ speed_factor = row ['speed_factor' ],
28+ scheduler = Scheduler [row ['scheduler' ]]
29+ )
30+ architectures .append (architecture )
31+
32+ return architectures
33+
34+ def read_budgets (csv :str )-> list [Budget ]:
35+ csv = _get_csv_path (csv )
36+
37+ df = pd .read_csv (csv )
38+
39+ for _ ,row in df .iterrows ():
40+ budget = Budget (
41+ component_id = row ['component_id' ],
42+ scheduler = Scheduler [row ['scheduler' ]],
43+ budget = row ['budget' ],
44+ period = row ['period' ],
45+ core_id = row ['core_id' ],
46+ priority = row ['priority' ]
47+ )
48+ budgets .append (budget )
49+
50+ def _get_csv_path (csv :str ) -> str :
51+ if os .path .exists (csv ):
52+ return csv
53+
54+ csv = os .path .join (get_project_root (),csv )
55+ if os .path .exists (csv ):
56+ return csv
57+
58+ raise FileNotFoundError (
59+ f"File { csv } does not exist. "
60+ "Pass to the function an absolute path or a relative path from the project root. "
61+ "For example 'data/testcases/1-tiny-test-case/architecture.csv"
62+ )
0 commit comments