/** Loads track segments of a GPX file, and returns them as a single line marker. */ public static List<Feature> loadData(PApplet p, String gpxFilename) { List<Feature> trackFeatures = new ArrayList<Feature>(); // Load GPX file XMLElement gpx = new XMLElement(p, gpxFilename); // Create track with all track points ShapeFeature trackFeature = new ShapeFeature(FeatureType.LINES); XMLElement[] itemXMLElements = gpx.getChildren("trk/trkseg/trkpt"); for (int i = 0; i < itemXMLElements.length; i++) { // Adds location for track point float lat = itemXMLElements[i].getFloat("lat"); float lon = itemXMLElements[i].getFloat("lon"); Location location = new Location(lat, lon); trackFeature.addLocation(location); } // Add time as property XMLElement timeXMLElement = gpx.getChild("trk/time"); trackFeature.addProperty("time", timeXMLElement.getContent()); trackFeatures.add(trackFeature); return trackFeatures; }
/** * Loads track segments of a GPX file, and returns them as a lines marker. Additionally, the speed * is calculated between two points, and stored as property. * * <p>This varies from {@link GPXReader#loadData(PApplet, String)}. */ public static List<Feature> loadData(PApplet p, String gpxFilename) { List<Feature> trackFeatures = new ArrayList<Feature>(); // Load GPX file XMLElement gpx = new XMLElement(p, gpxFilename); Calendar prevTime = null; Location prevLocation = null; // Create track with all track points ShapeFeature trackFeature = new ShapeFeature(FeatureType.LINES); List<Double> speedList = new ArrayList<Double>(); XMLElement[] itemXMLElements = gpx.getChildren("trk/trkseg/trkpt"); for (int i = 0; i < itemXMLElements.length; i++) { // Adds location for track point float lat = itemXMLElements[i].getFloat("lat"); float lon = itemXMLElements[i].getFloat("lon"); Location location = new Location(lat, lon); // Calculates speed for track point // Uses time span (h) and distance (km) to previous point to get km/h double speed = 0; try { String timeStr = itemXMLElements[i].getChild("time").getContent(); // Replace "Z" for Zulu/GMT time with parseable hour offset timeStr = timeStr.replaceAll("Z", "+0000"); Calendar time = StringUtils.parseIsoDateTime(timeStr); if (prevTime != null) { long timeMS = time.getTimeInMillis(); long timeDiff = timeMS - prevTime.getTimeInMillis(); double dist = GeoUtils.getDistance(location, prevLocation); speed = dist / ((float) timeDiff / 1000 / 60 / 60); } prevTime = time; prevLocation = location; } catch (ParseException e) { // println("Error:" + e); } speedList.add(speed); trackFeature.addLocation(location); } trackFeature.putProperty("speedList", speedList); trackFeatures.add(trackFeature); return trackFeatures; }
/* */ public XMLElement getChild(String path) /* */ { /* 563 */ if (path.indexOf('/') != -1) { /* 564 */ return getChildRecursive(PApplet.split(path, '/'), 0); /* */ } /* 566 */ int childCount = getChildCount(); /* 567 */ for (int i = 0; i < childCount; i++) { /* 568 */ XMLElement kid = getChild(i); /* 569 */ String kidName = kid.getName(); /* 570 */ if ((kidName != null) && (kidName.equals(path))) { /* 571 */ return kid; /* */ } /* */ } /* 574 */ return null; /* */ }
/* */ public boolean equals(Object object) /* */ { /* 1350 */ if (!(object instanceof XMLElement)) { /* 1351 */ return false; /* */ } /* 1353 */ XMLElement rawElement = (XMLElement)object; /* */ /* 1355 */ if (!this.name.equals(rawElement.getLocalName())) { /* 1356 */ return false; /* */ } /* 1358 */ if (this.attributes.size() != rawElement.getAttributeCount()) { /* 1359 */ return false; /* */ } /* 1361 */ Enumeration<XMLAttribute> en = this.attributes.elements(); /* 1362 */ while (en.hasMoreElements()) { /* 1363 */ XMLAttribute attr = (XMLAttribute)en.nextElement(); /* */ /* 1365 */ if (!rawElement.hasAttribute(attr.getName())) { /* 1366 */ return false; /* */ } /* */ /* */ /* */ /* 1371 */ String value = rawElement.getString(attr.getName(), null); /* 1372 */ if (!attr.getValue().equals(value)) { /* 1373 */ return false; /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* 1381 */ if (this.children.size() != rawElement.getChildCount()) { /* 1382 */ return false; /* */ } /* 1384 */ for (int i = 0; i < this.children.size(); i++) { /* 1385 */ XMLElement child1 = getChild(i); /* 1386 */ XMLElement child2 = rawElement.getChild(i); /* */ /* 1388 */ if (!child1.equals(child2)) { /* 1389 */ return false; /* */ } /* */ } /* 1392 */ return true; /* */ }
/* */ public XMLElement[] getChildren(String path) /* */ { /* 641 */ if (path.indexOf('/') != -1) { /* 642 */ return getChildrenRecursive(PApplet.split(path, '/'), 0); /* */ } /* */ /* */ /* 646 */ if (Character.isDigit(path.charAt(0))) { /* 647 */ return new XMLElement[] { getChild(Integer.parseInt(path)) }; /* */ } /* 649 */ int childCount = getChildCount(); /* 650 */ XMLElement[] matches = new XMLElement[childCount]; /* 651 */ int matchCount = 0; /* 652 */ for (int i = 0; i < childCount; i++) { /* 653 */ XMLElement kid = getChild(i); /* 654 */ String kidName = kid.getName(); /* 655 */ if ((kidName != null) && (kidName.equals(path))) { /* 656 */ matches[(matchCount++)] = kid; /* */ } /* */ } /* 659 */ return (XMLElement[])PApplet.subset(matches, 0, matchCount); /* */ }
/* */ protected XMLElement getChildRecursive(String[] items, int offset) /* */ { /* 587 */ if (Character.isDigit(items[offset].charAt(0))) { /* 588 */ XMLElement kid = getChild(Integer.parseInt(items[offset])); /* 589 */ if (offset == items.length - 1) { /* 590 */ return kid; /* */ } /* 592 */ return kid.getChildRecursive(items, offset + 1); /* */ } /* */ /* 595 */ int childCount = getChildCount(); /* 596 */ for (int i = 0; i < childCount; i++) { /* 597 */ XMLElement kid = getChild(i); /* 598 */ String kidName = kid.getName(); /* 599 */ if ((kidName != null) && (kidName.equals(items[offset]))) { /* 600 */ if (offset == items.length - 1) { /* 601 */ return kid; /* */ } /* 603 */ return kid.getChildRecursive(items, offset + 1); /* */ } /* */ } /* */ /* 607 */ return null; /* */ }
/* */ public void insertChild(XMLElement child, int index) /* */ { /* 422 */ if (child == null) { /* 423 */ throw new IllegalArgumentException("child must not be null"); /* */ } /* 425 */ if ((child.getLocalName() == null) && (!this.children.isEmpty())) { /* 426 */ XMLElement lastChild = (XMLElement)this.children.lastElement(); /* 427 */ if (lastChild.getLocalName() == null) { /* 428 */ lastChild.setContent(lastChild.getContent() + /* 429 */ child.getContent()); /* 430 */ return; /* */ } /* */ } /* 433 */ child.parent = this; /* 434 */ this.children.insertElementAt(child, index); /* */ }
/* */ public void addChild(XMLElement child) /* */ { /* 398 */ if (child == null) { /* 399 */ throw new IllegalArgumentException("child must not be null"); /* */ } /* 401 */ if ((child.getLocalName() == null) && (!this.children.isEmpty())) { /* 402 */ XMLElement lastChild = (XMLElement)this.children.lastElement(); /* */ /* 404 */ if (lastChild.getLocalName() == null) { /* 405 */ lastChild.setContent(lastChild.getContent() + /* 406 */ child.getContent()); /* 407 */ return; /* */ } /* */ } /* 410 */ child.parent = this; /* 411 */ this.children.addElement(child); /* */ }
public void initXMLObject() { numProfiles = xmlFeed.getChildCount(); println("NUM PROFILES: " + numProfiles); for (int i = 0; i < numProfiles; i++) { XMLElement profile = xmlFeed.getChild(i); /// * try { headerList.add(profile.getChild(0).getContent()); nameList.add(profile.getChild(1).getContent()); blurbList.add(profile.getChild(2).getContent()); // videoPathList.add(profile.getChild(3).getContent()); thePopUp.videoPath.add(profile.getChild(3).getContent()); latList.add(profile.getChild(4).getContent()); longList.add(profile.getChild(5).getContent()); pApp.println("Title= " + profile.getChild(0).getContent()); pApp.println("Name= " + profile.getChild(1).getContent()); pApp.println("Blurb= " + profile.getChild(2).getContent()); // pApp.println("video = " + profile.getChild(3).getContent()); pApp.println("Address = " + profile.getChild(4).getContent()); // pApp.println("long = " + profile.getChild(5).getContent()); // pApp.println(" "); pApp.println(" "); } catch (Exception e) { println("XML init error: " + e); } } /// now that the popup video array has data, init the video thePopUp.initVideo(); /// convert the lat and long string to floats initLocations(); }
private void readDomain(String element, XMLElement datadict) { for (int df = 0; df < datadict.getChildCount(); df++) { if (datadict.getChild(df).getStringAttribute("name").equals(element)) { // add the prob for each node String[] probs = {}; for (int val = 0; val < datadict.getChild(df).getChildCount(); val++) { if (datadict.getChild(df).getChild(val).getName().equals("Extension")) { XMLElement ext = datadict.getChild(df).getChild(val); for (int x = 0; x < ext.getChildCount(); x++) { if (ext.getChild(x).getName().equals("X-Definition")) { probs = ext.getChild(x).getChild(0).getContent().split(" "); break; } } break; } } // create a node for each value int valIdx = 0; for (int val = 0; val < datadict.getChild(df).getChildCount(); val++) { if (datadict.getChild(df).getChild(val).getName().equals("Value")) { float prob = Float.valueOf(probs[valIdx++]); // // this.addNode(datadict.getChild(df).getChild(val).getStringAttribute("value")).setProb(prob); if (!this.domains.containsKey(element)) this.domains.put(element, new ArrayList<String>()); if (!this.probabilities.containsKey(element)) this.probabilities.put(element, new HashMap<String, Float>()); this.domains .get(element) .add(datadict.getChild(df).getChild(val).getStringAttribute("value")); this.probabilities .get(element) .put(datadict.getChild(df).getChild(val).getStringAttribute("value"), prob); } } break; } } }
public void loadData() { XMLElement xml = new XMLElement(this, filename); // pmml for (int i = 0; i < xml.getChildCount(); i++) { if (!xml.getChild(i).getName().equals("DataDictionary")) { continue; } XMLElement datadict = xml.getChild(i); // read node domains from PMML readDomain(actionT, datadict); readDomain(objActedOn, datadict); readDomain(toLocation, datadict); readDomain(errorT, datadict); readDomain(groupT, datadict); readDomain(fromLocation, datadict); // TODO: create separate graphs for each activity /////////////////////////////////////// // read edges // find precedes predicate for (int df = 0; df < datadict.getChildCount(); df++) { if (datadict.getChild(df).getStringAttribute("name").equals(precedes)) { // find Extension module for (int val = 0; val < datadict.getChild(df).getChildCount(); val++) { if (datadict.getChild(df).getChild(val).getName().equals("Extension")) { XMLElement ext = datadict.getChild(df).getChild(val); // find the X-Table inside the X-Definition for (int x = 0; x < ext.getChildCount(); x++) { if (ext.getChild(x).getName().equals("X-Definition")) { for (int xx = 0; xx < ext.getChild(x).getChildCount(); xx++) { if (!ext.getChild(x).getChild(xx).getName().equals("X-Table")) { continue; } // read all the cond. probabilities String[] cpt = ext.getChild(x).getChild(xx).getContent().split(" "); // iterate across the table of conditional probabilities and link the nodes // accordingly // healthinf-trials // <X-Given>0</X-Given> <!-- objActedOn(a1) --> // <X-Given>1</X-Given> <!-- errorT(e) --> // <X-Given>2</X-Given> <!-- groupT(g) --> // <X-Given>3</X-Given> <!-- toLocation(a1) --> // <X-Given>4</X-Given> <!-- actionT(a1) --> // <X-Given>6</X-Given> <!-- #actionT(a2) --> // <X-Given>7</X-Given> <!-- #objActedOn(a2) --> // <X-Given>8</X-Given> <!-- #toLocation(a2) --> // <X-Given>9</X-Given> <!-- !(a1=a2) --> // int blocksize_obj1 = domains.get(errorT).size() * // domains.get(groupT).size() * domains.get(toLocation).size() * // domains.get(actionT).size() * domains.get(actionT).size() * // domains.get(objActedOn).size() * domains.get(toLocation).size(); // int blocksize_error = domains.get(groupT).size() * // domains.get(toLocation).size() * domains.get(actionT).size() * // domains.get(actionT).size() * domains.get(objActedOn).size() * // domains.get(toLocation).size(); // int blocksize_group = domains.get(toLocation).size() * // domains.get(actionT).size() * domains.get(actionT).size() * // domains.get(objActedOn).size() * domains.get(toLocation).size(); // int blocksize_toLoc1 = domains.get(actionT).size() * // domains.get(actionT).size() * domains.get(objActedOn).size() * // domains.get(toLocation).size(); // int blocksize_action1 = domains.get(actionT).size() * // domains.get(objActedOn).size() * domains.get(toLocation).size(); // int blocksize_action2 = domains.get(objActedOn).size() * // domains.get(toLocation).size(); // int blocksize_obj2 = domains.get(toLocation).size(); // int blocksize_toLoc2 = 1; // healthinf-finals (incl. fromlocation) // <X-Given>0</X-Given> <!-- objActedOn(a1) --> // <X-Given>1</X-Given> <!-- errorT(e) --> // <X-Given>2</X-Given> <!-- groupT(g) --> // <X-Given>3</X-Given> <!-- fromLocation(a1) --> // <X-Given>4</X-Given> <!-- toLocation(a1) --> // <X-Given>5</X-Given> <!-- actionT(a1) --> // <X-Given>7</X-Given> <!-- #actionT(a2) --> // <X-Given>8</X-Given> <!-- #objActedOn(a2) --> // <X-Given>9</X-Given> <!-- #toLocation(a2) --> // <X-Given>10</X-Given> <!-- #fromLocation(a2) --> // <X-Given>11</X-Given> <!-- !(a1=a2) --> int blocksize_obj1 = domains.get(errorT).size() * domains.get(groupT).size() * domains.get(fromLocation).size() * domains.get(toLocation).size() * domains.get(actionT).size() * domains.get(actionT).size() * domains.get(objActedOn).size() * domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_error = domains.get(groupT).size() * domains.get(fromLocation).size() * domains.get(toLocation).size() * domains.get(actionT).size() * domains.get(actionT).size() * domains.get(objActedOn).size() * domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_group = domains.get(fromLocation).size() * domains.get(toLocation).size() * domains.get(actionT).size() * domains.get(actionT).size() * domains.get(objActedOn).size() * domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_fromLoc1 = domains.get(toLocation).size() * domains.get(actionT).size() * domains.get(actionT).size() * domains.get(objActedOn).size() * domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_toLoc1 = domains.get(actionT).size() * domains.get(actionT).size() * domains.get(objActedOn).size() * domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_action1 = domains.get(actionT).size() * domains.get(objActedOn).size() * domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_action2 = domains.get(objActedOn).size() * domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_obj2 = domains.get(toLocation).size() * domains.get(fromLocation).size(); int blocksize_toLoc2 = domains.get(fromLocation).size(); int blocksize_fromLoc2 = 1; System.err.println("CPT size: " + cpt.length); System.err.println( "Domain sizes: " + domains.get(objActedOn).size() * domains.get(errorT).size() * domains.get(groupT).size() * domains.get(fromLocation).size() * domains.get(toLocation).size() * domains.get(actionT).size() * domains.get(actionT).size() * domains.get(objActedOn).size() * domains.get(fromLocation).size() * domains.get(toLocation).size()); for (int obj1 = 0; obj1 < domains.get(objActedOn).size(); obj1++) { // #elem 10 for (int error = 0; error < domains.get(errorT).size(); error++) { // #elem 1 for (int group = 0; group < domains.get(groupT).size(); group++) { // #elem 1 for (int fromLoc1 = 0; fromLoc1 < domains.get(fromLocation).size(); fromLoc1++) { for (int toLoc1 = 0; toLoc1 < domains.get(toLocation).size(); toLoc1++) { // #elem 5 for (int action1 = 0; action1 < domains.get(actionT).size(); action1++) { // #elem 3 for (int action2 = 0; action2 < domains.get(actionT).size(); action2++) { // #elem 3 for (int obj2 = 0; obj2 < domains.get(objActedOn).size(); obj2++) { // #elem 10 for (int fromLoc2 = 0; fromLoc2 < domains.get(fromLocation).size(); fromLoc2++) { // #elem 5 for (int toLoc2 = 0; toLoc2 < domains.get(toLocation).size(); toLoc2++) { // #elem 5 // total: 1 166 400 blocks in the CPT, each block four // numbers ((a1=a2) plus true/false) // TODO: modify this loop to take the different parents into // account // -> also read labels for parents and add separate // nodes for each combination float condA1A2 = Float.valueOf( cpt[ 4 * (obj1 * blocksize_obj1 + error * blocksize_error + group * blocksize_group + fromLoc1 * blocksize_fromLoc1 + toLoc1 * blocksize_toLoc1 + action1 * blocksize_action1 + action2 * blocksize_action2 + obj2 * blocksize_obj2 + fromLoc2 * blocksize_fromLoc2 + toLoc2 * blocksize_toLoc2)]); if (condA1A2 > 0.0) { // search for nodes, create if don't exist yet Node from = null; // use toLocation only if not empty if (!domains.get(toLocation).get(toLoc1).equals("No_from") && !domains .get(toLocation) .get(toLoc1) .equals("No_to")) { from = this.findNode( domains.get(actionT).get(action1) + " " + domains.get(objActedOn).get(obj1) + " to " + domains.get(toLocation).get(toLoc1)); from.prob = probabilities .get(actionT) .get(domains.get(actionT).get(action1)) * probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj1)) * probabilities .get(toLocation) .get(domains.get(toLocation).get(toLoc1)); if (from.prob > 0.000002) { System.err.println( from.getName() + ": " + probabilities .get(actionT) .get(domains.get(actionT).get(action1)) + " * " + probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj1)) + " * " + probabilities .get(toLocation) .get( domains.get(toLocation).get(toLoc1))); } } else if (!domains .get(fromLocation) .get(fromLoc1) .equals("No_from") && !domains .get(fromLocation) .get(fromLoc1) .equals("No_to")) { from = this.findNode( domains.get(actionT).get(action1) + " " + domains.get(objActedOn).get(obj1) + " from " + domains.get(fromLocation).get(fromLoc1)); from.prob = probabilities .get(actionT) .get(domains.get(actionT).get(action1)) * probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj1)) * probabilities .get(fromLocation) .get( domains .get(fromLocation) .get(fromLoc1)); if (from.prob > 0.000002) { System.err.println( from.getName() + ": " + probabilities .get(actionT) .get(domains.get(actionT).get(action1)) + " * " + probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj1)) + " * " + probabilities .get(fromLocation) .get( domains .get(fromLocation) .get(fromLoc1))); } } if (from != null) System.err.println(from.getName() + ": " + from.prob); Node to = null; if (!domains.get(toLocation).get(toLoc2).equals("No_from") && !domains .get(toLocation) .get(toLoc2) .equals("No_to")) { to = this.findNode( domains.get(actionT).get(action2) + " " + domains.get(objActedOn).get(obj2) + " to " + domains.get(toLocation).get(toLoc2)); to.prob = probabilities .get(actionT) .get(domains.get(actionT).get(action2)) * probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj2)) * probabilities .get(toLocation) .get(domains.get(toLocation).get(toLoc2)); if (to.prob > 0.000002) { System.err.println( to.getName() + ": " + probabilities .get(actionT) .get(domains.get(actionT).get(action2)) + " * " + probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj2)) + " * " + probabilities .get(toLocation) .get( domains.get(toLocation).get(toLoc2))); } } else if (!domains .get(fromLocation) .get(fromLoc2) .equals("No_from") && !domains .get(fromLocation) .get(fromLoc2) .equals("No_to")) { to = this.findNode( domains.get(actionT).get(action2) + " " + domains.get(objActedOn).get(obj2) + " from " + domains.get(fromLocation).get(fromLoc2)); to.prob = probabilities .get(actionT) .get(domains.get(actionT).get(action2)) * probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj2)) * probabilities .get(fromLocation) .get( domains .get(fromLocation) .get(fromLoc2)); if (to.prob > 0.000002) { System.err.println( to.getName() + ": " + probabilities .get(actionT) .get(domains.get(actionT).get(action2)) + " * " + probabilities .get(objActedOn) .get(domains.get(objActedOn).get(obj2)) + " * " + probabilities .get(fromLocation) .get( domains .get(fromLocation) .get(fromLoc2))); } } if (to != null) { System.err.println(to.getName() + ": " + to.prob); // System.err.println(to.getName() // + ": " // probabilities.get(domains.get(actionT).get(action2))); } if (from != null && to != null) this.addEdge(from.label, to.label, condA1A2); } } } } } } } } } } } break; } } } break; } } break; } } } }
/* The format of the grid parameters is the following: * <grid> * <resolution nx=10 ny=10></resolution> * <point> * <coord x="0.5" y="+0.5"></coord> * <texcoord s="0.0" t="1.0"></texcoord> * </point> * <point> * <coord x="x" y="y"></coord> * <texcoord s="s" t="t"></texcoord> * </point> * </grid> */ protected void initGrid(XMLElement xml) { int n = xml.getChildCount(); // if there is only one parameter line, it should contain the // grid dimensions. if (n == 1) { numLayers = 1; } else { numLayers = n - 1; } points = new GLTexturedPoint[numLayers]; XMLElement child; String name, wStr, hStr, modeName; int ptLayer = 0; for (int i = 0; i < n; i++) { child = xml.getChild(i); name = child.getName(); if (name.equals("resolution")) { wStr = child.getStringAttribute("nx"); hStr = child.getStringAttribute("ny"); usingSrcTexRes = false; if (wStr.equals("w")) resX = 0; else if (wStr.equals("w0")) resX = -1; else if (wStr.equals("w1")) resX = -2; else if (wStr.equals("w2")) resX = -3; else if (wStr.equals("w3")) resX = -4; else if (wStr.equals("w4")) resX = -5; else if (wStr.equals("w5")) resX = -6; else resX = child.getIntAttribute("nx"); if (hStr.equals("h")) resY = 0; else if (hStr.equals("h0")) resY = -1; else if (hStr.equals("h1")) resY = -2; else if (hStr.equals("h2")) resY = -3; else if (hStr.equals("h3")) resY = -4; else if (hStr.equals("h4")) resY = -5; else if (hStr.equals("h5")) resY = -6; else resY = child.getIntAttribute("ny"); if ((resX <= 0) || (resY <= 0)) if (resX != resY) System.err.println("Source width and height are different!"); else if (resX < 0) { usingSrcTexRes = true; srcTexIdx = -(resX + 1); } modeName = child.getStringAttribute("mode"); mode = GLUtils.parsePrimitiveType(modeName); } else if (name.equals("point")) { points[ptLayer] = new GLTexturedPoint(child); ptLayer++; } } if (n == 1) { points[0] = new GLTexturedPoint(); points[0].setAsUndefined(); } }