Axon Queries and How to

Axon Queries and How to

Examples and How To write Axon queries

Name

Axon query

Description

Name

Axon query

Description

Find Unused Bacnet Connectors

readAll(bacnetConn).findAll(x=> readCount(point and bacnetConnRef==x->id)==0)

Finds all bacnet connectors that are not being used

Contains Search

Examples:

readAll(point).findAll point => point.dis.contains("Temp")

readAll(equip).findAll equip => equip.dis.contains("Vav")

looks for records that 'contain' the text specified in the 'contains' query

Take point descriptions from the Connector and copy it onto a property tag on the point in FIN Stack.

readAll(point and bacnetConnRef).each x=> x.diff({description:bacnetReadObjectProperty(x->bacnetConnRef,x->id,"description").colToList("value").toStr}).commit()

This query takes every point coming from a bacnet connector and adds a string property tag called description and fills in the value of this tag with the description inside the BACnet device.

priority for points

read(writable).pointWriteArray

This will show you what level, and who wrote to a certain priority for points.

create records via commit

commit(diff(null, {dis:"actions testing",actions:"",finActions}, {add}))

This will allow the user to add a new record to the dataBase with a dis tag, action string, and a finActions

marker

add / edit tags on records

readAll(jason).toRecList.map(r => diff(r, {numberTest:88})).commit

This will let you find a list of records that match the filter (Jason), and it will add the numberTest:88

tag to them. Or it will edit the tag if it already exists.

Commit Records from Trio or just a grid

ioReadTrio(`io/finCommunity.trio`).toRecList.map(r => diff(null, r,{add})).commit



remove tags

readAll(jason).toRecList.map(r => diff(r, {numberTest:99,stringTest:"test Me",-rochelle})).commit

-rochelle will find and remove all the rochelle tags, that have a jason marker

delete/remove recrods

readAll(jason).toRecList.map(r => diff(r, null,{remove})).commit

Finds all records that have the jason marker, and will remove them out of the dataBase.

keep Cols

funcs().keepCols(["name","lib","id"])

This takes a grid, in this example I just used the funcs function, and then only kept columns name,lib, and ID

readAll then Fold

readAll(point and unit=="%").foldCol("curVal",avg)

This finds all points, that are %, and it gives you the average for the curVal tag. Using the foldCol function.

foldCols

readAll(point and unit=="%").keepCols(["id","curVal","hisSize"]).foldCols(["curVal","hisSize"],"newCol",sum)

This finds all point and unit, and then keeps just the id, curVal, and hisSize columns. Then it uses a foldCols function, and

sums the curVal, and hisSize columns.

uriPath

`http://host:81/a/b/file.txt`.uriPath

Takes a URI, and breaks out the path into a number of rows

get date info

now().format("MMM")

This query gets the current time, and then formats it so it's Month.

Time Formats

format(today()-9mo, "MMMM") This will show you what 9 months ago today was, and show you the Month only

YY Two digit year 07 YYYY Four digit year 2007 M One/two digit month 6, 11 MM Two digit month 06, 11 MMM Three letter abbr month Jun, Nov MMMM Full month June, November D One/two digit day 5, 28 DD Two digit day 05, 28 DDD Day with suffix 1st, 2nd, 3rd, 24th WWW Three letter abbr weekday Tue WWWW Full weekday Tuesday

find all discover sessions, or find the devices that were previsouly discovered

finDiscoveryRef==@1da849e8-612c4a16 finDiscovery



start from a gird

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid

Take a grid, and start working with it

read a string and remove 1st 5 lines, then turn it back into a grid

ioReadStr(`io/BV506600.txt`).split("\n").get(4..-1).concat("\n").ioReadCsv()



Size

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid.size()

.size() from the grid will tell you how many rows you have

First row

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid.first()

Gives you the first row

first and second row

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid[0..1]

[0..1] will return the first 2 rows

foldCol

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid.foldCol("area",sum)

This takes the area column and folds it using sum

sort

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid.sort("area")

This sorts it by the area column. sortr does a reverse sort

Rename Col

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid.renameCol("area","sqFT")

This will rename the column to a different name

Find a tag on a record ref

readAll(equip and siteRef->dis=="Short Pump")

Finds all equipments and then looks for all of their siteRefs that the tag name dis = Short Pump.

The -> is what allows you to goto that siteRefs record and find a tag that matches the dis name

math on columns

readAll(site).map(r => r.set("delta",r["area"]*r["storeNum"])).keepCols(["id","area","storeNum","delta"])

Find sites, and do a map, then create a new column called delta, and multiple the area by the storeNum. Then

we just keep 4 columns.

find all tags on a record

readAllTagNames(equip)

Find all the tags on a certain record

Nav Move

navMove("equip",@18c1160e-a1bfafe2,@18b79056-84738485)

This uses a equip tree to move on record to a different record. IE... To take a point from one equipment, and move it to

another equipment. navMove will look at navMeta, and it will make sure that the correct refs are on each record.

contains

readAll(site).findAll site => site.dis.contains("Car")

This one finds where the dis name contains "Car"

sqlConn

read(sqlConn).sqlQuery("select * from ae_s_bld_c where fac_id='PHX'")

sql Query that finds all of Assetworks buildings, where it == PHX

goto and find tags

read(point)->equipRef->siteRef

This read something, and find tags, or find refs, and then find tags.

read point

read(point)->equipRef->siteRef->area

find a point, then goto the equip, then goto the site, and then return the area tag

try and map

readAll(point).map(row => {area: try row->equipRef->siteRef->area catch 0})

What this function does is look and find every point, then use map to go through every row, and goto the equip, then the

site, and return the area. The reason I put try there is because it was throwing an error, because one of the rows didn't have

an equipRef, so now if it gets an error, it just returns 0. The reason we put area was only because we wanted to name the column in

the grid.

find crap, and use map

readAll(point and equipRef).map(row => {jason: try row->equipRef->siteRef->area catch 0, id: row-> id, equipName: try row->equipRef->dis catch 0})



Multiple valuations and

comparing each other

readAll(point and kind =="Number" and kw).map(row => {site: try row -> equipRef->siteRef->dis catch 0, currentValue: try row -> curVal catch 0}).foldCol("currentValue",sum)

readAll(point and kind =="Number" and kw).map(row => {site: try row -> equipRef->siteRef->area catch 0}).foldCol("site",sum)





I fold the first axon query, and then I divide the 2nd axon query by itself. This is just cool :}

Understanding maps is very important

haystackCall

http://localhost/haystack/read?filter=axType == "kitControl:Ramp"



haystackCall Read

read(haystackConn and dis == "nh_large").haystackReadAll(axType == "kitControl:Ramp")



more

read(haystackConn and dis == "nh_large").haystackReadAll(axSlotPath == "slot:/Drivers/NiagaraNetwork/AHU1/points/SAT")





read(haystackConn and dis == "nh_large").haystackReadAll(his)

finds histories that exist in nHaystack



read(haystackConn and dis == "nh_large").haystackHisRead(@c.c2xvdDovRHJpdmVycy9OaWFnYXJhTmV0d29yay9BSFUxL3BvaW50cy9TQVQ~, today)

This let's you read a history from a haystack server, in this case nHaystack, and that do normal history stuff.

nav Uri

navReadByUri(`equip:/Jason/tom`)

This is the way you can query a point or equip by using the navID... It will check the dis:"" or the navName:"" and return the result. :}

Sync all Haystack histories

readAll(haystackHis).haystackSyncHis(null)

This will find all haystack histories, and it will sync them. IE... Pull the history out of the haystack client, and store it in FIN Stack

finNavChildren

finNavChildren("equip")

This will let you walk the tree

finNavChildren fo down

finNavChildren("equip",180082a9-a72ca020)

This looks for the equp tree, and you pass in an ID

finNavLevels

finNavLevels("equip",@180082a9-a72ca020)

This shows you where you are at in the tree,

NIagara Haystack query

read(niagara).haystackReadAll(siteUri=="site:/UCLA/")

This is how to read n Haystack SiteUri

Haysatck url query

http://174.129.123.55:81/haystack/read?filter=site

This is how to query direct from the browser

List and function in a list

[1,2,3,4,5,6,2+4,today()]

This is a list with functions in them



[1,2,3,4,5,6,2+4,today()].get(2..5)





[1,2,3,4,5,6,2+4,today()].get(-1)



Dict

{dis:"jason",person: marker(),bday:today()}





{dis:"jason",person: marker(),bday:today(),-tagToBeRemoved}



Grid

[{dis:"jason",person: marker(),bday:today()},{dis:"jason",person: marker(),bday:today(),jason, frank, feorge}].toGrid



add meta data

[{dis:"jason",person: marker(),bday:today()},{dis:"jason",person: marker(),bday:today(),jason, frank, feorge}].toGrid.addMeta({title:"the title",jason,test: today()})

Run this and you will see how to add meta data to a grid, and how to run a function in a grid

get Meta data

read(point).hisRead(lastWeek).hisRollupAuto.meta->hisRollupDis

This will get you data from the meta data

convert units

40°C.to("°F")

.to converts things. ONly like dimensions. This exists in the units text



40m.to("ft")



add unit

10.as("ft") or you can use this too 10m.as("ft")

add a unit or switch a unit with no conversion



today()-4day

Time Units- s,min,h,day,wk,mo,yr



today()- 2013-01-01

I can take today and - it from something else. Very cool

read csv file

ioReadCsv(`io/import-points.csv`)

Read csv file in my dataBase



"ABCDEFGHIJKLMNOP".get(5..-2)





{dis:"BOB",day:1980-12-12,person}.get("dis")



trap

{dis:"BOB",day:1980-12-12,person}.trap("dis") {dis:"BOB",day:1980-12-12,person}.->dis

get is [] and trap is -> ..... Get

no exception

read(siteMeter and kw and notFound, false)

false makes it not return an error



do x: true; if (x) "x is true" else "x is false"; end



error message

throw "somthing really bad just happened, and I sent it to the error"

Here is how you can throw an error message

map

[2,3,4,5,6,10,12].map( val => val * 2)





[2,3,4,5,6,10,12].findAll(val => val > 8)



find the spread of something

[2,3,4,5,6,10,12].fold(spread)

This is great to see how much something hunted during a certain time. Great way

find

readAll(site).map row => {dis: row->dis, areaTest: row->area}





readAll(site).findAll row => row ->area > 10_000



find points in every row

readAll(point).findAll row => row->navName.contains("Temp")

find point names by looping through a lot of crap

add Haystack database

finCreateHaystackDb([@1902cc8c-adde74db], "sep:/" , true)

@... the id of the haystack connector and the true parameter is adding history to the points that don;t have it

you can use it without the true part

the "sep:/" is needed after Jarmy new changes - this is the default for Niagara and otherwise it can be: "/equip"

default excluded tags when adding a database

finHaystackExcludedTags()

you will get all the default excluded tags

you just need to add a new record in folio with finHaystackExcludedTags and after it the other markers that you want to exclude(so that you add some more to the excluded list)

the default excluded ones are: "axSlotPath",axHistoryRef,siteUri,id" 

contains query

connExts().findAll val => val->ext.contains("haystack")

Take a grid, and findAll that contains haystack

Debugging a connector

logSetLevel("haystack", "debug")

This puts the debugger on in skyspark. You then can look at the data in the console.

Read Tag Values

readAllTagVals(point and temp and air,"equipRef")

This one will show you all the values of a tag, based on a filter. It will show all the unique values. It's pretty helpful actually

Lint for a record

lint().find r => r->targetRef == 180082a9-d9aecffe

This will find the record Id for each lint error

each rec

readAll(point and equipRef->ahuRef->id==@191d48c4-95263c67).each rec => rec.pointEmergencyOverride(67%)

write each point in a readAll

map example

readAll(point and equipRef->ahuRef->id==@191d48c4-95263c67).map(rec => {result: rec.pointEmergencyOverride(67%)})

The above each example is better then the above solution which is a map solution. The map solution outputs a dict, so that why we need the { } here

boxWisker Test function below

readAll(point and sensor and temp and hisSize).map(r=>r.boxWisker(2012-05))

Make sure the point has a history

finPointSummary

readAll(site).finPointSummary(ahu and not rooftop,point and summary)

This will let us build a summary page for equipment and points. Kind of like FQL. The function takes 3 paramteres. 1. site or floor, or any record. 2. Takes a filter for equipment. IE... rooftop. 3. Takes a filter for a point. Typically this will be like floorSummary.

So the the query to left does this. Finds the first site, and then finds equipment under that site that is an ahu and not a rooftop, then it finds all the points that have a summary tag on it. This will then return a grid with equips as rows, and points as colums

readAllTagNames find kind

readAllTagNames(point).findAll r => r["kind"] == "Ref"

This will find all the tags, and it will let you find all the ref tags. This will be helpful in our search for tags.

random grid

["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul","Aug","Sep","Oct","Nov","Dec"].toGrid.map((r,i)=>{dis:r->val, value:random(0..100), index: i+1})

This let's you name a bunch of crap, and get a demo grid that comes out. :}

week for a year

read(kw and hisSize).hisRead(lastYear).hisRollup(sum,1wk).map((r,i) => {ts: r->ts.format("MMM"), v0: r->v0, week:"Wk " + (i+1)})

This won't show the right week if you don't do the entire year. IE...

taskVarTree

taskVarTree(@195357e2-faf5560f,@19042bad-f79d61b9 )

This query shows you a list of all Points/Tags/ and Variables on a particular program, and target. It finds the target, and then

shows every point/tag/variable on the target, then it finds every ref on the target, and finds all of it's points/tags/varaibles. This is

used in the UI to be able to auto complete creating variables. The function 1st parameter takes the program ID, the 2nd parameter takes the taret ID.



do foo:read(projMeta); if (foo.has("dis")) foo->dis else context()->projName end



taskVarsLinkedTo

taskVarsLinkedTo(@19a02c31-673132ee, @19042bad-73b30a28, "cool1")

This function is currently working on 1000, and will tell you all the places that this var is being used in.

findAll Example

readAllTagNames(point).findAll r => r ->kind.contains("Number")

This is an example on how to go through a grid, and find all things that contains a certain text

findAll with or

readAllTagNames(point).findAll r => (r ->kind.contains("Number")) or (r ->kind.contains("Str"))

This is an example of a find all with an or.

nHaystack and haystack Sever

http://localhost:85/api/demo/read?filter=site

This shows you how to query all the sites in a haystack server. Doing a get out of haystack to fo a filter on points

hisRead

http://localhost:85/api/demo/hisRead?id=@Carytown.RTU-1.DischargePressure&range=today

Example of getting a his out of haystack via a get.

hisRead date range

http://localhost:85/api/demo/hisRead?id=@Carytown.RTU-1.DischargePressure&range=%222013-01-05,2013-01-09%22



eval and expr

http://localhost:85/api/demo/eval?expr=readAll(site)

Axon query in the url

set points in monitor mode

taskSetMonitorMode(@19a167ef-14270409, @19042bad-73b30a28, {setPoint: true, zoneTempSp: true, returnTemp: true, blah: true, writeTempPID: true, link1: true})

This is used in Control logic and it lets you set points into a monitor mode. You can only set 8 points in at once.

poll the points from monitor

taskMonitorPoll(@19a167ef-14270409, @19042bad-73b30a28, null)

This is how you poll the points in monitor mode

tasksVarsLinkedTo

taskVarsLinkedTo(@19c3d30f-63117dc0, @19042bad-73b30a28, "zoneTempSp")

This finds all the other programs tasks that are using this Variable. Very helpful for troubleshooting

programVarLocs

programVarLocs(@19c3d30f-63117dc0)

This finds all the locations in a program that the variable is used, and tells you if it's being set or not.

one liner if statement

if (read(projMeta).has("dis")) read(projMeta)->dis else context()->projName

if this then tha

obix Server

/api/demo/ext/obix

This is the path to the obix server. FIN Stack is a obix client and obix server.

obix server

Server URIs

The following table summarizes the URIs of the Obix server API:

Uri Object ------------------------------- ------------- /api/{proj}/ext/obix/ lobby /api/{proj}/ext/obix/about/ about /api/{proj}/ext/obix/batch/ batch op /api/{proj}/ext/obix/watchService/ watch service /api/{proj}/ext/obix/watch/{id}/ watch operations /api/{proj}/ext/obix/query/{filter} query recs using filter /api/{proj}/ext/obix/rec/{id|name}/ record /api/{proj}/ext/obix/rec/{id|name}/{tag} tag /api/{proj}/ext/obix/icon/{id}/{uri} icon tunnelling

Here are the options



http://finanalytics.j2inn.com:999/api/demo/ext/obix



query or filter

http://finanalytics.j2inn.com:999/api/demo/ext/obix/query/curVal%3E5

This is how you can query obix. query/and it takes a filter

gridColKinds(grid)

[{dis:"Site-A", area:2300ft²},     {dis:"Site-B", area:3100ft²},     {dis:"Site-C", area:1950ft²}].toGrid().gridColKinds()

This will take any grid and return you a list of the unique tags, and tag counts

scalar

age:34



dictionary

{jason,brihhhs,name:"ddddd"}



list

["dfsd","dsfsdf","SSSSS"]



Grid "list of Dictionaries"

[{age:45,lastName:"Briggs",ahu,temp,sensor},{age:45,lastName:"Briggs",sensor}]



Muliple points

readAll(point and equipRef->rooftop and hisSize>20).hisRead(2012-12-01).hisInterpolate()

This shows how you can show multiple points on a chart

related graphics

readById(@19042bad-0aa06641).finGraphicOn(true)

This function will show you all the related graphics for a record

grid to commit

ioReadCsv(`io/UF_Devices.csv`).floridaImport().toRecList.map( row => diff(null,row,{add})).commit()

this takes a grid, and commits it to the database

read files out of a directory

ioDir(`io/`)

This let's us read files right out of a directory

read a bacnet Schedule

read(bacnetConn).bacnetScheduleRead(@pointRef) read(bacnetConn).bacnetScheduleRead("17:2")

This will read all the events from a bacnet Schedule

 write a weekly schedule to a bacnet Schedule point

 

read(bacnetConn).bacnetScheduleWrite(@pointRef,scheduleHis(@scheduleRef,thisWeek() +1day , {timeline})) read(bacnetConn).bacnetScheduleWrite("17:2",scheduleHis(@scheduleRef,thisWeek() +1day , {timeline}))

 This will write all the events for a week into a bacnet Schedule



finPointSummary

readAll(site).finPointSummary(ahu and rooftop,cmd and point)

Here is a cool way where point summary will just work :}

zip selected records

ioZipEntry(`io/haystack/Archive.zip`,`/vav.trio`).ioReadTrio()



read csv file and return number of unique records

ao: ioReadCsv(`io/test/bacnetList.csv`).findAll(row => row->dis.contains(":")).map(r => {new:r->dis.split(":").get(-2)}).map(r => {test:r->new.split(".").get(-1)}).unique("test").size()



rebuildDocs()

rebuildDocs()

This should just do a fresh rebuild of the docs

finBackupRecord()

finBackupRecord(@Gaithersburg.RTU-1,{files:true, references:true})

This will create a backup of all the records with the specified equip ref

@Gaithersburg.RTU-1 is the equip ref that will be present on all imported files in the graphicOn tag ( graphicOn: "equip and id==@Gaithersburg.RTU-1")

finRestoreRecord()

finRestoreRecord(@1a026bc8-a4879a4b)

This will restore all the records with the specified id

@1a026bc8-a4879a4b is the ref of the backUp created with the above function

trio and commit it

ioReadTrio(`io/HUEBackup.trio`).toGrid().removeCols(["dis","mod"]).toRecList.map( row => diff(null,row,{add})).commit()

remove the dis tag first, before re-committing

toAlarm()

read(point and temp).toAlarm( "myAlarm", {priority:77,alarmText:"This is a bad alarm",instructions:"1. Do this 2. Do that 3. Also this 4. Foo foo and foo",alarmType})

this will put a target into alarm.

toNormal()

read(point and temp).toNormal( "myAlarm", {priority:77,alarmText:"This is a bad alarm",instructions:"1. Do this 2. Do that 3. Also this 4. Foo foo and foo",alarmType})

This will put the alarm back to normal

find task for a certain target

tasks().findAll r=> r->targetRef == @19042bad-73b30a28



find alarms by ID/target

navFilter("alarmTarget", readById(@19042bad-1077bbbc), null).alarms(2014-01-29)

navFilter("alarmTarget", readAll(equip), null).alarms(today)

Find alarms for a particular target

Find all alarms today, and the 3rd paramter is the last read timeStamp

navFilter("alarmTarget", null, null).alarms(today,null,"1739583508091440") or navFilter("alarmTarget", null, null).alarms(today,id==@20151006:overHeatedZone.overHeatedZone:1a17dcf9-7f7947ab,"1739583508091440")

The last paramter here allows you to see what alarms are new. The result of this query will give you a new number each time

How to ack alarms

alarmAck([@20151006:overHeatedZone.overHeatedZone:1a17d935-2e1ab4be,])

This is how to ack alarms

find notes for a particular target

navFilter("noteTarget", @19042bad-73b30a28, null).notes({  }).noteSummary



find notes that are open for a target

navFilter("noteTarget", @19042bad-73b30a28, null).notes({ state:"open" }).noteSummary