示例#1
0
 def sanity_check(sit_1, sit_2):
     '''Performs a sanity check before two Situations can be compared'''
     if sit_1.area != sit_2.area:
         raise EnergysystemParseError('Areas do not match')
     if not sit_1.context:
         raise EnergysystemParseError('Context scenario is needed to measure relative change')
     if sit_1.context['end_year'] != sit_2.year:
         raise EnergysystemParseError('Context scenario does not match compared situation')
示例#2
0
def from_string(cls, esdl_string):
    '''
    Create a new EnergySystemHandler based on an EnergySystem esdl_string (using UTF-8 encoding)
    '''
    try:
        handler = cls()
        handler.load_from_string(esdl_string)
        return handler
    except Exception as exception:
        raise EnergysystemParseError('ESDL could not be parsed') from exception
示例#3
0
    def as_situation(self):
        ''' Calculates the inputs and wraps them in a Situation'''
        self.calculate()

        try:
            year = self.energy_system.es.instance[0].date.date.year
        except AttributeError as exc:
            raise EnergysystemParseError(
                'Date instance was missing in the ESDL') from exc

        return Situation(self.inputs, self.area, year)
示例#4
0
 def set_asset_generator(self):
     """
     Get all instances of asset type and set the generator.
     """
     try:
         self.asset_generator = self.energy_system.get_all_instances_of_type_by_name(
             self.props['asset'])
     except AttributeError as att:
         raise EnergysystemParseError(
             f'We currently do not support the asset {str(att).split()[-1]}'
         ) from att
示例#5
0
    def __ensure_valid_props(self):
        '''Raises an ESPError if power and fullLoadHours are not included in the props'''
        if all(a in self.props['attr_set']
               for a in ['power', 'fullLoadHours']):
            return

        print(self.props['asset'])

        raise EnergysystemParseError(
            f'Props do not contain "power" or "fullLoadHours" in attribute set: {self.props["attr_set"]}'
        )
示例#6
0
 def from_string(cls, esdl_string):
     '''
     Create a new EnergySystemHandler based on an EnergySystem esdl_string (using UTF-8 encoding)
     '''
     try:
         handler = EnergySystemHandler()
         handler.resource = handler.rset.create_resource(
             StringURI('loadfromstring', esdl_string)
         )
         handler.resource.load()
         handler.es = handler.resource.contents[0]
         return handler
     except Exception as exception:
         raise EnergysystemParseError('ESDL could not be parsed') from exception
示例#7
0
    def set_asset_generator(self):
        """
        Set the generator to assets with type and carrier.
        """

        try:
            self.asset_generator = self.energy_system.get_all_instances_of_type_and_carrier(
                self.props['asset'],
                self.props['carrier']
            )

        except AttributeError as att:
            raise EnergysystemParseError(
                f'We currently do not support the asset {str(att).split()[-1]}'
            ) from att
示例#8
0
    def set_asset_generator(self):
        """
        Get all instances with given sector and carrier and set the generator.
        """

        try:
            self.asset_generator = self.energy_system.get_all_instances_of_type_carrier_and_sector(
                self.props['asset'],
                self.props['sector'],
                self.props['carrier']
            )

        except AttributeError as att:
            print(att)
            raise EnergysystemParseError(
                f'We currently do not support the asset {str(att).split()[-1]}'
            ) from att
示例#9
0
    def __init__(self, energy_system, props, *args, **kwargs):
        ''' Assumes props to be one item with 'power' '''
        if not 'sector' in props:
            raise EnergysystemParseError(f'No sector was given in the config for {props["input"]}')

        super().__init__(energy_system, props, *args, **kwargs)
示例#10
0
def test_with_humanized_message_with_existing_key():
    errors = [list(etm_error_messages.keys())[0]]

    err = EnergysystemParseError.with_humanized_message(errors, 404)
    assert err.message == etm_error_messages[errors[0]]
    assert err.status_code == 404
示例#11
0
def test_with_humanized_message_with_non_existing_key():
    err = EnergysystemParseError.with_humanized_message(['hi', 'you'])
    assert err.message == 'hi'
    assert err.status_code == 422