#988 Using applyBatchTags from nHaystack library

Mike Melillo Fri 6 May

I've seen a few threads poking at managing tags in a Tridium database via scripts or a remote tool like SkySpark, but never much coming out of them. I also believe it was mentioned that toolkit hasn't been modified to avoid breaking it for anyone who had been using it (and the time sensitivity of keeping an open source project up and running -- which is a much appreciated effort!)

Edit: specifically re this thread https://project-haystack.org/forum/topic/896

I decided to take a crack at the info on https://github.com/ci-richard-mcelhinney/nhaystack/tree/n4/nhaystack-rt/src/nhaystack ... specifically the applyBatchTags operation in https://github.com/ci-richard-mcelhinney/nhaystack/blob/n4/nhaystack-rt/src/nhaystack/server/NHServerOps.java

My background is far from the computer science/software engineering, so a lot of this is "throw at the wall until it sticks", but I came up with the following program object script. This runs within a program object in Tridium (tested on 4.11) and works as follows:

Applies the tags: {theMarker, theString:"jjj", theNum:123.235} to points found by the filter point and not his The commented out lines are playing with the HDictBuilder to create the params argument a little more elegantly, I couldn't get the syntax right for defining a dict that had anything more than marker tags, thus hard coding it a few lines down.

I'd like to work on making this script a little bit more elegant, smoother ways of defining point filters, leveraging the ids input of the applyBatchTags function and cleaner ways of defining the actual tags dict/grid that gets applied. I believe the end goal would be wrapping this, and maybe a few other scripts into some kind of Niagara Module that can be deployed, and then a remote Haystack Node, in my case SkySpark, can leverage that script using the haystack eval call.

Perhaps there is an even easier way to accomplish this, without requiring a module(?), but I'm already way out of my depth -- seeing if anyone else would like to team up!

BOrd nhsOrd = BOrd.make("station:|slot:/Services/NHaystackService");
BObject nhs = (BObject) nhsOrd.get();
    
BNHaystackService myService = (BNHaystackService) ((BINHaystackWorkerParent) ((BAbstractService) ((BInterface) nhs)));
    
HOp[] theOps = myService.getHaystackServer().ops();
    
HDictBuilder hdb = new HDictBuilder();
//HDictBuilder tagDb = new HDictBuilder();
    
//tagDb.add("testMarker1").add("marker_2").add("hvac");
//HDict tagDict = tagDb.toDict();
    
//HGridBuilder x = new HGridBuilder();
//HGrid y = x.dictToGrid(tagDict);
    
//String myString = HZincWriter.gridToString(y);
    
//System.out.println(myString);
    
hdb.add("ids", "").add("tags","theMarker theString:\"jjj\" theNum:" + 124.235").add("targetFilter", "point and not his");
hdb.add("function", "applyBatchTags");
    
HDict paramDict = hdb.toDict();
    
HGridBuilder myGridBuilder = new HGridBuilder();
HGrid paramGrid = myGridBuilder.dictToGrid(paramDict);
    
theOps[13].onService(myService.getHaystackServer(), paramGrid);

Login or Signup to reply.