Welcome to ask.woodem.org. You may post when you login through your GitHub account.

How to send computing results?

0 votes
asked May 31 by RogozhinRoman (250 points)
Thanks again for all your help before.

I want to realise transport channel between WooDEM and my program on http server. I would like to send result of calculations (namely the coordinates of the figures at each time point) by POST request on my server and process them.

From documentation I don't understand clearly from which part (module, class or function...) I can send requests with coordinates. Can you help me solve my problem?

Thanks a lot!

1 Answer

0 votes
answered Jun 1 by eudoxos (44,970 points)
selected Jun 2 by RogozhinRoman
Best answer

Hi Roman,

the easiest approach is to define python function which will do the POST request, and call it periodically from engines, something like this:

   woo.core.PyRunner(1000,"doPostData(S)") # run every 1000 steps

def doPostData(S):
    # You need http://docs.python-requests.org/ package for this, easy to install through 
    # either APT (sudo apt install python3-requests) or pip (pip3 install requests)
    import json, requests
    # let's send all node's coordinates
    # we encode the list of tuples as JSON (but can be anything the other side can accept)
    # and put into a dictionary as "coords", so that other things can be added easily
    payload={'coords':json.dumps([(n.pos[0],n.pos[1],n.pos[2]) for n in S.dem.nodes]))
    # finito

I did not test the code, but this would be the idea. Of course, if you call it in every step, it will be very slow; if you need performance, an engine like this could be implemented in c++ and send out using some efficient protocol (like protobufs or boost::serialization). My guess is, though, that most time spent will be attributable to network latencies.

Another speedup option would be to obtain lock, start the request and let it continue in a separate thread (releasing the thread when done); the function would send data only if the previous request is done, thus not slowing down the computation. Many options, all depends on what exactly you need.

Let me know about your progress, it is an interesting task.

Cheers, Vaclav

commented Jun 2 by RogozhinRoman (250 points)

Thank you so much, Vaclav! I'll keep you informed.