|
|
@@ -1,6 +1,7 @@
|
|
|
extern crate chrono;
|
|
|
extern crate xml;
|
|
|
|
|
|
+
|
|
|
use chrono::DateTime;
|
|
|
use chrono::TimeZone;
|
|
|
use chrono::Utc;
|
|
|
@@ -10,7 +11,8 @@ use std::time::Duration;
|
|
|
|
|
|
use xml::reader::{EventReader, XmlEvent};
|
|
|
|
|
|
-#[derive(Debug)]
|
|
|
+
|
|
|
+#[derive(Debug, Clone)]
|
|
|
struct Point {
|
|
|
lat: f64,
|
|
|
long: f64,
|
|
|
@@ -18,10 +20,12 @@ struct Point {
|
|
|
time: chrono::DateTime<Utc>,
|
|
|
}
|
|
|
|
|
|
-struct Tour {
|
|
|
+struct Track {
|
|
|
points: Vec<Point>,
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
fn dist(p1: Point, p2: Point) -> f64 {
|
|
|
let r = 6371.0;
|
|
|
let d_lat = (p1.lat - p2.lat).to_radians();
|
|
|
@@ -37,13 +41,17 @@ fn dist(p1: Point, p2: Point) -> f64 {
|
|
|
}
|
|
|
|
|
|
fn main() {
|
|
|
- let mut tours: Vec<Tour>;
|
|
|
+ // let mut tracks: Vec<Track>;
|
|
|
+
|
|
|
+ let mut track: Track;
|
|
|
+ track.points = Vec::new();
|
|
|
+
|
|
|
+ let mut points: Vec<Point> = Vec::new();
|
|
|
|
|
|
let file = File::open("data/Day1-1.gpx").unwrap();
|
|
|
let file = BufReader::new(file);
|
|
|
|
|
|
let parser = EventReader::new(file);
|
|
|
- let mut depth = 0;
|
|
|
let mut current_point = Point {
|
|
|
lat: 0.0,
|
|
|
long: 0.0,
|
|
|
@@ -57,12 +65,12 @@ fn main() {
|
|
|
Ok(XmlEvent::StartElement {
|
|
|
name,
|
|
|
attributes,
|
|
|
- namespace,
|
|
|
+ ..
|
|
|
}) => {
|
|
|
if name.local_name == "trkpt" {
|
|
|
// println!("ADDING POINT --- --- --- ---", )
|
|
|
} else {
|
|
|
- println!(">>>{:?}", name.local_name);
|
|
|
+ // println!(">>>{:?}", name.local_name);
|
|
|
}
|
|
|
|
|
|
for attr in attributes {
|
|
|
@@ -74,16 +82,17 @@ fn main() {
|
|
|
current_point.long = attr.value.parse().unwrap();
|
|
|
}
|
|
|
}
|
|
|
- depth += 1;
|
|
|
}
|
|
|
Ok(XmlEvent::Characters(text)) => {
|
|
|
// println!("{:?}", text);
|
|
|
current_data = text;
|
|
|
}
|
|
|
Ok(XmlEvent::EndElement { name, .. }) => {
|
|
|
+
|
|
|
+ //Track point end event
|
|
|
if name.local_name == "trkpt" {
|
|
|
- println!("POINT DONE --- --- --- ---",);
|
|
|
- println!("{:?}", current_point);
|
|
|
+ // println!("POINT DONE --- --- --- ---",);
|
|
|
+ // println!("{:?}", current_point);
|
|
|
}
|
|
|
|
|
|
if name.local_name == "ele" {
|
|
|
@@ -91,12 +100,16 @@ fn main() {
|
|
|
}
|
|
|
|
|
|
if name.local_name == "time" {
|
|
|
- match Utc.datetime_from_str(current_data.as_str(), "%Y-%m-%dT%H:%M:%S.3f%z") {
|
|
|
- Ok(n) => println!("{:?}", n),
|
|
|
+ match Utc.datetime_from_str(current_data.as_str(), "%FT%H:%M:%S%.3fZ") {
|
|
|
+ Ok(time) => current_point.time = time,
|
|
|
Err(err) => println!("=== TIME ERROR === {:?}", err),
|
|
|
- // current_point.time = DateTime::parse_from_rfc3339("current_data").unwrap();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //push a copy of the point
|
|
|
+
|
|
|
+ points.push(current_point.clone());
|
|
|
+
|
|
|
}
|
|
|
Err(e) => {
|
|
|
println!("Error: {}", e);
|
|
|
@@ -105,4 +118,11 @@ fn main() {
|
|
|
_ => {}
|
|
|
}
|
|
|
}
|
|
|
+ //XML read in
|
|
|
+ // println!("{:?}", points);
|
|
|
+ track.points = points;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|