示例#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,
                   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
示例#3
0
class TestIbiza(unittest.TestCase):
    def setUp(self):
        self.instance = Formentera()
        self.date = get('2022-06-19').format('YYYY-MM-DD')

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

    def test_get(self):
        response = self.instance.get(self.date)
        self.assertIsInstance(response, Response)
        self.assertIsNotNone(response.timestamp)
        self.assertEqual(response.demand, 8.8)
        self.assertEqual(response.carbon, 0.0)
        self.assertEqual(response.link['pe_ma'], 0.0)
        self.assertEqual(response.link['ma_me'], 0.0)
        self.assertEqual(response.link['ma_ib'], 0.0)
        self.assertEqual(response.link['ib_fo'], 8.8)

    def test_get_all(self):
        responses = self.instance.get_all()
        self.assertIsNotNone(responses)
示例#4
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
示例#5
0
 def setUp(self):
     self.instance = Formentera()
     self.date = get('2022-06-19').format('YYYY-MM-DD')