src.InputLoader
1from . import Generator 2import pandas as pd 3from tabulate import tabulate 4class InputLoader: 5 """ 6 Class to load input data for generators. 7 Can load data from user input or from a CSV file. 8 9 Attributes: 10 ----------- 11 `generators (list)`: List of Generator objects. 12 13 Methods: 14 -------- 15 - `load_data_from_user()`: Load generator data from user input. 16 - `load_data_from_file(file_path)`: Load generator data from a CSV file. 17 - `get_generators()`: Return the list of Generator objects. 18 - `display_generators()`: Display the generator data in a tabular format. 19 """ 20 21 def __init__(self): 22 """ 23 Initialize the InputLoader with an empty list of generators. 24 """ 25 self.generators = [] 26 27 28 def load_data_from_user(self): 29 """Load generator data from user input. 30 Prompts the user to enter the number of generators and their details. 31 32 Returns: 33 -------- 34 None 35 """ 36 37 num_generators = int(input("Enter the number of generators: ")) 38 for i in range(num_generators): 39 print(f"Enter details for generator {i + 1}:") 40 gen_id = input(" Generator ID: ") 41 min_capacity = float(input(" Min Capacity: ")) 42 max_capacity = float(input(" Max Capacity: ")) 43 a = float(input(" Cost coefficient a: ")) 44 b = float(input(" Cost coefficient b: ")) 45 c = float(input(" Cost coefficient c: ")) 46 47 48 generator = Generator.Generator(gen_id, min_capacity, max_capacity, a, b, c) 49 self.generators.append(generator) 50 51 52 def load_data_from_file(self,file_path): 53 """ 54 Load generator data from a CSV file. 55 The CSV file should have the following columns: 56 - Gen_ID 57 - Min_Capacity 58 - Max_Capacity 59 - a 60 - b 61 - c 62 63 Parameters: 64 ----------- 65 `file_path (str)`: Path to the CSV file. 66 67 Returns: 68 -------- 69 None 70 """ 71 data = pd.read_csv(file_path) 72 for index, row in data.iterrows(): 73 gen_id = row['Gen_ID'] 74 min_capacity = row['Min_Capacity'] 75 max_capacity = row['Max_Capacity'] 76 a = row['a'] 77 b = row['b'] 78 c = row['c'] 79 generator = Generator.Generator(gen_id, min_capacity, max_capacity, a, b, c) 80 self.generators.append(generator) 81 82 def get_generators(self): 83 """ 84 Return the list of Generator objects. 85 86 Returns: 87 -------- 88 `list`: List of Generator objects. 89 """ 90 return self.generators 91 92 def display_generators(self): 93 """ 94 Display the generator data in a tabular format. 95 Returns: 96 -------- 97 `DataFrame`: Pandas DataFrame containing generator data. 98 """ 99 table = [] 100 for gen in self.generators: 101 table.append([gen.gen_id, gen.min_capacity, gen.max_capacity, gen.a, gen.b, gen.c]) 102 headers = ["Gen_ID", "Min_Capacity", "Max_Capacity", "a", "b", "c"] 103 df = pd.DataFrame(table, columns=headers) 104 return df
class
InputLoader:
5class InputLoader: 6 """ 7 Class to load input data for generators. 8 Can load data from user input or from a CSV file. 9 10 Attributes: 11 ----------- 12 `generators (list)`: List of Generator objects. 13 14 Methods: 15 -------- 16 - `load_data_from_user()`: Load generator data from user input. 17 - `load_data_from_file(file_path)`: Load generator data from a CSV file. 18 - `get_generators()`: Return the list of Generator objects. 19 - `display_generators()`: Display the generator data in a tabular format. 20 """ 21 22 def __init__(self): 23 """ 24 Initialize the InputLoader with an empty list of generators. 25 """ 26 self.generators = [] 27 28 29 def load_data_from_user(self): 30 """Load generator data from user input. 31 Prompts the user to enter the number of generators and their details. 32 33 Returns: 34 -------- 35 None 36 """ 37 38 num_generators = int(input("Enter the number of generators: ")) 39 for i in range(num_generators): 40 print(f"Enter details for generator {i + 1}:") 41 gen_id = input(" Generator ID: ") 42 min_capacity = float(input(" Min Capacity: ")) 43 max_capacity = float(input(" Max Capacity: ")) 44 a = float(input(" Cost coefficient a: ")) 45 b = float(input(" Cost coefficient b: ")) 46 c = float(input(" Cost coefficient c: ")) 47 48 49 generator = Generator.Generator(gen_id, min_capacity, max_capacity, a, b, c) 50 self.generators.append(generator) 51 52 53 def load_data_from_file(self,file_path): 54 """ 55 Load generator data from a CSV file. 56 The CSV file should have the following columns: 57 - Gen_ID 58 - Min_Capacity 59 - Max_Capacity 60 - a 61 - b 62 - c 63 64 Parameters: 65 ----------- 66 `file_path (str)`: Path to the CSV file. 67 68 Returns: 69 -------- 70 None 71 """ 72 data = pd.read_csv(file_path) 73 for index, row in data.iterrows(): 74 gen_id = row['Gen_ID'] 75 min_capacity = row['Min_Capacity'] 76 max_capacity = row['Max_Capacity'] 77 a = row['a'] 78 b = row['b'] 79 c = row['c'] 80 generator = Generator.Generator(gen_id, min_capacity, max_capacity, a, b, c) 81 self.generators.append(generator) 82 83 def get_generators(self): 84 """ 85 Return the list of Generator objects. 86 87 Returns: 88 -------- 89 `list`: List of Generator objects. 90 """ 91 return self.generators 92 93 def display_generators(self): 94 """ 95 Display the generator data in a tabular format. 96 Returns: 97 -------- 98 `DataFrame`: Pandas DataFrame containing generator data. 99 """ 100 table = [] 101 for gen in self.generators: 102 table.append([gen.gen_id, gen.min_capacity, gen.max_capacity, gen.a, gen.b, gen.c]) 103 headers = ["Gen_ID", "Min_Capacity", "Max_Capacity", "a", "b", "c"] 104 df = pd.DataFrame(table, columns=headers) 105 return df
Class to load input data for generators. Can load data from user input or from a CSV file.
Attributes:
generators (list): List of Generator objects.
Methods:
- `load_data_from_user()`: Load generator data from user input.
- `load_data_from_file(file_path)`: Load generator data from a CSV file.
- `get_generators()`: Return the list of Generator objects.
- `display_generators()`: Display the generator data in a tabular format.
InputLoader()
22 def __init__(self): 23 """ 24 Initialize the InputLoader with an empty list of generators. 25 """ 26 self.generators = []
Initialize the InputLoader with an empty list of generators.
def
load_data_from_user(self):
29 def load_data_from_user(self): 30 """Load generator data from user input. 31 Prompts the user to enter the number of generators and their details. 32 33 Returns: 34 -------- 35 None 36 """ 37 38 num_generators = int(input("Enter the number of generators: ")) 39 for i in range(num_generators): 40 print(f"Enter details for generator {i + 1}:") 41 gen_id = input(" Generator ID: ") 42 min_capacity = float(input(" Min Capacity: ")) 43 max_capacity = float(input(" Max Capacity: ")) 44 a = float(input(" Cost coefficient a: ")) 45 b = float(input(" Cost coefficient b: ")) 46 c = float(input(" Cost coefficient c: ")) 47 48 49 generator = Generator.Generator(gen_id, min_capacity, max_capacity, a, b, c) 50 self.generators.append(generator)
Load generator data from user input. Prompts the user to enter the number of generators and their details.
Returns:
None
def
load_data_from_file(self, file_path):
53 def load_data_from_file(self,file_path): 54 """ 55 Load generator data from a CSV file. 56 The CSV file should have the following columns: 57 - Gen_ID 58 - Min_Capacity 59 - Max_Capacity 60 - a 61 - b 62 - c 63 64 Parameters: 65 ----------- 66 `file_path (str)`: Path to the CSV file. 67 68 Returns: 69 -------- 70 None 71 """ 72 data = pd.read_csv(file_path) 73 for index, row in data.iterrows(): 74 gen_id = row['Gen_ID'] 75 min_capacity = row['Min_Capacity'] 76 max_capacity = row['Max_Capacity'] 77 a = row['a'] 78 b = row['b'] 79 c = row['c'] 80 generator = Generator.Generator(gen_id, min_capacity, max_capacity, a, b, c) 81 self.generators.append(generator)
Load generator data from a CSV file. The CSV file should have the following columns:
- Gen_ID
- Min_Capacity
- Max_Capacity
- a
- b
- c
Parameters:
file_path (str): Path to the CSV file.
Returns:
None
def
get_generators(self):
83 def get_generators(self): 84 """ 85 Return the list of Generator objects. 86 87 Returns: 88 -------- 89 `list`: List of Generator objects. 90 """ 91 return self.generators
Return the list of Generator objects.
Returns:
list: List of Generator objects.
def
display_generators(self):
93 def display_generators(self): 94 """ 95 Display the generator data in a tabular format. 96 Returns: 97 -------- 98 `DataFrame`: Pandas DataFrame containing generator data. 99 """ 100 table = [] 101 for gen in self.generators: 102 table.append([gen.gen_id, gen.min_capacity, gen.max_capacity, gen.a, gen.b, gen.c]) 103 headers = ["Gen_ID", "Min_Capacity", "Max_Capacity", "a", "b", "c"] 104 df = pd.DataFrame(table, columns=headers) 105 return df
Display the generator data in a tabular format.
Returns:
DataFrame: Pandas DataFrame containing generator data.