Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Performing statistical data analysis on real-world data using the power of Python and Pandas on WoTKit sensor data.
#!/bin/python
import httplib, urllib, base64, json
import pandas as pd
#TODO: ADD YOUR SENSOR NAME AND CREDENTIALS
SENSOR_NAME = 'mike.yvr-arrive'
USERNAME = 'YOURWOTKITUSERNAME'
PASSWORD = 'YOUROWOTKITPASSWORD'
HOST = 'wotkit.sensetecnic.com'
auth = base64.encodestring('%s:%s' % (USERNAME, PASSWORD)).replace('\n', '')
headers = {"Authorization": "Basic %s" % auth}
def getWoTKitSensorData():
try:
# get 1000 datapoints
# http://wotkit.readthedocs.org/en/latest/api_v1/api_sensor_data.html#raw-data-retrieval
URL = "/api/v1/sensors/%s/data?beforeE=1000" % SENSOR_NAME
conn = httplib.HTTPConnection(HOST);
conn.request("GET", URL, headers=headers)
data = json.loads(conn.getresponse().read())
conn.close()
return data
except:
return None
def WotKitDataToSeries(data):
result = pd.Series()
for i,element in enumerate(data):
if "value" in element:
timestamp = pd.to_datetime(element["timestamp_iso"])
value = element["value"]
result.set_value(timestamp, value)
return result
if __name__ == "__main__":
pddata = WotKitDataToSeries( getWoTKitSensorData() )
print "Median of arrivals: %f" % pddata.median()
print "Max arrivals: %f" % pddata.max()
print "Variance in arrivals: %f" % pddata.var()
print "Skewness arrivals: %f and kurtosis: %f" % (pddata.skew(), pddata.kurtosis())
print pddata.describe()
#Bonus: Correlation with itself, or data from another sensor:
print "Correlation with itself: %f" % (pddata.corr(pddata))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.