jeudi 15 janvier 2015

convert sqlite timestamp to javascript , gviz_api

I'm inserting data rows into sqlite database with UTC timestamp:



curs.execute("INSERT INTO data values (null, CURRENT_TIMESTAMP, (?), (?), (?), (?), (?), (?), (?), (?))", (temp,pinstatus,low_limit,high_limit,lightstatus,balstatus,vvstatus,svstatus))


sqlite schema is:



CREATE TABLE data (id integer primary key,timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, temp REAL, status INT, low_limit REAL, high_limit REAL, lightstatus INT, balstatus INT, vvstatus INT, svstatus INT);


example data (I live in GMT +2 zone)



sqlite> select * from data where ID = (select MAX(ID) from data);
26706|2015-01-15 17:58:44|21.875|0|20.0|22.0|1|1|1|1


How can I convert it into json when I use google gviz_api? Code below gives me "null" if I throw it into gviz_api



curs.execute("SELECT strftime('%m.%d.%Y %H:%M:%S', timestamp, 'localtime'),temp, low_limit, high_limit FROM data WHERE timestamp>datetime('now','-1 hours')")

schema = {"timestamp": ("date", "timestamp"),"temp": ("number", "temp"),"low_limit": ("number", "low_limit"),"high_limit": ("number", "high_limit")}
data = results
# Loading it into gviz_api.DataTable
data_table = gviz_api.DataTable(schema)
data_table.LoadData(data)
json = data_table.ToJSon()


Result that's passed to Javascript



{"c":[null]}


Hope anyone can help to clear that mess out with me.


Aucun commentaire:

Enregistrer un commentaire