<jupyter_start><jupyter_text>Helper functions<jupyter_code>def generate_charger_classes(chargers):
    chargers_list = []
    for charger_name, charger_detail in chargers.items():
        max_charging_power_kw = charger_detail.get("Max_Charging_Power_kW", None)
        hosted_car = charger_detail.get("Hosted_Car", None)
        soc = charger_detail.get("SoC", None)
        assert max_charging_power_kw, f"Incorrect input: Max_Charging_Power_kW missing for charger: {charger_name}"
        chargers_list.append(ChargingStation(max_charging_power_kw, hosted_car, soc))
    return chargers_list


def generate_car_classes(cars):
    cars_list = []
    for car_name, car_detail in cars.items():
        battery_capacity = car_detail.get("Battery_Capacity_kWh", None)
        assert battery_capacity, f"Incorrect input: Battery_Capacity_kWh missing for car: {car_name}"
        cars_list.append(Car(car_name, battery_capacity))
    return cars_list<jupyter_output><empty_output><jupyter_text>Input parser<jupyter_code>from functools import partial
from profev.MonteCarloSimulator import simulate

class InputConfigParser:
    
    def __init__(self, input_config_file, input_config_mqtt, model_name):
        self.model_name = model_name
        self.model_variables = {'Feasible_ESS_Decisions': {'type': 'Set', 'indexing': 'None'}, 'Feasible_VAC_Decisions': {'type': 'Set', 'indexing': 'None'}, 'Value_Index': {'type': 'Set', 'indexing': 'None'}, 'Value': {'type': 'Param', 'indexing': 'index'}, 'P_PV_Forecast': {'type': 'Param', 'indexing': 'None'}, 'Initial_ESS_SoC': {'type': 'Param', 'indexing': 'index'}, 'Initial_VAC_SoC': {'type': 'Param', 'indexing': 'index'}, 'Number_of_Parked_Cars': {'type': 'Param', 'indexing': 'None'}, 'Unit_Consumption_Assumption': {'type': 'Param', 'indexing': 'None'}, 'Unit_Drop_Penalty': {'type': 'Param', 'indexing': 'None'}, 'ESS_Capacity': {'type': 'Param', 'indexing': 'None'}, 'VAC_Capacity': {'type': 'Param', 'indexing': 'None'}, 'Behavior_Model_Index': {'type': 'Set', 'indexing': 'None'}, 'Behavior_Model': {'type': 'Param', 'indexing': 'None'}, 'dT': {'type': 'Param', 'indexing': 'None'}, 'Decision': {'type': 'Var', 'indexing': 'index'}, 'P_ESS': {'type': 'Var', 'indexing': 'None'}, 'P_VAC': {'type': 'Var', 'indexing': 'None'}, 'P_PV': {'type': 'Var', 'indexing': 'index'}, 'P_GRID': {'type': 'Var', 'indexing': 'None'}}
        self.input_config_file = input_config_file
        self.input_config_mqtt = input_config_mqtt
        self.mqtt_params = {}
        self.generic_names = []
        self.generic_file_names = []
        
        self.defined_prediction_names = []
        self.defined_non_prediction_names = ["P_PV", "P_PV_Forecast"] #New
        self.defined_external_names = ["SoC_Value"]
        self.prediction_names = []
        self.non_prediction_names = []
        self.external_names = []
        
        # Added
        self.car_park = None
        self.simulator = None
        
        self.optimization_params = self.extract_optimization_values()
        
    def add_name_to_list(self, key):
        if key in self.defined_prediction_names:
            self.prediction_names.append(key)
        elif key in self.defined_non_prediction_names:
            self.non_prediction_names.append(key)
        elif key in self.defined_external_names:
            self.external_names.append(key)
        else:
            self.generic_names.append(key)

    def generate_car_park(self, details):
        chargers = details.get("Charging_Station", None)
        cars = details.get("Cars", None)
        assert chargers, "Incorrect input: Charging_Station missing in CarPark"
        assert cars, "Incorrect input: Cars missing in CarPark"
        chargers = dict(chargers)
        cars = dict(cars)
        chargers_list = generate_charger_classes(chargers)
        cars_list = generate_car_classes(cars)
        self.car_park = CarPark(chargers_list, cars_list)

        return self.car_park.number_of_cars, self.car_park.vac_capacity
    
    def generate_behaviour_model(self, plugged_time, unplugged_time, simulation_repetition):
        plugged_time_mean = plugged_time.get("mean", None)
        plugged_time_std = plugged_time.get("std", None)
        
        assert plugged_time_mean, "mean value missing in Plugged_Time"
        assert plugged_time_std, "std value missing in Plugged_Time"
        
        unplugged_time_mean = plugged_time.get("mean", None)
        unplugged_time_std = plugged_time.get("std", None)
        
        assert unplugged_time_mean, "mean value missing in Unlugged_Time"
        assert unplugged_time_std, "std value missing in Unlugged_Time"
        
        self.simulator = partial(simulate,
                                 repetition=simulation_repetition,
                                 unplugged_mean=unplugged_time_mean, unplugged_std=unplugged_time_std,
                                 plugged_mean=plugged_time_mean, plugged_std=plugged_time_std)

    def generate_states(self, states, state_name):
        min_value = states.get("Min", None)
        max_value = states.get("Max", None)
        steps = states.get("Steps", None)
        
        assert min_value != None, f"Min value missing in {state_name}"
        assert max_value, f"Max value missing in {state_name}"
        assert steps, f"Steps value missing in {state_name}"
        
        min_value = int(min_value)
        max_value = int(max_value)
        
        return min_value, max_value, steps, list(np.arange(min_value,max_value+steps,steps))
        
    
    def extract_optimization_values(self):
        data = {}
        for input_config in [self.input_config_file, self.input_config_mqtt]:
            for k, v in input_config.items():
                if isinstance(v, dict):
                    for k1, v1 in v.items():
                        if k1 == Constants.meta:
                            for k2, v2 in v1.items():
                                try:
                                    v2 = float(v2)
                                except ValueError:
                                    pass
                                if isinstance(v2, float) and v2.is_integer():
                                    v2 = int(v2)
                                if k2 in self.model_variables.keys():
                                    indexing = self.model_variables[k2]["indexing"]
                                    if indexing == "index":
                                        data[k2] = {int(0): v2}
                                    elif indexing == "None":
                                        data[k2] = {None: v2}
                                else:
                                    data[k2] = {None: v2}
                        elif k1 == Constants.SoC_Value and isinstance(v1, int):
                            indexing = self.model_variables[Constants.SoC_Value]["indexing"]
                            if indexing == "index":
                                data[Constants.SoC_Value] = {int(0): float(v1 / 100)}
                            elif indexing == "None":
                                data[Constants.SoC_Value] = {None: float(v1 / 100)}
                        elif isinstance(v1, list):
                            self.add_name_to_list(k1)
                        elif k == "generic" and not isinstance(v1, dict):
                            logger.debug("Generic single value")
                            try:
                                v1 = float(v1)
                            except ValueError:
                                pass
                            if isinstance(v1, float) and v1.is_integer():
                                v1 = int(v1)
                            data[k1] = {None: v1}
                        elif k == "PROFEV":
                            if isinstance(v1, dict):
                                if k1 == Constants.CarPark:
                                    number_of_cars, vac_capacity = self.generate_car_park(v1)

                                    data["Number_of_Parked_Cars"] = {None: number_of_cars}
                                    data["VAC_Capacity"] = {None: vac_capacity}

                                if k1 == Constants.Uncertainty:
                                    plugged_time = v1.get("Plugged_Time", None)
                                    unplugged_time = v1.get("Unplugged_Time", None)
                                    simulation_repetition = v1.get("simulation_repetition", None)
                                    
                                    assert plugged_time, "Plugged_Time is missing in Uncertainty"
                                    assert unplugged_time, "Unplugged_Time is missing in Uncertainty"
                                    assert simulation_repetition, "simulation_repetition is missing in Uncertainty"
                                    
                                    self.generate_behaviour_model(plugged_time, unplugged_time, simulation_repetition)
                                    
                                    ess_states = v1.get("ESS_States", None)
                                    vac_states = v1.get("VAC_States", None)
                                    
                                    assert ess_states, "ESS_States is missing in Uncertainty"
                                    assert vac_states, "VAC_States is missing in Uncertainty"
                                    
                                    _,_,ess_steps,ess_soc_states = self.generate_states(ess_states, "ESS_States")
                                    _,_,vac_steps,vac_soc_states = self.generate_states(vac_states, "VAC_States")
                                    
                                    self.ess_steps = ess_steps
                                    self.vac_steps = vac_steps
                                    self.ess_soc_states = ess_soc_states
                                    self.vac_soc_states = vac_soc_states
                                    
                                    
                                    data["Value"] = "null"
                                    data["Initial_ESS_SoC"] = "null"
                                    data["Initial_VAC_SoC"] = "null"
                                    data["Behavior_Model"] = "null"
                            else:
                                try:
                                    v1 = float(v1)
                                except ValueError:
                                    pass
                                if isinstance(v1, float) and v1.is_integer():
                                    v1 = int(v1)
                                data[k1] = {None: v1}
        #         pprint.pprint(data, indent=4)
        return data
    
icp = InputConfigParser(input_config_file, input_config_mqtt, model_name)<jupyter_output>[0.0, 2.5, 5.0, 7.5, 10.0, 12.5, 15.0, 17.5, 20.0, 22.5, 25.0, 27.5, 30.0, 32.5, 35.0, 37.5, 40.0, 42.5, 45.0, 47.5, 50.0, 52.5, 55.0, 57.5, 60.0, 62.5, 65.0, 67.5, 70.0, 72.5, 75.0, 77.5, 80.0, 82.5, 85.0, 87.5, 90.0, 92.5, 95.0, 97.5, 100.0]
{'fraction_non_alphanumeric': 0.10303629177146964, 'fraction_numerical': 0.016259432267337406, 'mean_word_length': 1.5872646990471764, 'pattern_counts': {'":': 5, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '60406', 'license': 'Apache-2.0', 'n_tokens_mistral': 3309, 'n_tokens_neox': 3089, 'n_words': 630, 'path': 'jupyter_notebooks/Input parser.ipynb', 'repo_name': 'garagonc/optimization-framework', 'size': '11132'}