My program reads distances and altitudes from all Garmin files (xml) present in the sketch folder. At the end of
setup()
i have two global ArrayLists. One is called altArrays and one is called distArrays. The are both structured the same, i.e. they are two-dimensional. So, for example, altArrays[0] contains an ArrayList of all of the altitudes for the first xml file in the sketch folder. altArrays[1] contains an ArrayList of all the altitudes for the second xml file, and so on. Here's the code that gets me there:
XMLElement xml;
float mapX1, mapX2, mapY1, mapY2;
float w_start, w_end, h_start, h_end;
int pad = 100; // sizes the window padding around the edgemost points
ArrayList altArrays = new ArrayList();
ArrayList distArrays = new ArrayList();
void setup() {
size(100, 100);
File dir = new File("/Users/leecarmichael/Documents/Processing/bikeViz_alt/data");
String[] files = dir.list();
println(files.length + " files present.");
for(int i=0; i<files.length; i++){
xml = new XMLElement(this, files[i]);
GarminXML data = new GarminXML(xml);
altArrays.add(data.getAltitudes());
}
for(int i=0; i<files.length; i++){
xml = new XMLElement(this,files[i]);
GarminXML data = new GarminXML(xml);
distArrays.add(data.getDistances());
}
}
void draw(){
My question is, now what? :)
My assumption is that if i'm going to use distance for the x-axis and altitude for the y-axis, I'm going to need all of these values to be integers (or double). What is the best way to get them there? My first thought was to simply index through the ArrayLists and somehow convert (perhaps via casting) the values to primitives. I can't seem to get that to work. Second approach was to just try some sort of conversion like:
String[] distances = new String[distArray.size()];
distArray.toArray(distances);
but it appears the two-dimensions are making this difficult. So I'm now out of ideas.
I'm having trouble understanding SimpleDateFormat. What i'm trying to do is read a date from an XML file then eventually use it as an X axis point on a graph. Obviously that means I need to get the time from a object that includes both time and date (for example, my data looks like this: 2011-05-07T14:12:25Z).
phi.lho advised using DateFormat which makes sense. However, I'm having trouble understanding the time zone part. For example, take the initial time data point from my file:
2011-05-07T12:06:19Z
The actual start time was 8:06 AM so clearly no time offset is provided by the device writing this file, thus GMT. So, how do I apply
my time zone to the data?
Here's a snippet of code. Up to this point all that's happened is I've created an ArrayList called allTimes that simply contains all of the time/date data from an XML file.
Object temp[] = allTimes.toArray(); //convert allTimes from type ArrayList to type Array (don't know why. just like arrays better.) String[] stringArray = Arrays.copyOf(temp, temp.length, String[].class); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); //create new date format //format.setTimeZone(TimeZone.getTimeZone("GMT"));
for(int i=0; i<stringArray.length; i++){ // See if we can parse try { Date current = format.parse(stringArray[i]); //println(i + ". " + stringArray[i]); //println(current); println(i+1 + ". " + current.toString()); } catch(ParseException pe) { println("ERROR: Cannot parse \"" + stringArray[i] + "\""); }
You can see my commented lines where I'm trying to see how different statements (setTimeZone, etc.) change the output. I just can't seem to get anything from it.
Aside from that, feel free to criticize my conversions from ArrayList to Array to a string to whatever else I've done. I don't totally understand all of the type stuff. All I know is that when it doesn't work and the error complains about type, I change the type.
I'm sure I'm just being dumb here but I can't seem to get XMLElement to do what I want it to (probably because I'm telling it wrong). In
this file, what I want to do is parse out all of the "TrackPoint" data that's buried way down in the structure. Just as a way to tip-toe into this (I'm new to Processing) I thought I'd just use the example on the XMLElement page and then try to slowly expand it until I got to where I wanted. It quickly came to a screeching halt.
First, I did this:
XMLElement xml;
void setup() { size(200, 200); xml = new XMLElement(this, "2010-01-07-22-52-57.xml"); XMLElement[] kids = xml.getChildren(); for (int i=0; i < kids.length; i++) { String site = kids[i].getName(); println(site); } }
void draw(){ }
It returned two children, Activities and Author, as expected. Next I thought I'd add a path to, say, Activities to see all of the children it had so I did this:
XMLElement xml;
void setup() { size(200, 200); xml = new XMLElement(this, "2010-01-07-22-52-57.xml"); XMLElement[] kids = xml.getChildren("Activities"); for (int i=0; i < kids.length; i++) { String site = kids[i].getName(); println(site); } }
void draw(){ }
However, all it returns is "Activities", not a list of of the children of Activities. So then I added another level to path: "Activities/Activity" and all it returns is "Activity". Any idea where what I'm doing wrong here? I'm expecting to see all of the children of a node but all I'm seeing is the parent node's name.