#!/usr/bin/python

# Read the latest power readings as a JSON string compatible with the Google Visualization stuff
# http://code.google.com/apis/chart/interactive/docs/index.html

import gvizlib
import gviz_api

print "Content-type: application/json"
print

dataset = gvizlib.mysqlToJson('server', 'database', 'user', 'password',
                              'table')
dataset.col2typedict = {"MinMax": "string", "min": "number", "max": "number"}
dataset.dt = gviz_api.DataTable(dataset.col2typedict.items())

sql = """SELECT "MinMax",MIN(temperature) AS min, MAX(temperature) AS max FROM readings"""
dataset.populate_data(sql)
print dataset.print_JSON(cols=("MinMax", "min", "max"))
#!/usr/bin/python

# Read the latest power readings as a JSON string compatible with the Google Visualization stuff
# http://code.google.com/apis/chart/interactive/docs/index.html

import gvizlib

print "Content-type: application/json"
print

dataset = gvizlib.mysqlToJson('localhost', 'database', 'username', 'password',
                              'table')
dataset.make_data_table(columns=['time', 'temperature'])
column_names = ",".join(dataset.col2typedict.keys())
sql = "select time,CONVERT(avg(temperature),UNSIGNED) as temperature from readings where time > DATE_SUB(NOW(), INTERVAL 7 DAY) group by DATE(time),HOUR(time)"

dataset.populate_data(sql)

print dataset.print_JSON(cols=("time", "temperature"))
Example #3
0
#!/usr/bin/python

# Read the latest power readings as a JSON string compatible with the Google Visualization stuff
# http://code.google.com/apis/chart/interactive/docs/index.html

import gvizlib

print "Content-type: application/json"
print 

dataset = gvizlib.mysqlToJson('server','dbname','username','password','table')
dataset.make_data_table(columns=["watts"])
column_names = ",".join(dataset.col2typedict.keys())
sql = "SELECT "+column_names+" FROM "+dataset.table+" ORDER BY time DESC LIMIT 1"
dataset.populate_data(sql)

print dataset.print_JSON()


Example #4
0
#!/usr/bin/python

# Read the latest power readings as a JSON string compatible with the Google Visualization stuff
# http://code.google.com/apis/chart/interactive/docs/index.html

import gvizlib

print "Content-type: application/json"
print 

dataset = gvizlib.mysqlToJson('localhost','database','username','password','table')
dataset.make_data_table(columns=['time','temperature'])
column_names = ",".join(dataset.col2typedict.keys())
sql = "select time,CONVERT(avg(temperature),UNSIGNED) as temperature from readings where time > DATE_SUB(NOW(), INTERVAL 7 DAY) group by DATE(time),HOUR(time)"

dataset.populate_data(sql)

print dataset.print_JSON(cols=("time","temperature"))