Beispiel #1
0
    def setUp(self):
        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)  # configure logging

        self.gp = gridpi_core.System()

        # configure asset models
        parser = ConfigParser()
        parser.read_dict({
            'FEEDER': {
                'class_name': 'VirtualFeeder',
                'name': 'feeder'
            },
            'ENERGY_STORAGE': {
                'class_name': 'VirtualEnergyStorage',
                'name': 'inverter'
            },
            'GRID_INTERTIE': {
                'class_name': 'VirtualGridIntertie',
                'name': 'grid'
            }
        })

        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        for cfg in parser.sections(
        ):  # Add models to System, The asset factory acts on a configuration
            self.gp.add_asset(asset_factory.factory(parser[cfg]))
        del asset_factory

        self.db = SQLAlchemyGP.SQLAlchemyGP()
Beispiel #2
0
    def setUp(self):
        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)  # configure logging

        self.gp = gridpi_core.System()

        # configure asset models
        parser = ConfigParser()
        parser.read_dict({
            'FEEDER': {
                'class_name': 'VirtualFeeder',
                'name': 'feeder'
            },
            'ENERGY_STORAGE': {
                'class_name': 'VirtualEnergyStorage',
                'name': 'inverter'
            },
            'GRID_INTERTIE': {
                'class_name': 'VirtualGridIntertie',
                'name': 'grid'
            }
        })

        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        for cfg in parser.sections(
        ):  # Add models to System, The asset factory acts on a configuration
            self.gp.add_asset(asset_factory.factory(parser[cfg]))
        del asset_factory

        # configure persistence model
        parser.clear()
        parser.read_dict({
            'PERSISTENCE': {
                'class_name': 'DBSQLite3',
                'local_path': '/database/GridPi.sqlite',
                'empty_database_on_start': 1
            }
        })
        persistence_factory = persistence_core.PersistenceFactory()
        for cfg in parser.sections():
            self.db = persistence_factory.factory(parser[cfg])
        del persistence_factory

        asset_refs = [x for x in self.gp.assets]

        for asset in asset_refs:
            params = [p for p in asset.status.keys()]
            self.db.addGroup(asset.config['name'], *params)
Beispiel #3
0
    def test_asset_factory(self):
        logging.debug('********** Test models asset factory **********')
        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object

        self.test_asset = asset_factory.factory(self.parser['ENERGY_STORAGE'])
        self.assertIsInstance(self.test_asset,
                              VirtualEnergyStorage.VirtualEnergyStorage)

        self.test_asset = asset_factory.factory(self.parser['FEEDER'])
        self.assertIsInstance(self.test_asset, VirtualFeeder.VirtualFeeder)

        self.test_asset = asset_factory.factory(self.parser['GRID_INTERTIE'])
        self.assertIsInstance(self.test_asset,
                              VirtualGridIntertie.VirtualGridIntertie)
Beispiel #4
0
def main(*args, **kwargs):
    """ Initalize System object.
        Create the system object. Load system assets, modules, and tagbus. Register the parameters of each asset with the
        tagbus object.
    """
    gp = gridpi_core.System()  # Create System container object
    vs = virtual_system.Virtual_System(
        gp.state_machine, gp.asset_container)  # virtual system for testing

    # read asset config.ini
    bootstrap_parser = kwargs['bootstrap']
    parser = ConfigParser()
    parser.read(bootstrap_parser['BOOTSTRAP']['asset_cfg_local_path'])
    asset_factory = model_core.AssetFactory()  # Create Asset Factory object
    for cfg in parser.sections():
        gp.add_asset(asset_factory.factory(parser[cfg], virtual_system=vs))
    del asset_factory

    # read process config.ini
    parser.clear()
    parser.read(bootstrap_parser['BOOTSTRAP']['process_cfg_local_path'])
    process_factory = process_core.ProcessFactory()
    for cfg in parser.sections():
        gp.add_process(process_factory.factory(parser[cfg]))
    del process_factory

    # read persistent storage config.ini
    parser.clear()
    parser.read(bootstrap_parser['BOOTSTRAP']['persistence_cfg_local_path'])
    persistence_factory = persistence_core.PersistenceFactory()
    for cfg in parser.sections():
        db = persistence_factory.factory(parser[cfg])
    del persistence_factory
    del bootstrap_parser
    del parser

    gp.process_container.sort()  # Sort the process tags by dependency

    loop = asyncio.get_event_loop()  # Get event loop
    loop.create_task(update_assets_loop(gp, poll_rate=.1))
    loop.create_task(update_persistent_storage(gp, db, .2))
    loop.create_task(update_virtual_system(vs))

    try:
        loop.run_forever()
    except:
        loop.close()
Beispiel #5
0
    def test_VF_state_machine(self):
        logging.debug('********** Test VirtualFeeder state machine **********')
        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        self.test_asset = asset_factory.factory(
            self.parser['FEEDER'])  # Virtual Feeder
        self.loop.run_until_complete(self.test_asset.update_status())

        self.test_asset.control['run'] = True
        self.loop.run_until_complete(self.test_asset.update_control())
        self.loop.run_until_complete(self.test_asset.update_status())

        self.assertEqual(self.test_asset.status['online'], True)

        self.test_asset.control['run'] = False
        self.loop.run_until_complete(self.test_asset.update_status())
        self.loop.run_until_complete(self.test_asset.update_control())
Beispiel #6
0
    def test_VES_state_machine_soc_tracking(self):
        logging.debug(
            '********** Test VirtualEnergyStorage soc tracking **********')
        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        self.test_asset = asset_factory.factory(
            self.parser['ENERGY_STORAGE'])  # Virtual Energy persistence

        self.test_asset.control['run'] = True
        self.test_asset.control['kw_setpoint'] = 50.0
        self.loop.run_until_complete(self.test_asset.update_status())
        self.loop.run_until_complete(self.test_asset.update_control())

        start_soc = self.test_asset.status['soc']
        for x in range(5):
            self.loop.run_until_complete(self.test_asset.update_status())

        self.assertLess(self.test_asset.status['soc'], start_soc)
Beispiel #7
0
    def test_read_asset_container(self):
        logging.debug('********** Test read_asset_container **********')
        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        self.test_asset = asset_factory.factory(self.parser['ENERGY_STORAGE'])

        self.test_asset.status['soc'] = 0.5
        self.test_asset.config['target_soc'] = 0.6

        self.AC = model_core.AssetContainer()
        self.AC.add_asset(self.test_asset)

        search_param1 = ('inverter', 'status', 'soc')
        search_param2 = ('inverter', 'config', 'target_soc')

        resp = self.AC.read({search_param1: 0, search_param2: 0})

        self.assertEqual(resp[search_param1], 0.5)
        self.assertEqual(resp[search_param2], 0.6)
Beispiel #8
0
    def test_add_asset(self):

        self.parser = ConfigParser()
        self.parser.read_dict(
            {'FEEDER': {
                'class_name': 'VirtualFeeder',
                'name': 'test'
            }})

        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        for cfg in self.parser.sections(
        ):  # Add models to System, The asset factory acts on a configuration
            self.test_asset = (asset_factory.factory(self.parser[cfg]))
        del asset_factory

        self.test_system.add_asset(self.test_asset)

        self.assertEqual(self.test_asset, self.test_system._assets.assets[0])
Beispiel #9
0
    def test_VES_state_machine(self):
        logging.debug(
            '********** Test VirtualEnergyStorage state machine **********')
        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        self.test_asset = asset_factory.factory(self.parser['ENERGY_STORAGE'])
        self.loop.run_until_complete(self.test_asset.update_status())

        kw_setpoint = 50.0
        self.test_asset.control['run'] = True
        self.test_asset.control['kw_setpoint'] = kw_setpoint
        self.loop.run_until_complete(self.test_asset.update_control())
        self.loop.run_until_complete(self.test_asset.update_status())

        self.assertEqual(self.test_asset.status['online'], True)
        self.assertEqual(self.test_asset.status['kw'], kw_setpoint)

        self.test_asset.control['run'] = False
        self.loop.run_until_complete(self.test_asset.update_control())
        self.loop.run_until_complete(self.test_asset.update_status())

        self.assertEqual(self.test_asset.status['online'], False)
        self.assertEqual(self.test_asset.status['kw'], 0.0)
Beispiel #10
0
    def setUp(self):
        "Setup for process Module Testing"
        self.test_system = gridpi_core.System(
        )  # Create System container object

        # configure asset models
        self.parser = ConfigParser()
        self.parser.read_dict({
            'FEEDER': {
                'class_name': 'VirtualFeeder',
                'name': 'feeder'
            },
            'ENERGY_STORAGE': {
                'class_name': 'VirtualEnergyStorage',
                'name': 'inverter'
            },
            'GRID_INTERTIE': {
                'class_name': 'VirtualGridIntertie',
                'name': 'grid'
            }
        })

        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        for cfg in self.parser.sections(
        ):  # Add models to System, The asset factory acts on a configuration
            self.test_system.add_asset(asset_factory.factory(self.parser[cfg]))
        del asset_factory

        # configure processes
        self.parser.clear()
        self.parser.read_dict({
            'process_1': {
                'class_name': 'EssUpdateStatus'
            },
            'process_2': {
                'class_name': 'GridUpdateStatus'
            },
            'process_3': {
                'class_name': 'EssSocPowerController',
                'inverter_target_soc': 0.6
            },
            'process_4': {
                'class_name': 'EssDemandLimitPowerController',
                'grid_kw_import_limit': 20,
                'grid_kw_export_limit': 20
            },
            'process_5': {
                'class_name': 'EssWriteControl'
            }
        })
        process_factory = process_core.ProcessFactory()
        for cfg in self.parser.sections():
            self.test_system.add_process(
                process_factory.factory(self.parser[cfg]))
        del process_factory

        self.test_system.process.sort()

        # Get an asyncio event loop so that we can run updateStatus() and updateCtrl() on assets.
        self.loop = asyncio.get_event_loop()
Beispiel #11
0
    def setUp(self):
        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)  # configure logging
        self.gp = gridpi_core.System()

        # configure asset models
        parser = ConfigParser()
        parser.read_dict({
            'FEEDER': {
                'class_name': 'VirtualFeeder',
                'class_type': 'feeder',
                'name': 'feeder'
            },
            'ENERGY_STORAGE': {
                'class_name': 'VirtualEnergyStorage',
                'class_type': 'ess',
                'name': 'inverter'
            },
            'GRID_INTERTIE': {
                'class_name': 'VirtualGridIntertie',
                'class_type': 'grid',
                'name': 'grid'
            }
        })

        asset_factory = model_core.AssetFactory(
        )  # Create Asset Factory object
        for cfg in parser.sections(
        ):  # Add models to System, The asset factory acts on a configuration
            self.gp.add_asset(asset_factory.factory(parser[cfg]))
        del asset_factory

        # configure processes
        parser.clear()
        parser.read_dict({
            'process_1': {
                'class_name': 'EssUpdateStatus'
            },
            'process_2': {
                'class_name': 'GridUpdateStatus'
            },
            'process_3': {
                'class_name': 'EssSocPowerController',
                'inverter_target_soc': 0.6
            },
            'process_4': {
                'class_name': 'EssDemandLimitPowerController',
                'grid_kw_import_limit': 20,
                'grid_kw_export_limit': 20
            },
            'process_5': {
                'class_name': 'EssWriteControl'
            }
        })
        process_factory = process_core.ProcessFactory()
        for cfg in parser.sections():
            self.gp.add_process(process_factory.factory(parser[cfg]))
        del process_factory

        parser.clear()
        """