Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of ability to add new entities? #99

Open
mschrader15 opened this issue Oct 1, 2020 · 7 comments
Open

Implementation of ability to add new entities? #99

mschrader15 opened this issue Oct 1, 2020 · 7 comments

Comments

@mschrader15
Copy link

Hey All,

Ran into this:

raise NotImplementedError("To be implemented in %s" % self.__class__.__name__)

Is it possible to add new entitles to SkySpark with pyhaystack? Looking to automate the process of adding equipment and sensor points.

Thanks!

@sjlongland
Copy link
Collaborator

If you can point us to documentation on how to do that, sure. We'll look at adding it.

At the moment, the only way I know of in nHaystack to edit the asset model is via the workbench, and I have no idea how entities get into SkySpark. The only implementation that I know of which supports this is WideSky.

@sjlongland
Copy link
Collaborator

Related issue: #74

@mschrader15
Copy link
Author

@sjlongland You are probably right. I will reach out to SkySpark and see if it is even possible per #74

I'll close this issue for now

@mschrader15
Copy link
Author

mschrader15 commented Jan 7, 2021

Follow up to this, I was able to add new equipment points to our skyspark server using:

    def _create_equipment_grid(self, equip_name, markers):
        grid = hszinc.Grid()
        grid.metadata['commit'] = 'add'
        # grid.metadata['projName'] = 'Springfield'
        grid.column['dis'] = {}
        grid.column["equip"] = {}
        grid.column["siteRef"] = {}
        grid.column["navName"] = {}
        #grid.column['disMacro'] = {}
        g = {'dis': equip_name, 'navName': equip_name, 'equip': hszinc.MARKER, "siteRef": self._site.id}
        for marker in markers:
            grid.column[marker] = {}
            g[marker] = hszinc.MARKER
        grid.append(g)
        return grid

and then passing the grid to PyHaystack's protected _post_grid method:

    def _post_grid(self, g):
        r = self.session._post_grid(grid=g, callback=None, uri='commit')
        return r

I added measurement points in the same way:

    def _create_measurement_grid(self, method, name, markers, unit, kind,):
        grid = hszinc.Grid()
        grid.metadata['commit'] = 'add'
        # grid.column['dis'] = {}
        grid.column['navName'] = {}
        grid.column['disMacro'] = {}
        grid.column["siteRef"] = {}
        grid.column["equipRef"] = {}
        grid.column["tz"] = {}
        grid.column["kind"] = {}
        g = {'navName': name, 'disMacro': '$equipRef $navName', "siteRef": self._site.id, "equipRef": self._equip.id,
             'unit': unit, 'tz': str(self._site.hs_tz), 'kind': kind}
        for marker in markers:
            grid.column[marker] = {}
            g[marker] = hszinc.MARKER
        grid.append(g)
        return grid

where method is 'add'

@mschrader15 mschrader15 reopened this Jan 7, 2021
@sjlongland
Copy link
Collaborator

sjlongland commented Jan 10, 2021

This is an interesting development indeed.

To achieve parity with what WideSky permits, we'd need the ability to:

  • add new entities (commit endpoint looks to be the one that does this)
  • mutate entities (maybe doable via commit as well) by:
    • adding new tags
    • changing the values of existing tags
    • deleting tags
  • delete entities

If we can do those things, say via curl, we can most certainly implement it in pyhaystack. The "CRUD" operations in WideSky would be a good starting point for implementing this.

@mschrader15
Copy link
Author

mschrader15 commented Jan 10, 2021

I have had success mutating existing entities in SkySpark using:
grid.metadata['commit'] = 'update' instead of grid.metadata['commit'] = 'add'. In both cases I used the commit endpoint
I have used this to add new tags, though haven't tried to overwrite or remove existing tags.

We actually just ran into a use case where it would've been convenient to delete entities using pyhaystack, but the low # of entities made it more efficient to just delete them using SkySparks UI

@ChristianTremblay
Copy link
Owner

I like that, it adds a nice scripting possibility to pyhaystack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants