pyhaystack icon indicating copy to clipboard operation
pyhaystack copied to clipboard

Implementation of ability to add new entities?

Open mschrader15 opened this issue 3 years ago • 7 comments

Hey All,

Ran into this: https://github.com/ChristianTremblay/pyhaystack/blob/3c3508212c0f5a4e5f254fed4d169da91f03242d/pyhaystack/client/entity/model.py#L61

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

Thanks!

mschrader15 avatar Oct 01 '20 20:10 mschrader15

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 avatar Oct 01 '20 23:10 sjlongland

Related issue: https://github.com/ChristianTremblay/pyhaystack/issues/74

sjlongland avatar Oct 01 '20 23:10 sjlongland

@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 avatar Oct 02 '20 02:10 mschrader15

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 avatar Jan 07 '21 00:01 mschrader15

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.

sjlongland avatar Jan 10 '21 08:01 sjlongland

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

mschrader15 avatar Jan 10 '21 15:01 mschrader15

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

ChristianTremblay avatar Jan 14 '21 13:01 ChristianTremblay