|
| 1 | +class ScenarioParams: |
| 2 | + def __init__(self, scenario_id=None): |
| 3 | + # This list of attributes defines the columns that we query from the database. |
| 4 | + # Therefore attribute names matter! |
| 5 | + self.scenario_id = scenario_id |
| 6 | + self.name = None |
| 7 | + self.description = None |
| 8 | + self.study_timeframe_id = None |
| 9 | + self.time_sample_id = None |
| 10 | + self.demand_scenario_id = None |
| 11 | + self.fuel_simple_price_scenario_id = None |
| 12 | + self.generation_plant_scenario_id = None |
| 13 | + self.generation_plant_cost_scenario_id = None |
| 14 | + self.generation_plant_existing_and_planned_scenario_id = None |
| 15 | + self.hydro_simple_scenario_id = None |
| 16 | + self.carbon_cap_scenario_id = None |
| 17 | + self.supply_curves_scenario_id = None |
| 18 | + self.regional_fuel_market_scenario_id = None |
| 19 | + self.rps_scenario_id = None |
| 20 | + self.enable_dr = None |
| 21 | + self.enable_ev = None |
| 22 | + self.transmission_base_capital_cost_scenario_id = None |
| 23 | + self.ca_policies_scenario_id = None |
| 24 | + self.enable_planning_reserves = None |
| 25 | + self.generation_plant_technologies_scenario_id = None |
| 26 | + self.variable_o_m_cost_scenario_id = None |
| 27 | + self.wind_to_solar_ratio = None |
| 28 | + |
| 29 | + |
| 30 | +def load_scenario_from_config(config, db_cursor) -> ScenarioParams: |
| 31 | + config = config["get_inputs"] # Only keep the config that matters |
| 32 | + |
| 33 | + # Create the ScenarioParams object |
| 34 | + params = ScenarioParams(scenario_id=config["scenario_id"]) |
| 35 | + param_names = list(params.__dict__.keys()) |
| 36 | + print(param_names) |
| 37 | + |
| 38 | + # Read from the database all the parameters. |
| 39 | + db_cursor.execute( |
| 40 | + f"""SELECT {",".join(param_names)} |
| 41 | + FROM scenario |
| 42 | + WHERE scenario_id = {params.scenario_id};""" |
| 43 | + ) |
| 44 | + db_values = list(db_cursor.fetchone()) |
| 45 | + |
| 46 | + # Allow overriding from config |
| 47 | + for i, param_name in enumerate(param_names): |
| 48 | + value = config[param_name] if param_name in config else db_values[i] |
| 49 | + if value == -1: |
| 50 | + value = None |
| 51 | + setattr(params, param_name, value) |
| 52 | + |
| 53 | + return params |
0 commit comments