Пример #1
0
    def get_metrics(self, *gqueries):
        '''Requests the metrics for the gqueries from the ETM'''
        query_result = QueryScenario.execute(self.scenario_id, *gqueries)

        if query_result.successful:
            return query_result.value

        raise ETMParseError.with_humanized_message(query_result.errors)
Пример #2
0
def fail_with(result):
    '''
    Raises an ETMParseError based on the results (ServiceResult) errors
    '''
    if not len(result.errors) > 0:
        raise ETMParseError('Something went wrong')

    if result.errors[0] == 'ETEngine returned a 429' or result.errors[
            0] == 'Too many requests':
        raise ETMParseError.with_humanized_message('too_many_requests',
                                                   status_code=429)

    if isinstance(result.errors, list):
        raise ETMParseError.with_humanized_message(result.errors)

    message = ', '.join(
        [f"{key} {', '.join(value)}" for key, value in result.errors.items()])
    raise ETMParseError(message)
Пример #3
0
    def query_scenario(self, scenario_id, prop):
        """
        TODO
        """
        query_result = QueryScenario.execute(scenario_id, prop['gquery'])

        if query_result.successful:
            return query_result.value[
                prop['gquery']]['future'] / prop['factor']

        raise ETMParseError(
            f"We currently do not support the ETM gquery listed in the config: {prop['gquery']}"
        )
Пример #4
0
def test_add_kpis_when_scenario_is_unknown(energy_system_handler_no_kpis):
    handler = KPIHandler(energy_system_handler_no_kpis, 123456)
    handler.get_metrics = MagicMock(side_effect=ETMParseError('No scenario'))

    with pytest.raises(ETMParseError):
        handler.add_kpis()