home
Warp10 cheat sheet
GeoTimeSeries® manipulation script.
print

Date : april 2017

The WarpScript data manipulation environment allows the retrieval and analysis of data stored in the Warp 10 storage platform. It's a stack oriented language.

API endpoints

API need an X-Warp10-Token header set with a READ or WRITE token.

Send data to the platform

POST /api/v0/update

Executing a WarpScript

POST /api/v0/exec

Get raw GeoTimeSeries® data

GET /api/v0/fetch

Get GeoTimeSeries® identifier (class name and labels)

GET /api/v0/find

Remove data from the platform

GET /api/v0/delete

For setting GeoTimeSeries® attributes

POST /api/v0/meta

Fetch some metrics

During the last hour, any metric which contains os.cpu

[ 'READ_TOKEN' '~os.cpu.*' { } NOW 1 h ] FETCH

The last 10 datapoints of metric which name is exactly fuel.station

[ 'READ_TOKEN' '=fuel.station' { 'tag' 'value' } NOW -10 ] FETCH

Bucketizer

.sum .max
.min .count
.mean .first
.mean.circular .and
.mean.circular.exclude-nulls .join
.last .or
.median

Syntaxe: [ [GTS] bucketizer lastbucket bucketspan bucketcount ] BUCKETIZE

Ex: return 100 meaning datapoints from the previous GeoTimeSeries®

[ SWAP bucketizer.mean 0 0 100 ] BUCKETIZE

Reducer

.argmax .argmin
.count.exclude-nulls .count
.count.include-nulls .join
.join.forbid-nulls .max
.max.forbid-nulls .mean
.mean.exclude-nulls .mean.circular
.mean.circular.exclude-nulls .median
.min .min.forbid-nulls
.and .and.exclude-nulls
.or.exclude-nulls .or
.shannonentropy.0 .sd
.shannonentropy.1 .sum
.sum.forbid-nulls .var

Syntaxe: [ [GTS]...[GTS] [labels] reducer ] REDUCE

Ex: return a sum of aggregated GeoTimeSerie® from the previous GeoTimeSerie®

[ SWAP [ 'label1'] reducer.sum ] REDUCE

Mappers

Apply a function on each tick of each GeoTimeSeries®.

Syntaxe: [ [GTS]...[GTS] constant mapper 0 0 0 ] MAP

Ex: display Bytes instead of bits

[ SWAP 8.0 mapper.mul 0 0 0 ] MAP

Input data format

Each metric has an unique identifier. Changing just one label, create a new GeoTimeSeries®.

TIMESTAMP/LATITUDE:LONGITUDE/ALTITUDE className{label=value} VALUE

1493153321000000/49.13:6.65/12.75 device{id=1} 15

Output data format

[{
  "c": "class",
  "i": "1",
  "l": {
    "label0": "value0",
    "label1": "value1"
  },
  "a": {
    "attr0": "value0"
  },
  "v":[
    [ 1380475081000000, 3.14 ],
    [ 1380475081500000, 48.0, -4.5, 2.5],
    [ 1380475082000000, 10000000, 3.0]
  ]
},
{
  "i": "1",
  "v": [
    [ 1380475083000000, 48.1, -4.5,11000000, 42.0]
  ]
}]

If / Else

Ex: if 7 <= 4 then A else B

<% 7 4 <= %>   <% 'A' %>   <% 'B'%>   IFTE

For

Ex: for i from 1 to 10 : push i*i

1 10 <% 2 **  %> FOR

Secure Script

Cipher a script to share it

'aSecretKey' SECUREKEY
<S
  [
    'TOKEN'
    '~metric.*'
    { }
    NOW
    -1
  ] FETCH
S>

And to execute it

"secureScriptString" EVALSECURE

Filter on Geo place

The last position must be the start position

Ex: Grep all GeoTimeSerie® which have datapoints in the place

[ [ 'READ_TOKEN' '~station.*' { } NOW -1 ] FETCH
  'POLYGON ((
  47.6300000 3.8300000,
  47.6600000 3.8300000,
  47.6300000 3.7900000,
  47.6300000 3.8300000, ))'
  0.1 true GEO.WKT
  mapper.geo.within 0 0 0
]

Links

My first steps with WarpScript

http://tour.warp10.io/#1-1

List of WarpScript functions

http://www.warp10.io/reference/reference/#frameworks