TulipaEnergy / esdl4tulipa

Apache License 2.0
0 stars 1 forks source link

Associate profiles to assets & flows #6

Open suvayu opened 1 month ago

suvayu commented 1 month ago

Blocked by #8

Profiles

Associating to assets/flows

Implementation notes

When visiting the nodes to form the list of assets and flows, also extract the corresponding profiles.

accumulate = []
for node in nodes:
    result = visitor(node)
    if is_asset(result):
        asset_profile = get_asset_profile(result)
        accumulate += [(result, asset_profile)]
    if is_flow(result):
        flow_profile = get_flow_profile(result)
        accumulate += [(result, flow_profile)]
suvayu commented 1 month ago

Can't figure out how to download the profile.

MWE:

from esdl4tulipa.parser import load, debug, parse_graph, find_edges, fill_asset

tiny_ensys = debug("tests/data/esdl/Tiny.esdl")
wt = list(tiny_ensys.instance[0].area.asset)[1]
wt
# <esdl.esdl.WindTurbine at 0x7fbaf1b6f5c0>
wt_port = wt.port[0]
wt_prof = wt_port.profile[0]
wt_prof
# <esdl.esdl.InfluxDBProfile at 0x7fbaf1b90260>

from esdl.profiles.influxdbprofilemanager import InfluxDBProfileManager, InfluxDBClient, ConnectionSettings

settings = ConnectionSettings(host=wt_prof.host, port=wt_prof.port, username='', password='', database=wt_prof.database, ssl=False, verify_ssl=False)
influxmgr = InfluxDBProfileManager(settings=settings)
---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
File ~/.virtualenvs/esdl4tulipa/lib/python3.12/site-packages/urllib3/connection.py:198, in HTTPConnection._new_conn(self)
    197 try:
--> 198     sock = connection.create_connection(
    199         (self._dns_host, self.port),
    200         self.timeout,
    201         source_address=self.source_address,
    202         socket_options=self.socket_options,
    203     )
    204 except socket.gaierror as e:

File ~/.virtualenvs/esdl4tulipa/lib/python3.12/site-packages/urllib3/util/connection.py:85, in create_connection(address, timeout, source_address, socket_options)
     84 try:
---> 85     raise err
     86 finally:
     87     # Break explicitly a reference cycle

File ~/.virtualenvs/esdl4tulipa/lib/python3.12/site-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle

TimeoutError: [Errno 110] Connection timed out

The above exception was the direct cause of the following exception:

ConnectTimeoutError                       Traceback (most recent call last)
...
ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x7fbaf1ba77a0>, 'Connection to 10.30.2.1 timed out. (connect timeout=None)')

The above exception was the direct cause of the following exception:

MaxRetryError                             Traceback (most recent call last)
...
MaxRetryError: HTTPConnectionPool(host='10.30.2.1', port=8086): Max retries exceeded with url: /query?q=SHOW+DATABASES&db=energy_profiles (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7fbaf1ba77a0>, 'Connection to 10.30.2.1 timed out. (connect timeout=None)'))

During handling of the above exception, another exception occurred:

ConnectTimeout                            Traceback (most recent call last)
...
ConnectTimeout: HTTPConnectionPool(host='10.30.2.1', port=8086): Max retries exceeded with url: /query?q=SHOW+DATABASES&db=energy_profiles (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7fbaf1ba77a0>, 'Connection to 10.30.2.1 timed out. (connect timeout=None)'))
suvayu commented 1 month ago

Also this:

wt_prof.getProfile()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[103], line 1
----> 1 wt_prof.getProfile()

File ~/.virtualenvs/esdl4tulipa/lib/python3.12/site-packages/esdl/esdl.py:628, in GenericProfile.getProfile(self, from_, to, aggregationPrecision)
    626 def getProfile(self, from_=None, to=None, aggregationPrecision=None):
--> 628     raise NotImplementedError('operation getProfile(...) not yet implemented')

NotImplementedError: operation getProfile(...) not yet implemented
suvayu commented 1 month ago

Maybe it fails because the host ip is an internal ip (10.x.x.x).

In [12]: wt_prof.host
Out[12]: 'http://10.30.2.1'

Looks like you really need to be on a TNO computer.

suvayu commented 1 month ago

@clizbe I need help here. I need a "recipe" to download the profiles.

Ideally it should work from the public internet, but if that's impossible, a compromise that allows us to move forward should be acceptable for now.

clizbe commented 1 month ago

Guess it's time to install Python. 😅

clizbe commented 1 month ago

@suvayu I ran your connection script (I think it ran properly) and I got this error:

Traceback (most recent call last):
  File "C:\Users\clisbyle\OneDrive - TNO\GitHub\esdl4tulipa\.venv\Lib\site-packages\urllib3\connection.py", line 196, in _new_conn
    sock = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\clisbyle\OneDrive - TNO\GitHub\esdl4tulipa\.venv\Lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    raise err
  File "C:\Users\clisbyle\OneDrive - TNO\GitHub\esdl4tulipa\.venv\Lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

It goes on a lot longer with downstream errors about "connection." That's running it from a home internet connection and also running while connected to TNO from home (I guess through a VPN?) I'll try it from the office if I go in today.

clizbe commented 1 month ago

It's not working for me either. Even if I'm on TNO and logged into the MapEditor (just in case that made a difference). So I'm going to email Wester and the other guys from ACE. I'll cc you so you can add details. :)