|
|
@@ -1,44 +1,102 @@
|
|
|
+extern crate chrono;
|
|
|
extern crate xml;
|
|
|
|
|
|
+use chrono::DateTime;
|
|
|
+use chrono::TimeZone;
|
|
|
+use chrono::Utc;
|
|
|
use std::fs::File;
|
|
|
use std::io::BufReader;
|
|
|
+use std::time::Duration;
|
|
|
|
|
|
use xml::reader::{EventReader, XmlEvent};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+#[derive(Debug)]
|
|
|
struct Point {
|
|
|
lat: f64,
|
|
|
- long: f64,
|
|
|
- ele: f64
|
|
|
+ long: f64,
|
|
|
+ ele: f64,
|
|
|
+ time: chrono::DateTime<Utc>,
|
|
|
}
|
|
|
|
|
|
struct Tour {
|
|
|
- points: Vec<Point>
|
|
|
+ points: Vec<Point>,
|
|
|
}
|
|
|
|
|
|
+fn dist(p1: Point, p2: Point) -> f64 {
|
|
|
+ let r = 6371.0;
|
|
|
+ let d_lat = (p1.lat - p2.lat).to_radians();
|
|
|
+ let d_long = (p1.long - p2.long).to_radians();
|
|
|
|
|
|
-fn dist(p1: Point, p2: Point) -> f64{
|
|
|
- let R = 6371;
|
|
|
- let dLat: f64 = p1.lat - p2.lat;
|
|
|
- return 1.0
|
|
|
+ let a = (d_lat / 2.0).sin() * (d_lat / 2.0).sin()
|
|
|
+ + p1.lat.to_radians().cos()
|
|
|
+ * p2.lat.to_radians().cos()
|
|
|
+ * (d_long / 2.0).sin()
|
|
|
+ * (d_long / 2.0).sin();
|
|
|
+ let c = 2.0 * a.sqrt().atan2((1.0 - a).sqrt());
|
|
|
+ return r * c;
|
|
|
}
|
|
|
|
|
|
fn main() {
|
|
|
+ let mut tours: Vec<Tour>;
|
|
|
+
|
|
|
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,
|
|
|
+ ele: 0.0,
|
|
|
+ time: Utc.timestamp(1, 1),
|
|
|
+ };
|
|
|
+ let mut current_data = "".to_string();
|
|
|
+
|
|
|
for e in parser {
|
|
|
match e {
|
|
|
- Ok(XmlEvent::StartElement { name, attributes, namespace }) => {
|
|
|
- println!("{:?} {:?}", name, attributes);
|
|
|
+ Ok(XmlEvent::StartElement {
|
|
|
+ name,
|
|
|
+ attributes,
|
|
|
+ namespace,
|
|
|
+ }) => {
|
|
|
+ if name.local_name == "trkpt" {
|
|
|
+ // println!("ADDING POINT --- --- --- ---", )
|
|
|
+ } else {
|
|
|
+ println!(">>>{:?}", name.local_name);
|
|
|
+ }
|
|
|
+
|
|
|
+ for attr in attributes {
|
|
|
+ // println!("A\t{:?}={:?}", attr.name.local_name, attr.value);
|
|
|
+ if attr.name.local_name == "lat" {
|
|
|
+ current_point.lat = attr.value.parse().unwrap();
|
|
|
+ }
|
|
|
+ if attr.name.local_name == "lon" {
|
|
|
+ current_point.long = attr.value.parse().unwrap();
|
|
|
+ }
|
|
|
+ }
|
|
|
depth += 1;
|
|
|
}
|
|
|
Ok(XmlEvent::Characters(text)) => {
|
|
|
- println!("{:?}", text);
|
|
|
+ // println!("{:?}", text);
|
|
|
+ current_data = text;
|
|
|
+ }
|
|
|
+ Ok(XmlEvent::EndElement { name, .. }) => {
|
|
|
+ if name.local_name == "trkpt" {
|
|
|
+ println!("POINT DONE --- --- --- ---",);
|
|
|
+ println!("{:?}", current_point);
|
|
|
+ }
|
|
|
+
|
|
|
+ if name.local_name == "ele" {
|
|
|
+ current_point.ele = current_data.parse().unwrap();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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),
|
|
|
+ Err(err) => println!("=== TIME ERROR === {:?}", err),
|
|
|
+ // current_point.time = DateTime::parse_from_rfc3339("current_data").unwrap();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
Err(e) => {
|
|
|
println!("Error: {}", e);
|
|
|
@@ -46,6 +104,5 @@ fn main() {
|
|
|
}
|
|
|
_ => {}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-}
|
|
|
+}
|