ChristianTremblay / pyhaystack

Pyhaystack is a module that allow python programs to connect to a haystack server project-haystack.org. Connection can be established with Niagara Platform running the nhaystack, Skyspark and Widesky. For this to work with Anaconda IPython Notebook in Windows, be sure to use "python setup.py install" using the Anaconda Command Prompt in Windows. If not, module will be installed for System path python but won't work in the environment of Anaconda IPython Notebook. You will need hszinc 1.3+ for this to work.
Apache License 2.0
74 stars 31 forks source link

Call SkySpark Functions #53

Closed p2ya closed 7 years ago

p2ya commented 7 years ago

I wanted to ask if we can call developed functions in SkySpark with specific inputs through pyhaystack and get the result back ?

ChristianTremblay commented 7 years ago

I will need more details. I know very little from skyspark and I don't have access to a site where I can make tests. Is there a way to call functions from REST API ?

sjlongland commented 7 years ago

I think I helped @pierresigwalt with this a few weeks back. It's an eval call, correct?

We managed to do it with a call like this:

self.session._get_grid('eval',expr='expr=navFilter("sparkTarget",readAll(equip)).sparks(2017-02).sparkHis', callback=lambda *a, **k: None)

Not friendly, we're calling private methods here… but doable.

We will have to add an evalexpr() endpoint to the SkySpark classes methinks… that'll wrap the above code up in a nice easy-to-call function.

pierresigwalt commented 7 years ago

Exactly,

I was able to request particular data using the library.

Code sample:

def get_eval(self, arg_expr):
        url = '/eval?expr=%s' % arg_expr
        result = self.session._get_grid(url, callback=lambda *a, **k: None)
        return result
ChristianTremblay commented 7 years ago

@pierresigwalt @sjlongland I think this should be implemented in skyspark client, and documented. Skyspark is widely used and custom functions compliance inside pyhaystack can be a game changer for someone considering using python and Skyspark vs only Skyspark. Pierre's function is clear.

sjlongland commented 7 years ago

On 05/07/17 11:14, Christian Tremblay wrote:

@pierresigwalt https://github.com/pierresigwalt @sjlongland https://github.com/sjlongland I think this should be implemented in skyspark client, and documented. Skyspark is widely used and custom functions compliance inside pyhaystack can be a game changer for someone considering using python and Skyspark vs only Skyspark. Pierre's function is clear.

Agreed. :-)

-- Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind... ...it's backed up on a tape somewhere.

ChristianTremblay commented 7 years ago

As it is a very small modification, I didn't create a feature branch. Please have a look to https://github.com/ChristianTremblay/pyhaystack/commit/de81823a0c9e82621fd4ae86101842ec810b34a0

ChristianTremblay commented 7 years ago

I corrected many little errors I made yesterday in the hurry.... I've been able to test

session.get_eval("readAll(site)")

It works great now : https://github.com/ChristianTremblay/pyhaystack/commit/469bde306dd1751837b485374f37c09e9fe93b45

ChristianTremblay commented 7 years ago

@p2ya can you confirm that we are responding to your need with get_eval function. If so, I will close the issue.

Thanks for your interest in pyhaystack

p2ya commented 7 years ago

Thanks for the update, however I get the following error: AttributeError: 'SkysparkHaystackSession' object has no attribute 'get_eval'

pierresigwalt commented 7 years ago

Hum,

What I checked is still in the develop branch (get_eval feature) so if you want to test you may use that branch instead of the master.

Christian will be able to confirm but I think it has not been pushed yet to Master.

Thank you

p2ya commented 7 years ago

Hi @ChristianTremblay , can you please let me know how I can test this or if it is possible to push it to the master branch

sjlongland commented 7 years ago

Try:

pip install git+https://github.com/ChristianTremblay/pyhaystack.git@develop
p2ya commented 7 years ago

Installed and tested, I get the following error: GetGridOperation failed When I try: op = session.get_eval("readAll(site)") op.wait() print op

p2ya commented 7 years ago

Hi @sjlongland, Any idea why I get this error and how it can be handled ?

sjlongland commented 7 years ago

Not the foggiest. I might suggest you use print op.result not print op.

The former will print the actual result, or raise the error caused, the latter just returns a string representation of the state machine which simply tells us that it didn't work, it doesn't tell us why.

p2ya commented 7 years ago

thanks for the comment @sjlongland the error is: pyhaystack.client.http.exceptions.HTTPStatusError: [Errno 404 Client Error: Not Found for url: http://IP/api/sites//eval?expr=readAll(site)] 404

it seems that the issue is double // in the http

sjlongland commented 7 years ago

That appears to suggest the server doesn't support eval.

p2ya commented 7 years ago

I can get the result when I run the same request with one "/" in the browser though as: http://IP/api/sites/eval?expr=readAll(site) rather than http://IP/api/sites//eval?expr=readAll(site)

p2ya commented 7 years ago

Hi @ChristianTremblay , you reckon this can be fixed ?

ChristianTremblay commented 7 years ago

This won't be fixed right now as I'm in the middle of my summer vacations. But I will give a high priority to this as soon as I come back.

p2ya commented 7 years ago

Hi @ChristianTremblay, no worries. Hope you have a nice holiday and looking forward to hear back from you to test this again and bring it into action.

p2ya commented 7 years ago

the latest update has fixed the issue and I can call eval function.