예제 #1
0
    def init_components(self):
        self.state = "uninitialised"
        self.error = None
        try:
            devices_excl_sys = {
                x: self.devices[x]
                for x in self.devices if x != "Victron_VenusGX"
            }
            allocation_excl_sys = {
                x: self.allocation[x]
                for x in self.allocation if x != "System_Data"
            }
            if self.th_type == "Controller":
                enact = Enactor(devices_excl_sys, self.sftp_location,
                                self.sftp_port, self.sftp_username,
                                self.sftp_password, self.sftp_key_location,
                                self.sftp_directory)
                #ToDo all DBes for data retreive
                data = Data_Retreiver(devices_excl_sys, self.sql_user,
                                      self.sql_pw, self.sql_addr,
                                      self.sql_port, self.sql_db)

                self.service = Controller(data, enact, allocation_excl_sys)
            elif self.th_type == "Aggregator":
                self.service = Aggregator(list(devices_excl_sys.keys()),
                                          self.sql_aggregate,
                                          self.sql_raw_energy,
                                          self.sql_raw_state, self.sql_addr,
                                          self.sql_port, self.sql_user,
                                          self.sql_pw, self.sql_db)
            elif self.th_type == "Forecaster":
                data = Data_Retreiver(devices_excl_sys, self.sql_user,
                                      self.sql_pw, self.sql_addr,
                                      self.sql_port, self.sql_db)
                self.service = Forecaster(Battery, data, self.devices)
            elif self.th_type == "LocalLogger":
                self.service = LocalLogger(
                    self.group, self.device, self.devices[self.device],
                    self.telnet_addr, self.telnet_port, self.sql_raw_energy,
                    self.sql_raw_state, self.sql_addr, self.sql_port,
                    self.sql_user, self.sql_pw, self.sql_db)
            elif self.th_type == "WebLogger":
                self.service = MicrogridWebRetreiver(
                    self.group, self.device, self.devices[self.device],
                    self.sql_raw_energy, self.sql_raw_state, self.sql_addr,
                    self.sql_port, self.sql_user, self.sql_pw, self.sql_db,
                    self.mesh_user, self.mesh_pw, self.mesh_addr)
            elif self.th_type == "RemoteLogger":
                data = Data_Retreiver(devices_excl_sys, self.sql_user,
                                      self.sql_pw, self.sql_addr,
                                      self.sql_port, self.sql_db)
                self.service = RemoteLogger(data, self.mqtt_address,
                                            self.mqtt_port, self.mqtt_username,
                                            self.mqtt_password)
        except Exception as ex:
            print("FAULT: Thread " + self.getName() + " Internal Error : " +
                  str(sys.exc_info()[0]))
            self.error = str(sys.exc_info()[0])
            self.state = "Error"
    def setUp(self):

        dir_path = os.path.dirname(os.path.dirname(
            os.path.realpath(__file__)))  #Core directory always
        with open(
                os.path.join(os.path.join(dir_path, 'config'),
                             'runner_config.json')) as json_file:
            json_data = json.load(json_file)

        self.devices = json_data["devices"]

        # Data Retreiver
        self.sql_user = json_data["sql_user"]
        self.sql_pw = json_data["sql_pw"]
        self.sql_db = json_data["sql_db"]
        self.sql_addr = json_data["sql_addr"]
        self.sql_port = json_data["sql_port"]

        # Init Data Retreiver
        self.data = Data_Retreiver(self.devices, self.sql_user, self.sql_pw,
                                   self.sql_addr, self.sql_port, self.sql_db)

        self.sql_table = json_data["sql_aggregate"]
        self.sql_table_raw = json_data["sql_raw_energy"]
        self.sql_table_state = json_data["sql_raw_energy"]
    def setUp(self):

        dir_path = os.path.dirname(os.path.dirname(
            os.path.realpath(__file__)))  #Core directory always
        with open(
                os.path.join(os.path.join(dir_path, 'config'),
                             'runner_config.json')) as json_file:
            json_data = json.load(json_file)

        devices = json_data["devices"]

        # Data Retreiver
        sql_user = json_data["sql_user"]
        sql_pw = json_data["sql_pw"]
        sql_db = json_data["sql_db"]
        sql_addr = json_data["sql_addr"]
        sql_port = json_data["sql_port"]

        self.mqtt_address = json_data["mqtt_address"]
        self.mqtt_port = json_data["mqtt_port"]
        self.mqtt_username = json_data["mqtt_username"]
        self.mqtt_password = json_data["mqtt_password"]

        self.data = Data_Retreiver(devices, sql_user, sql_pw, sql_addr,
                                   sql_port, sql_db)
    def setUp(self):

        dir_path = os.path.dirname(os.path.dirname(
            os.path.realpath(__file__)))  #Core directory always
        with open(
                os.path.join(os.path.join(dir_path, 'config'),
                             'runner_config.json')) as json_file:
            json_data = json.load(json_file)

        self.devices = json_data["devices"]
        self.devices = {
            x: self.devices[x]
            for x in self.devices if x != "Victron_VenusGX"
        }
        # Data Retreiver
        self.sql_user = json_data["sql_user"]
        self.sql_pw = json_data["sql_pw"]
        self.sql_db = json_data["sql_db"]
        self.sql_addr = json_data["sql_addr"]
        self.sql_port = json_data["sql_port"]

        # Init Data Retreiver
        self.data = Data_Retreiver(self.devices, self.sql_user, self.sql_pw,
                                   self.sql_addr, self.sql_port, self.sql_db)

        self.curr_ts = datetime.datetime.now()
        print("Running Forecasting -- ", self.curr_ts, " --")
        self.forecast_period = 48
    def setUp(self):

        dir_path = os.path.dirname(os.path.dirname(
            os.path.realpath(__file__)))  #Core directory always
        with open(
                os.path.join(os.path.join(dir_path, 'config'),
                             'runner_config.json')) as json_file:
            json_data = json.load(json_file)

        devices = json_data["devices"]

        # Data Retreiver
        sql_user = json_data["sql_user"]
        sql_pw = json_data["sql_pw"]
        sql_db = json_data["sql_db"]
        sql_addr = json_data["sql_addr"]
        sql_port = json_data["sql_port"]

        # Init Data Retreiver
        self.data = Data_Retreiver(devices, sql_user, sql_pw, sql_addr,
                                   sql_port, sql_db)

        ## Conctrol Enactor
        sftp_location = json_data["sftp_location"]
        sftp_port = json_data["sftp_port"]
        sftp_username = json_data["sftp_username"]
        sftp_password = json_data["sftp_password"]
        sftp_key_location = json_data["sftp_key_location"]
        sftp_directory = json_data["sftp_directory"]

        # Global for Unit Test
        self.enact = Enactor(devices, sftp_location, sftp_port, sftp_username,
                             sftp_password, sftp_key_location, sftp_directory)

        # Controller Init
        ts_step = datetime.datetime.now()  # - datetime.timedelta(hours=3)

        self.allocation = json_data["allocation"]
        if 'System_Data' in self.allocation:
            del self.allocation['System_Data']
예제 #6
0
class DataRetreive_Test(unittest.TestCase):
    def setUp(self):

        dir_path = os.path.dirname(os.path.dirname(
            os.path.realpath(__file__)))  #Core directory always
        with open(
                os.path.join(os.path.join(dir_path, 'config'),
                             'runner_config.json')) as json_file:
            json_data = json.load(json_file)

        self.devices = json_data["devices"]

        # Data Retreiver
        self.sql_user = json_data["sql_user"]
        self.sql_pw = json_data["sql_pw"]
        self.sql_db = json_data["sql_db"]
        self.sql_addr = json_data["sql_addr"]
        self.sql_port = json_data["sql_port"]

        self.data = Data_Retreiver(self.devices, self.sql_user, self.sql_pw,
                                   self.sql_addr, self.sql_port, self.sql_db)

    def test_components_noResp(self):
        self.data.get_unsent_logs(datetime.datetime.now())
        self.data.retreive_filled_aggre(
            datetime.datetime.now() - datetime.timedelta(days=20), 2)

    def test_componentResponse(self):
        dev_light = "Nursery_1A_CPE_No_2"
        dev_socket = "Playground_AC_socket_No_1"
        group = [
            "Nursery_1A_CPE_No_1", "Nursery_1A_CPE_No_2",
            "Nursery_1B_CPE_No_3", "Nursery_1B_CPE_No_4",
            "Nursery_1C_CPE_No_5", "Nursery_1C_CPE_No_6"
        ]
        hour = 6

        dt_ts = datetime.datetime.now()

        self.assertEqual(
            self.data.retreive_latest_forecast(dt_ts).shape, (1, 2))
        self.assertEqual(
            self.data.retreive_latest_raw_system_snapshot(dt_ts).shape, (4, 3))
        self.assertEqual(self.data.retreive_latest_priority(dt_ts).shape[0], 1)
        self.assertEqual(
            self.data.get_total_energy_for_group(group, dt_ts).shape,
            (1, len(group)))
        self.assertEqual(
            self.data.retreive_aggregared_values(dt_ts).shape[0], 1)
        self.assertEqual(
            self.data.retreive_average_vals_for_hour(dt_ts, hour, 8).shape[1],
            4)
        self.assertTrue(
            0 <= self.data.retreive_AC_Session(dev_socket, dt_ts) <= 5000)
        self.assertTrue(
            0 <= self.data.retreive_AC_Energy(dev_socket, dt_ts) <= 5000)
        self.assertEqual(
            len(self.data.retreive_Light_Session(dev_light, dt_ts)), 2)
        self.assertEqual(
            len(self.data.retreive_Light_Energy(dev_light, dt_ts)), 2)
        self.assertEqual(len(self.data.get_latest_quota(dev_light, dt_ts)), 2)
        self.assertEqual(len(self.data.get_latest_quota(dev_socket, dt_ts)), 2)