Falkonry Python Client to access Falkonry Condition Prediction APIs
$ pip install falkonryclient
* Create Eventbuffer
* Retrieve Eventbuffers
* Create Pipeline
* Retrieve Pipelines
* Add data to Eventbuffer (csv/json, stream)
* Retrieve output of Pipeline
* Create subscription for Eventbuffer
* Create publication for Pipeline
* Get auth token from Falkonry Service UI
* Read the examples provided for integratioin with various data formats
Data :
{"time" :"2016-03-01 01:01:01", "tag" : "signal1", "value" : 3.4}
{"time" :"2016-03-01 01:01:02", "tag" : "signal2", "value" : 9.3}
or
time, tag, value
2016-03-01 01:01:01, signal1, 3.4
2016-03-01 01:01:02, signal2, 9.3
Usage :
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
eventbuffer = Schemas.Eventbuffer()
eventbuffer.set_name('Motor Health' + str(random.random())) #set name of the Eventbuffer
eventbuffer.set_time_identifier('time') #set property to identify time in the data
eventbuffer.set_time_format('iso_8601') #set format of the time in the data
eventbuffer.set_signals_tag_field('tag') #property that identifies signal tag in the data
eventbuffer.set_value_column('value') #property that identifies value of the signal in the data
#create Eventbuffer
createdEventbuffer = falkonry.create_eventbuffer(eventbuffer)
#add data to Eventbuffer
String data = "{\"time\" : \"2016-03-01 01:01:01\", \"tag\" : \"signal1\", \"value\" : 3.4}" + "\n"
+ "{\"time\" : \"2016-03-01 01:01:02\", \"tag\" : \"signal2\", \"value\" : 9.3}";
inputResponse = falkonry.add_input_data('eventbuffer_id', 'json', {}, data)
Data :
{"time" :"2016-03-01 01:01:01", "tag" : "signal1_thing1", "value" : 3.4}
{"time" :"2016-03-01 01:01:01", "tag" : "signal2_thing1", "value" : 1.4}
{"time" :"2016-03-01 01:01:02", "tag" : "signal1_thing2", "value" : 9.3}
{"time" :"2016-03-01 01:01:02", "tag" : "signal2_thing2", "value" : 4.3}
or
time, tag, value
2016-03-01 01:01:01, signal1_thing1, 3.4
2016-03-01 01:01:01, signal2_thing1, 1.4
2016-03-01 01:01:02, signal1_thing2, 9.3
2016-03-01 01:01:02, signal2_thing2, 4.3
Usage :
from falkonryclient import client as Falkonry
from falkonryclient import schemas as
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
eventbuffer = Schemas.Eventbuffer()
eventbuffer.set_name('Motor Health') #set name of the Eventbuffer
eventbuffer.set_time_identifier('time') #set property to identify time in the data
eventbuffer.set_time_format('iso_8601') #set format of the time in the data
eventbuffer.set_thing_identifier('motor') #set property to identify things in the data
eventbuffer.set_signals_tag_field("tag") #property that identifies signal tag in the data
eventbuffer.set_signals_delimiter('_') #delimiter used to concat thing id and signal name to create signal tag
eventbuffer.set_signals_location('prefix') #part of the tag that identifies the signal name
eventbuffer.set_value_column("value") #property that identifies value of the signal in the data
#create Eventbuffer
createdEventbuffer = falkonry.create_eventbuffer(eventbuffer)
#add data to Eventbuffer
String data = "{\"time\" : \"2016-03-01 01:01:01\", \"tag\" : \"signal1_thing1\", \"value\" : 3.4}" + "\n"
+ "{\"time\" : \"2016-03-01 01:01:01\", \"tag\" : \"signal2_thing1\", \"value\" : 1.4}" + "\n"
+ "{\"time\" : \"2016-03-01 01:01:02\", \"tag\" : \"signal1_thing1\", \"value\" : 9.3}" + "\n"
+ "{\"time\" : \"2016-03-01 01:01:02\", \"tag\" : \"signal2_thing2\", \"value\" : 4.3}";
inputResponse = falkonry.add_input_data('eventbuffer_id', 'json', {}, data)
Data :
{"time":1467729675422, "signal1":41.11, "signal2":82.34, "signal3":74.63, "signal4":4.8}
{"time":1467729668919, "signal1":78.11, "signal2":2.33, "signal3":4.6, "signal4":9.8}
or
time, signal1, signal2, signal3, signal4
1467729675422, 41.11, 62.34, 77.63, 4.8
1467729675445, 43.91, 82.64, 73.63, 3.8
Usage :
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
eventbuffer = Schemas.Eventbuffer()
eventbuffer.set_name('Motor Health') #set name of the Eventbuffer
eventbuffer.set_time_identifier('time') #set property to identify time in the data
eventbuffer.set_time_format('iso_8601') #set format of the time in the data
#create Eventbuffer
createdEventbuffer = falkonry.create_eventbuffer(eventbuffer)
#add data to Eventbuffer
String data = "{\"time\":1467729675422,\"signal1\":41.11,\"signal2\":82.34,\"signal3\":74.63,\"signal4\":4.8}" + "\n"
+ "{\"time\":1467729668919,\"signal1\":78.11,\"signal2\":2.33,\"signal3\":4.6,\"signal4\":9.8}";
inputResponse = falkonry.add_input_data('eventbuffer_id', 'json', {}, data)
Data :
{"time":1467729675422, "thing": "Thing1", "signal1":41.11, "signal2":82.34, "signal3":74.63, "signal4":4.8}
{"time":1467729668919, "thing": "Thing2", "signal1":78.11, "signal2":2.33, "signal3":4.6, "signal4":9.8}
or
time, thing, signal1, signal2, signal3, signal4
1467729675422, thing1, 41.11, 62.34, 77.63, 4.8
1467729675445, thing1, 43.91, 82.64, 73.63, 3.8
Usage :
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
eventbuffer = Schemas.Eventbuffer()
eventbuffer.set_name('Motor Health') #set name of the Eventbuffer
eventbuffer.set_time_identifier('time') #set property to identify time in the data
eventbuffer.set_time_format('iso_8601') #set format of the time in the data
eventbuffer.set_thing_identifier('thing1') #set property to identify things in the data
#create Eventbuffer
createdEventbuffer = falkonry.create_eventbuffer(eventbuffer)
#add data to Eventbuffer
String data = "time, thing, signal1, signal2, signal3, signal4" + "\n"
+ "1467729675422, thing1, 41.11, 62.34, 77.63, 4.8" + "\n"
+ "1467729675445, thing1, 43.91, 82.64, 73.63, 3.8";
inputResponse = falkonry.add_input_data('eventbuffer_id', 'json', {}, data)
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
#return list of Eventbuffers
eventbuffers = falkonry.get_eventbuffers()
import os, sys
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
stream = io.open('./data.json')
response = falkonry.add_input_stream('eventbuffer_id', 'json', {}, stream)
import os, sys
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
stream = io.open('./data.csv')
response = falkonry.add_input_stream('eventbuffer_id', 'csv', {}, stream)
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
eventbuffer.set_name('Motor Health')
eventbuffer.set_time_identifier('time')
eventbuffer.set_time_format('iso_8601')
createdEventbuffer = falkonry.create_eventbuffer(eventbuffer)
assessment = Schemas.Assessment()
.set_name('Health') #set name for the Assessment
.set_input_signals(['current', 'vibration']) #add signal data
pipeline = Schemas.Pipeline()
.set_name('Motor Health') #set name for the Pipeline
.set_eventbuffer(createdEventbuffer.get_id()) #set Eventbuffer for the Pipeline
.set_input_signals({'current' : 'Numeric', 'vibration' : 'Numeric'}) #signals present in the Eventbuffer
.set_assessment(assessment) #add an Assessment to the Pipeline
#create Pipeline
createdPipeline = falkonry.createPipeline(pipeline)
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
#return list of Pipelines
pipelines = falkonry.getPipelines()
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
data = '{"time" : "2011-03-26T12:00:00Z", "car" : "HI3821", "end" : "2012-06-01T00:00:00Z", "Health" : "Normal"}'
inputResponse = falkonry.add_verification('pipeline_id', 'json', {}, data)
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
data = 'time,car,end,Health' + "\n"
+ '2011-03-26T12:00:00Z,HI3821,2012-06-01T00:00:00Z,Normal' + "\n"
+ '2014-02-10T23:00:00Z,HI3821,2014-03-20T12:00:00Z,Spalling';
inputResponse = falkonry.add_verification('pipeline_id', 'json', {}, data)
import os, sys
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
stream = io.open('./data.json')
response = falkonry.add_verification_stream('pipeline_id', 'json', {}, stream)
import os, sys
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
stream = io.open('./data.csv')
response = falkonry.add_verification_stream('pipeline_id', 'json', {}, stream)
import os, sys
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
stream = open('/tmp/sample.json', 'r')
startTime = '1457018017' #seconds since unix epoch
endTime = '1457028017' #seconds since unix epoch
outputStream = falkonry.getOutput('pipeline_id', startTime, endTime)
with open('/tmp/pipelineOutput.json', 'w') as outputFile:
for line in outputStream:
outputFile.write(line + '\n')
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
subscription = Schemas.Subscription()
subscription.set_type('MQTT') \ #set Subscription type
.set_path('mqtt://test.mosquito.com') \ #set Mosquitto broker host url
.set_topic('falkonry-eb-1-test') \ #set topic for the Subscription
.set_username('test-user') \ #optional parameter
.set_password('test') \ #optional parameter
#create Subscription
subscription = falkonry.create_subscription('eventbuffer_id', subscription)
#delete Subscription
falkonry.delete_subscription('eventbuffer_id', subscription)
from falkonryclient import client as Falkonry
from falkonryclient import schemas as Schemas
#instantiate Falkonry
falkonry = Falkonry('https://service.falkonry.io', 'auth-token')
publication = Schemas.Publication() \
.set_type('WEBHOOK') \ #set Publication type
.set_path('https://test.example.com/getFalkonryData') \
.set_headers({ #set headers to send
'Authorization': 'Token 1234567890'
})
#create Publication
publication = falkonry.create_publication('pipeline_id', publication)
#delete Publication
falkonry.delete_publication('pipeline_id', publication)
To run the test suite, first install the dependencies, then run Test.sh
:
$ pip install -r requirements.txt
$ python test/*.py
Available under MIT License