Created
March 21, 2010 10:28
-
-
Save psychemedia/339219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import simplejson | |
import csv | |
import os | |
f2=open(f2name,"wb+") | |
csv_file = csv.writer(f2) | |
csv_file.writerow([ "file",'timestamp','NGPSLatitude','NGPSLongitude', 'NGear','nEngine','rThrottlePedal','pBrakeF','gLat','gLong','sLap','vCar' ]) | |
##data is in files named numerically | |
for i in range(1268569874,1268574286): | |
f=PATH+`i` | |
if os.path.isfile(f): | |
f=open(f) | |
f.seek(0) | |
txt=f.read() | |
f.close() | |
## tidy the data so we just get a JSON blob | |
txt=txt.replace('Dashboard.jsonCallback(\'','') | |
txt=txt.replace('\\','') | |
txt=txt.replace('\');','') | |
##parse the json into a Python data structure | |
data=simplejson.loads(txt) | |
##parse the data at a more meanigful level and create a CSV output | |
if 'drivers' in data: | |
if 'HAM' in data['drivers']: | |
if 'telemetry' in data['drivers']['HAM']: | |
d=data['drivers']['HAM']['telemetry'] | |
csv_file.writerow([ i,d['timestamp'],d['NGPSLatitude'],d['NGPSLongitude'], d['NGear'],d['nEngine'],d['rThrottlePedal'],d['pBrakeF'],d['gLat'],d['gLong'],d['sLap'],d['vCar'] ]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment