def initialize_components(self, config_file):
        conf_calc = config_file['calculation']
        time_step_in_s = conf_calc['time_step_in_s']     # in seconds
        record_step_in_s = conf_calc['record_step_in_s'] # in seconds
        
        start_sim_inh = conf_calc['simulation_mode']['start_sim_in_hours']  # starting time of the simulation in h
        end_sim_inh = conf_calc['simulation_mode']['end_sim_in_hours']      # end time of the simulation in h
        wetter_file = utils.check_and_open_file(conf_calc['simulation_mode']['weather_file_path'])        # list of strings
        dhw_load_file = utils.check_and_open_file(conf_calc['simulation_mode']['dhw_profile_file_path']) # list of strings
        el_load_file = utils.check_and_open_file(conf_calc['simulation_mode']['el_load_file_path'])  # list of strings

        sim_flag = conf_calc['mode']
        if(sim_flag == 'simulation'):
            simulation = True
        else:
            simulation = False
        actual_time = self.initialize_actual_time(simulation, start_sim_inh, end_sim_inh)  # time in datetime format
        
        F = open(conf_calc['simulation_mode']['output_file_path'],"w")
        
        conf_comp = config_file['components']
        tsm = timestep.timestepmanager(time_step_in_s, conf_comp['timestep_manager']['minimal_timestep_in_s'], actual_time)

        chp = self.initialize_chp_unit(conf_comp['chp_unit'], actual_time)
        self.chp = chp
        kessel = self.initialize_gas_boiler(conf_comp['gas_boiler'], actual_time)
        self.boiler = kessel
        tank = self.initialize_storage_tank(conf_comp['storage_tank'], actual_time, tsm)
        self.storage_tank = tank
        cvalve = controlvalve.ThreeWayControlValve(conf_comp['control_valve']['initial_hub_position_0_1'])
        heizkurve = self.initialize_heating_curve(conf_comp['heating_curve'])
        self.heizkurve = heizkurve
        # prediction - global and output
        self.prediction_time_step_in_s = config_file['prediction']['prediction_time_step_in_s']
        self.next_prediction_timestamp = actual_time + timedelta(seconds=self.prediction_time_step_in_s)
        self.output_horizont_in_h =  config_file['prediction']['output_horizont_in_h']
        self.output_resolution_in_s =  config_file['prediction']['output_resolution_in_s']
        
        # Martin's code
        conf_pred = config_file['prediction']['heat']
        conf_powr = config_file['prediction']['power']
        pred = self.initialize_thermal_prediction(conf_pred, conf_powr)
        predict_thermal.write_init(conf_pred['path_result'])

        # schedule
        self.current_schedule = self.initialize_schedule(actual_time)

        return (simulation, time_step_in_s, record_step_in_s, start_sim_inh, end_sim_inh, wetter_file, dhw_load_file, el_load_file, actual_time, 
         F, tsm, tank, chp, kessel, cvalve, heizkurve, pred)
Exemple #2
0
def cloud_schedule_gen(actual_time, energy_vector, start_datetime,
                       config_file):
    #config_file = utils.check_and_open_json_file('./config.json')
    output_horizon_in_h = config_file['prediction']['output_horizon_in_h']
    output_resolution_in_s = config_file['prediction'][
        'output_resolution_in_s']
    precision_out_res = timedelta(seconds=output_resolution_in_s)
    wetter_file = utils.check_and_open_file(
        config_file['calculation']['simulation_mode']
        ['weather_file_path'])  # list of strings
    start_sim_inh = config_file['calculation']['simulation_mode'][
        'start_sim_in_hours']
    end_sim_inh = config_file['calculation']['simulation_mode'][
        'end_sim_in_hours']

    lower_thresold = 100.0  # in W/m2
    upper_thresold = 350.0  # in W/m2

    ii = 0
    result_array = []
    for elem in energy_vector:
        out_time = elem['time stamp']
        #time_in_h = utils.convert_time_to_hours()
        dir_rad = get_direct_sun_radiation(True, wetter_file, actual_time,
                                           start_datetime, start_sim_inh,
                                           end_sim_inh)
        if (dir_rad <= lower_thresold):
            # low insolation ==> high energy prices - produce as much as possible in order to sell
            active_flag = True
            value = utils.get_tab_from_list_of_dicts('time stamp', out_time,
                                                     'P_el_max_in_W',
                                                     energy_vector,
                                                     precision_out_res, True,
                                                     ii)
        elif (dir_rad >= upper_thresold):
            # high insolation ==> low energy prices - consume as much as possible in order to save energy or get premium for buying
            active_flag = True
            value = utils.get_tab_from_list_of_dicts('time stamp', out_time,
                                                     'P_el_min_in_W',
                                                     energy_vector,
                                                     precision_out_res, True,
                                                     ii)
        else:
            # moderate insolation ==> run in optimal operation mode to make the most efficient use of the fuel
            active_flag = False
            value = 0.0

        newx = {
            'time_stamp': out_time,
            'activation': active_flag,
            'energy_production_in_W': value
        }
        result_array.append(newx)
        ii = ii + 1
        #print(newx)
    return {
        'timestep_in_s': output_resolution_in_s,
        'active schedule': True,
        'values': result_array
    }
Exemple #3
0
    def initialize_components(self, config_file):
        conf_calc = config_file['calculation']
        self.time_step_in_s = conf_calc['time_step_in_s']     # in seconds
        record_step_in_s = conf_calc['record_step_in_s'] # in seconds
        self.start_sim_inh = conf_calc['simulation_mode']['start_sim_in_hours']  # starting time of the simulation in h
        self.end_sim_inh = conf_calc['simulation_mode']['end_sim_in_hours']      # end time of the simulation in h
        self.wetter_file = utils.check_and_open_file(conf_calc['simulation_mode']['weather_file_path'])        # list of strings
        # mqtt
        conf_plat = conf_calc['platform_mode']
        self.mqtt_broker = conf_plat['mqtt_broker']
        self.mqtt_port_nr = conf_plat['mqtt_port_nr']
        self.mqtt_api_key = conf_plat['mqtt_api_key']
        self.mqtt_sensor_name = conf_plat['mqtt_sensor_name']
        mqtt_attributes = conf_plat['mqtt_attributes']
        self.mqtt_commands = conf_plat['mqtt_commands']
        self.mqtt_client_name = conf_plat['mqtt_client_name_plat']
        
        # prediction - global and output
        self.prediction_time_step_in_s = config_file['prediction']['prediction_time_step_in_s']
        #self.next_prediction_timestamp = actual_time + timedelta(seconds=self.prediction_time_step_in_s)
        self.output_horizon_in_h =  config_file['prediction']['output_horizon_in_h']
        self.output_resolution_in_s =  config_file['prediction']['output_resolution_in_s']
        # Martin's code
        conf_pred = config_file['prediction']['heat']
        conf_powr = config_file['prediction']['power']
        self.pred = self.initialize_thermal_prediction(config_file)
        #predict_thermal.write_init(conf_pred['path_result'])
        
        sim_flag = conf_calc['mode']
        if(sim_flag == 'simulation'):
            self.simulation = True
            self.platform = False
        elif(sim_flag == 'platform'):
            self.simulation = True
            self.platform = True
        elif(sim_flag == 'multigw'):
            self.simulation = False
            self.platform = True
        else:
            self.simulation = False
            self.platform = False
        self.mode = conf_calc['mode']

        crdb_endpoint = config_file['calculation']['platform_mode']['crdb_endpoint']
        crdb_endpoint_add = config_file['calculation']['platform_mode']['crdb_endpoint_add']
        crdb_username = config_file['calculation']['platform_mode']['crdb_username']
        crdb_direct_com = config_file['calculation']['platform_mode']['crdb_direct_com']
        self.pred.initialize_crate_db_connection(crdb_endpoint, crdb_endpoint_add, crdb_username, crdb_direct_com)

        multiple_gateways = config_file['calculation']['platform_mode']['multiple_gateways']
        mg_path = config_file['calculation']['platform_mode']['multiple_gateways_directory']
        mg_croot = config_file['calculation']['platform_mode']['multiple_gateways_croot']

        return (record_step_in_s, mqtt_attributes, multiple_gateways, mg_path, mg_croot)
    def receive_monitoring_data(self, message):
        # extract actual_time and trigger prediction_and_control once the thresold has been reached
        #print(message, type(message))
        # read the input file - here wetter_file - anew in every timestep, as it is changed externally by Stephan
        wet_file = utils.check_and_open_file(
            self.conf_file['calculation']['demonstrator_mode']
            ['load_profile_file'])  # list of strings
        if (isinstance(wet_file, list)
            ):  # use the wetter file only when reaing it was successfull
            self.wetter_file = wet_file  # list of strings

        wyn1 = str(message.payload.decode("utf-8")).split("|")
        #print('DEMO {} {}'.format(wyn1[94], wyn1[95]))
        #actual_time = utils.extract_time_stamp_from_string(wyn1[1])
        actual_time = datetime.fromtimestamp(float(wyn1[95]))
        #print('DEMO actual_time = {}'.format(actual_time))
        # define start_datetime as soon as possible
        if (self.first):
            self.first = False
            self.start_datetime = actual_time
            self.ini_time_in_h = utils.convert_time_to_hours(actual_time)
            self.next_prediction_timestamp = actual_time

        # whenever new time is received from rvk do the following
        act_time_in_h = utils.convert_time_to_hours(
            actual_time) - self.ini_time_in_h
        #print('act_time_in_h = {}'.format(act_time_in_h))
        # get heat load in kW from wetter_file
        q_in_kW = utils.get_jth_column_val(self.simulation, self.wetter_file,
                                           actual_time, self.start_datetime,
                                           self.start_sim_inh,
                                           self.end_sim_inh, 24, 1, 3)
        # send the heat load in kW to the rvk
        print(
            'DEMO act_time = {}; q in kW from demo= {}, q in kW after scaling = {}'
            .format(actual_time, q_in_kW,
                    q_in_kW * self.scaling_factor + self.scaling_offset))
        self.send_heat_load_to_rvk(
            actual_time, q_in_kW * self.scaling_factor + self.scaling_offset)
Exemple #5
0
    def __init__(self, n_day, n_values, eps, predef_loads_file_path,
                 use_predef_loads, output_horizont_in_h,
                 output_resolution_in_s, conf_powr, rvk):

        self.n_day = n_day  # number of past days considered
        self.n_values = n_values  # number of values per day
        self.dt = 24 // n_values  # time step
        self.count = 0  # counter for values between call of prediction
        self.c_tot = 0  # counter for values total
        self.c_day = 0  # counter for saved days
        self.q = 0  # actual heat
        self.t_e = 0  # actual external temperature
        self.q_s = [[0] * n_values for i in range(n_day)]  # array for heat
        self.t_e_s = [[0] * n_values
                      for i in range(n_day)]  # array for external temperatures
        # changes - Wojtek Kozak
        self.q_write = False  # flag - is the thermal prediction possible
        self.eps = eps  # precision of time calculation in hours
        self.act_hour = 0.0 + self.dt
        self.use_predef_loads = use_predef_loads
        self.predef_loads_file_path = predef_loads_file_path
        if (use_predef_loads):
            self.predef_loads = utils.check_and_open_file(
                predef_loads_file_path)
            self.predefine_thermal_loads_from_file()
        #print('has broken')
        self.output_horizont_in_h = output_horizont_in_h
        self.output_resolution_in_s = output_resolution_in_s
        # conf_powr - configuration of electricity demand prediction
        self.type_of_prediction = conf_powr['type_of_prediction']
        if (self.type_of_prediction == 'SLP'):
            self.el_data = conf_powr['SLP']
            self.slp_resolution_in_s = conf_powr['resolution_in_s']
        self.rvk = rvk
        # debug modus
        self.dbg = 1
    def initialize_components(self, config_file):
        conf_calc = config_file['calculation']
        self.time_step_in_s = conf_calc['time_step_in_s']  # in seconds
        record_step_in_s = conf_calc['record_step_in_s']  # in seconds
        self.start_sim_inh = conf_calc['simulation_mode'][
            'start_sim_in_hours']  # starting time of the simulation in h
        self.end_sim_inh = conf_calc['simulation_mode'][
            'end_sim_in_hours']  # end time of the simulation in h
        # mqtt - subscriber that listens to actual date from rvk
        conf_plat = conf_calc['platform_mode']
        self.mqtt_broker = conf_plat['mqtt_broker']
        self.mqtt_port_nr = conf_plat['mqtt_port_nr']
        self.mqtt_api_key = conf_plat['mqtt_api_key']
        self.mqtt_sensor_name = conf_plat['mqtt_sensor_name']
        mqtt_attributes = conf_plat['mqtt_attributes']
        # mqtt - publisher that sends the measured heat consumption data to the rvk
        #self.mqtt_commands = conf_plat['mqtt_commands']
        self.mqtt_topic = conf_calc['demonstrator_mode']['mqtt_topic']
        self.mqtt_client_name = conf_calc['demonstrator_mode'][
            'mqtt_client_name_sender']  # = 'demo1'
        self.wetter_file = utils.check_and_open_file(
            conf_calc['demonstrator_mode']
            ['load_profile_file'])  # list of strings
        self.conf_file = config_file
        self.scaling_factor = conf_calc['demonstrator_mode']['scaling_factor']
        self.scaling_offset = conf_calc['demonstrator_mode']['scaling_offset']

        # prediction - global and output
        self.prediction_time_step_in_s = config_file['prediction'][
            'prediction_time_step_in_s']
        #self.next_prediction_timestamp = actual_time + timedelta(seconds=self.prediction_time_step_in_s)
        self.output_horizon_in_h = config_file['prediction'][
            'output_horizon_in_h']
        self.output_resolution_in_s = config_file['prediction'][
            'output_resolution_in_s']
        # Martin's code
        #conf_pred = config_file['prediction']['heat']
        #conf_powr = config_file['prediction']['power']
        #self.pred = self.initialize_thermal_prediction(config_file)
        #predict_thermal.write_init(conf_pred['path_result'])

        sim_flag = conf_calc['mode']
        if (sim_flag == 'simulation'):
            self.simulation = True
            self.platform = False
        elif (sim_flag == 'platform'):
            self.simulation = True
            self.platform = True
        elif (sim_flag == 'multigw'):
            self.simulation = False
            self.platform = True
        else:
            self.simulation = False
            self.platform = False

        #crdb_endpoint = config['calculation']['platform_mode']['crdb_endpoint']
        #crdb_endpoint_add = config['calculation']['platform_mode']['crdb_endpoint_add']
        #crdb_username = config['calculation']['platform_mode']['crdb_username']
        #crdb_direct_com = config['calculation']['platform_mode']['crdb_direct_com']
        #self.pred.initialize_crate_db_connection(crdb_endpoint, crdb_endpoint_add, crdb_username, crdb_direct_com)

        # authentication
        authentication = config_file['calculation']['platform_mode'][
            'authentication']['activate']
        mqtt_username = config_file['calculation']['platform_mode'][
            'authentication']['mqtt_username']
        mqtt_password = config_file['calculation']['platform_mode'][
            'authentication']['mqtt_password']
        tls_connection = config_file['calculation']['platform_mode'][
            'authentication']['tls_connection']

        return (record_step_in_s, mqtt_attributes, authentication,
                mqtt_username, mqtt_password, tls_connection)