Created
September 27, 2010 08:39
-
-
Save sbuys/598766 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
HashMap runElements = new HashMap(); | |
XMLElement xml; | |
int id; | |
String workoutType, startTime, date, time, distance, duration, heartrateAvgString, heartrateMinString, heartrateMaxString; | |
float k_to_m_conversion=1/1.609344; | |
float distance_k, distance_m; | |
float durationFloat; | |
int durationM, durationS; | |
int heartCount; | |
String feed = "http://nikerunning.nike.com/nikeplus/v2/services/app/run_list.jsp?userID=414556331&startIndex=1&endIndex=30&filterBy=all"; | |
PFont font; | |
void setup() { | |
size(800,600); | |
background(255); | |
runElements.put("startTime", 0); | |
runElements.put("distance", 1); | |
runElements.put("duration", 2); | |
runElements.put("syncTime", 3); | |
runElements.put("calories", 4); | |
runElements.put("name", 5); | |
runElements.put("description", 6); | |
runElements.put("howFelt", 7); | |
runElements.put("weather", 8); | |
runElements.put("terrain", 9); | |
runElements.put("intensity", 10); | |
runElements.put("gpxId", 11); | |
runElements.put("equipmentType", 12); | |
runElements.put("heartrate", 13); | |
parseXML(feed); | |
font = loadFont("Monaco-16.vlw"); | |
textFont(font, 16); | |
} | |
void parseXML(String _doc){ | |
String doc = _doc; | |
xml = new XMLElement(this, doc); | |
XMLElement runList = xml.getChild(1); | |
int runCount = runList.getChildCount(); | |
XMLElement firstRun = runList.getChild(28); | |
int elementCount = firstRun.getChildCount(); | |
id = firstRun.getIntAttribute("id"); | |
workoutType = firstRun.getStringAttribute("workoutType"); | |
println("id:" + "\t" + id); | |
println("workoutType:" + "\t" + workoutType); | |
//START TIME | |
int index = (Integer)runElements.get("startTime"); | |
XMLElement _startTime = firstRun.getChild(index); | |
//XMLElement _startTime = firstRun.getChild(0); | |
startTime = _startTime.getContent(); | |
String[] splitTime = split(startTime,"T"); | |
date = splitTime[0]; | |
time = splitTime[1]; | |
//DISTANCE | |
index = (Integer)runElements.get("distance"); | |
XMLElement _distance = firstRun.getChild(index); | |
String distance = _distance.getContent(); | |
distance_k = Float.parseFloat(distance); | |
distance_m = distance_k*k_to_m_conversion; | |
//DURATION | |
index = (Integer)runElements.get("duration"); | |
XMLElement _duration = firstRun.getChild(index); | |
String duration = _duration.getContent(); | |
durationFloat = Float.parseFloat(duration); | |
durationM = floor(durationFloat/1000/60); | |
durationS = round((durationFloat/1000/60-durationM)*60); | |
//HEARTRATE | |
index = (Integer)runElements.get("heartrate"); | |
if(elementCount>=index){ | |
XMLElement _heartrate = firstRun.getChild(index); | |
heartCount = _heartrate.getChildCount(); | |
//println(heartCount); | |
XMLElement _heartrateAvg = _heartrate.getChild(0); | |
XMLElement _heartrateMin = _heartrate.getChild(1); | |
XMLElement _heartrateMax = _heartrate.getChild(2); | |
heartrateAvgString = _heartrateAvg.getContent(); | |
heartrateMinString = _heartrateMin.getContent(); | |
heartrateMaxString = _heartrateMax.getContent(); | |
} | |
} | |
void draw() { | |
background(255); | |
fill(100); | |
textAlign(RIGHT); | |
text("ID:", 140, 20); | |
text("WORKOUT TYPE:", 140, 45); | |
text("DATE:", 140, 70); | |
text("START TIME:", 140, 95); | |
text("DURATION:", 140, 120); | |
text("DISTANCE:", 140, 145); | |
text("HEARTRATE:", 140, 170); | |
fill(140); | |
textAlign(LEFT); | |
text(id, 150, 20); | |
text(workoutType, 150, 45); | |
text(date, 150, 70); | |
text(time, 150, 95); | |
text(durationM+" min " + durationS+ " sec ", 150, 120); | |
text(nfc(distance_m,2)+" MI", 150, 145); | |
text(heartrateAvgString+" (avg), " + heartrateMinString + " (min), " + heartrateMaxString + " (max)", 150, 170); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment