示例#1
0
def fetch_island_data(zone_key, session):
    if zone_key == "ES-IB-FO":
        formentera_data = Formentera(session, verify=False).get_all()
        if not formentera_data:
            raise ParserException(zone_key, "Formentera doesn't respond")
        else:
            return formentera_data
    elif zone_key == "ES-IB-IZ":
        ibiza_data = Ibiza(session, verify=False).get_all()
        if not ibiza_data:
            raise ParserException(zone_key,
                                  "Party is over, Ibiza doesn't respond")
        else:
            return ibiza_data
    elif zone_key == "ES-IB-MA":
        mallorca_data = Mallorca(session, verify=False).get_all()
        if not mallorca_data:
            raise ParserException(zone_key, "Mallorca doesn't respond")
        else:
            return mallorca_data
    elif zone_key == "ES-IB-ME":
        menorca_data = Menorca(session, verify=False).get_all()
        if not menorca_data:
            raise ParserException(zone_key, "Menorca doesn't respond")
        else:
            return menorca_data
    elif zone_key == "ES-IB":
        balearic_islands = BalearicIslands(session, verify=False).get_all()
        if not balearic_islands:
            raise ParserException(zone_key, "Balearic Islands doesn't respond")
        else:
            return balearic_islands
    else:
        raise ParserException(
            zone_key, "Can't read this country code {0}".format(zone_key))
示例#2
0
def fetch_exchange(zone_key1='ES',
                   zone_key2='ES-IB',
                   session=None,
                   target_datetime=None,
                   logger=None):
    if target_datetime:
        raise NotImplementedError(
            'This parser is not yet able to parse past dates')

    ses = session or Session()

    # TODO: Remove verify SSL config when working without it.
    responses = BalearicIslands(ses, verify=False).get_all()
    if not responses:
        raise ParserException("ES-IB", "No response")
    else:

        data = []
        for response in responses:

            sorted_zone_keys = sorted([zone_key1, zone_key2])
            net_flow = response.link['pe_ma']

            response_data = {
                'sortedZoneKeys': '->'.join(sorted_zone_keys),
                'datetime': get(response.timestamp).datetime,
                'netFlow':
                net_flow if zone_key1 == sorted_zone_keys[0] else -1 *
                net_flow,
                'source': 'demanda.ree.es',
            }

            data.append(response_data)

        return data
示例#3
0
def fetch_consumption(zone_key='ES-IB',
                      session=None,
                      target_datetime=None,
                      logger=None):
    if target_datetime:
        raise NotImplementedError(
            'This parser is not yet able to parse past dates')

    ses = session or Session()

    # TODO: Remove verify SSL config when working without it.
    responses = BalearicIslands(ses, verify=False).get_all()
    if not responses:
        raise ParserException("ES-IB", "No response")
    else:
        data = []

        for response in responses:
            response_data = {
                'zoneKey': zone_key,
                'datetime': get(response.timestamp).datetime,
                'consumption': response.demand,
                'source': 'demanda.ree.es'
            }

            data.append(response_data)

        return data
示例#4
0
class TestBalearicIslands(unittest.TestCase):
    def setUp(self):
        self.instance = BalearicIslands()
        self.date = get('2022-06-10').format('YYYY-MM-DD')

    def test_instance(self):
        self.assertIsInstance(self.instance, BalearicIslands)

    def test_get(self):
        response = self.instance.get(self.date)
        self.assertIsInstance(response, Response)
        self.assertEqual(546.8, response.demand)
        self.assertTrue('pe_ma' in response.link)

    def test_get_all(self):
        responses = self.instance.get_all()
        self.assertIsNotNone(responses)
        for response in responses:
            self.assertIsInstance(response, Response)
示例#5
0
def fetch_exchange(zone_key1,
                   zone_key2,
                   session=None,
                   target_datetime=None,
                   logger=None) -> list:

    if target_datetime:
        raise NotImplementedError(
            "This parser is not yet able to parse past dates")

    sorted_zone_keys = "->".join(sorted([zone_key1, zone_key2]))

    ses = session or Session()

    if sorted_zone_keys == "ES->ES-IB":
        responses = BalearicIslands(ses, verify=False).get_all()
        if not responses:
            raise ParserException("ES-IB", "No responses")
    elif (sorted_zone_keys == "ES->ES-IB-MA"
          or sorted_zone_keys == "ES-IB-MA->ES-IB-ME"
          or sorted_zone_keys == "ES-IB-IZ->ES-IB-MA"):
        responses = Mallorca(ses, verify=False).get_all()
        if not responses:
            raise ParserException("ES-IB-MA", "No responses")
    elif sorted_zone_keys == "ES-IB-FO->ES-IB-IZ":
        responses = Formentera(ses, verify=False).get_all()
        if not responses:
            raise ParserException("ES-IB-FO", "No responses")
    else:
        raise NotImplementedError("This exchange pair is not implemented")

    exchanges = []
    for response in responses:

        if sorted_zone_keys == "ES-IB-MA->ES-IB-ME":
            net_flow = -1 * response.link["ma_me"]
        elif sorted_zone_keys == "ES-IB-IZ->ES-IB-MA":
            net_flow = response.link["ma_ib"]
        elif sorted_zone_keys == "ES-IB-FO->ES-IB-IZ":
            net_flow = -1 * response.link["ib_fo"]
        else:
            net_flow = response.link["pe_ma"]

        exchange = {
            "sortedZoneKeys": sorted_zone_keys,
            "datetime": get(response.timestamp).datetime,
            "netFlow": net_flow,
            "source": "demanda.ree.es",
        }

        exchanges.append(exchange)

    return exchanges
示例#6
0
def fetch_exchange(zone_key1,
                   zone_key2,
                   session=None,
                   target_datetime=None,
                   logger=None) -> list:

    if target_datetime:
        raise NotImplementedError(
            'This parser is not yet able to parse past dates')

    sorted_zone_keys = '->'.join(sorted([zone_key1, zone_key2]))

    ses = session or Session()

    if sorted_zone_keys == 'ES->ES-IB':
        responses = BalearicIslands(ses, verify=False).get_all()
        if not responses:
            raise ParserException("ES-IB", "No responses")
    elif sorted_zone_keys == 'ES->ES-IB-MA' or sorted_zone_keys == 'ES-IB-MA->ES-IB-ME' or sorted_zone_keys == 'ES-IB-IZ->ES-IB-MA':
        responses = Mallorca(ses, verify=False).get_all()
        if not responses:
            raise ParserException("ES-IB-MA", "No responses")
    elif sorted_zone_keys == 'ES-IB-FO->ES-IB-IZ':
        responses = Formentera(ses, verify=False).get_all()
        if not responses:
            raise ParserException("ES-IB-FO", "No responses")
    else:
        raise NotImplementedError('This exchange pair is not implemented')

    exchanges = []
    for response in responses:

        if sorted_zone_keys == 'ES-IB-MA->ES-IB-ME':
            net_flow = -1 * response.link['ma_me']
        elif sorted_zone_keys == 'ES-IB-IZ->ES-IB-MA':
            net_flow = response.link['ma_ib']
        elif sorted_zone_keys == 'ES-IB-FO->ES-IB-IZ':
            net_flow = -1 * response.link['ib_fo']
        else:
            net_flow = response.link['pe_ma']

        exchange = {
            'sortedZoneKeys': sorted_zone_keys,
            'datetime': get(response.timestamp).datetime,
            'netFlow': net_flow,
            'source': 'demanda.ree.es',
        }

        exchanges.append(exchange)

    return exchanges
示例#7
0
def fetch_production(zone_key='ES-IB',
                     session=None,
                     target_datetime=None,
                     logger=None):
    if target_datetime:
        raise NotImplementedError(
            'This parser is not yet able to parse past dates')

    ses = session or Session()

    # TODO: Remove verify SSL config when working without it.
    responses = BalearicIslands(ses, verify=False).get_all()

    if not responses:
        raise ParserException("ES-IB", "No response")
    else:

        data = []

        for response in responses:
            response_data = {
                'zoneKey': zone_key,
                'datetime': get(response.timestamp).datetime,
                'production': {
                    'coal': response.carbon,
                    'gas': round(response.gas + response.combined, 2),
                    'solar': response.solar,
                    'oil': round(response.vapor + response.diesel, 2),
                    'wind': response.wind,
                    'hydro': response.hydraulic,
                    'biomass': 0.0,
                    'nuclear': 0.0,
                    'geothermal': 0.0,
                    'unknown': response.unknown()
                },
                'storage': {
                    'hydro': 0.0,
                    'battery': 0.0
                },
                'source': 'demanda.ree.es',
            }

            data.append(response_data)

        return data
示例#8
0
 def setUp(self):
     self.instance = BalearicIslands()
     self.date = get('2022-06-10').format('YYYY-MM-DD')