Пример #1
0
        public void Before()
        {
            String trackJSON = ""
                + "{"
                +   "\"track\": {"
                +     "\"id\": \"1000\","
                +     "\"name\": \"Test Raceway\","
                +     "\"gates\": ["
                +       "{"
                +       "\"gate_type\": \"SPLIT\","
                +       "\"latitude\": \"37.451775\","
                +       "\"longitude\": \"-122.203657\","
                +       "\"bearing\": \"136\","
                +       "\"split_number\": \"1\""
                +       "},"
                +       "{"
                +       "\"gate_type\": \"SPLIT\","
                +       "\"latitude\": \"37.450127\","
                +       "\"longitude\": \"-122.205499\","
                +       "\"bearing\": \"326\","
                +       "\"split_number\": \"2\""
                +       "},"
                +       "{"
                +       "\"gate_type\": \"START_FINISH\","
                +       "\"latitude\": \"37.452602\","
                +       "\"longitude\": \"-122.207069\","
                +       "\"bearing\": \"32\","
                +       "\"split_number\": \"3\""
                +       "}"
                +     "]"
                +   "}"
                + "}";

            track = Track.Load(trackJSON)[0];
        }
        public MainViewController(IntPtr handle)
            : base(handle)
        {
            String trackJSON = ""
                + "{"
                +   "\"track\": {"
                +     "\"id\": \"1000\","
                +     "\"name\": \"Test Raceway\","
                +     "\"gates\": ["
                +       "{"
                +       "\"gate_type\": \"SPLIT\","
                +       "\"latitude\": \"37.451775\","
                +       "\"longitude\": \"-122.203657\","
                +       "\"bearing\": \"136\","
                +       "\"split_number\": \"1\""
                +       "},"
                +       "{"
                +       "\"gate_type\": \"SPLIT\","
                +       "\"latitude\": \"37.450127\","
                +       "\"longitude\": \"-122.205499\","
                +       "\"bearing\": \"326\","
                +       "\"split_number\": \"2\""
                +       "},"
                +       "{"
                +       "\"gate_type\": \"START_FINISH\","
                +       "\"latitude\": \"37.452602\","
                +       "\"longitude\": \"-122.207069\","
                +       "\"bearing\": \"32\","
                +       "\"split_number\": \"3\""
                +       "}"
                +     "]"
                +   "}"
                + "}";

            track = Track.Load(trackJSON)[0];

            string contents = System.IO.File.ReadAllText("Assets/multi_lap_session.csv");
            string[] lines = contents.Split('\n');
            points = new List<Point>();
            foreach(string line in lines) {
                string[] parts = line.Split(',');
                points.Add(new Point(
                    latitude: Double.Parse(parts[0]),
                    longitude: Double.Parse(parts[1]),
                    speed: Double.Parse(parts[2]),
                    bearing: Double.Parse(parts[3]),
                    horizontalAccuracy: 5.0,
                    verticalAccuracy: 15.0,
                    timestamp: 0));
            }
        }
Пример #3
0
        public Lap(Session session, Track track, double startTime, int lapNumber)
        {
            this.session = session;
            this.track = track;
            this.startTime = startTime;
            this.lapNumber = lapNumber;
            this.points = new List<Point>();
            this.duration = 0;
            this.distance = 0;
            this.valid = false;
            this.splits = new double[track.NumSplits()];
            this.outLap = lapNumber == 0;

            if (outLap) { nextGate = track.start; }
        }
Пример #4
0
 public static Track[] Load(String json)
 {
     try {
         if (json.StartsWith("[")) {
             var jsonArray = Newtonsoft.Json.Linq.JArray.Parse(json);
             var array = new Track[jsonArray.Count];
             for (int i = 0; i < jsonArray.Count; i++) {
                 array[i] = new Track(jsonArray[i]["track"]);
             }
             return array;
         } else {
             return new Track[] { new Track(Newtonsoft.Json.Linq.JObject.Parse(json)["track"]) };
         }
     } catch (System.ArgumentNullException e) {
         Console.WriteLine("Track load error: " + e);
     }
     return null;
 }
Пример #5
0
 public Session(Track track, double startTime)
 {
     this.track     = track;
     this.startTime = startTime;
 }
Пример #6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            String trackJSON = ""
                + "{"
                +   "\"track\": {"
                +     "\"id\": \"1000\","
                +     "\"name\": \"Test Raceway\","
                +     "\"gates\": ["
                +       "{"
                +       "\"gate_type\": \"SPLIT\","
                +       "\"latitude\": \"37.451775\","
                +       "\"longitude\": \"-122.203657\","
                +       "\"bearing\": \"136\","
                +       "\"split_number\": \"1\""
                +       "},"
                +       "{"
                +       "\"gate_type\": \"SPLIT\","
                +       "\"latitude\": \"37.450127\","
                +       "\"longitude\": \"-122.205499\","
                +       "\"bearing\": \"326\","
                +       "\"split_number\": \"2\""
                +       "},"
                +       "{"
                +       "\"gate_type\": \"START_FINISH\","
                +       "\"latitude\": \"37.452602\","
                +       "\"longitude\": \"-122.207069\","
                +       "\"bearing\": \"32\","
                +       "\"split_number\": \"3\""
                +       "}"
                +     "]"
                +   "}"
                + "}";

            track = Track.Load(trackJSON)[0];

            string contents;
            using (var sr = new StreamReader(Assets.Open("multi_lap_session.csv")))	{
                contents = sr.ReadToEnd();
            }
            string[] lines = contents.Split('\n');
            points = new List<Point>();
            foreach(string line in lines) {
                string[] parts = line.Split(',');
                points.Add(new Point(
                    latitude: Double.Parse(parts[0]),
                    longitude: Double.Parse(parts[1]),
                    speed: Double.Parse(parts[2]),
                    bearing: Double.Parse(parts[3]),
                    horizontalAccuracy: 5.0,
                    verticalAccuracy: 15.0,
                    timestamp: 0));
            }

            SetContentView(Resource.Layout.Main);
            button1000 = FindViewById<Button>(Resource.Id.button1000);
            button10000 = FindViewById<Button>(Resource.Id.button10000);
            label1000 = FindViewById<TextView>(Resource.Id.label1000);
            label10000 = FindViewById<TextView>(Resource.Id.label10000);

            button1000.Click += delegate {
            double timestamp = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            for (int i = 0; i < 1000; i++) {
              SessionManager.Instance().Start(track);
              foreach(Point point in points) {
            SessionManager.Instance().GPS(point.LatitudeDegrees(),
              longitude: point.LongitudeDegrees(),
              speed: point.speed,
              bearing: point.bearing,
              horizontalAccuracy: point.hAccuracy,
              verticalAccuracy: point.vAccuracy,
              timestamp: timestamp);
            timestamp++;
              }
              SessionManager.Instance().End();
            }
            stopWatch.Stop();
            label1000.Text = String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds);
            };

              button10000.Click += delegate {
            double timestamp = (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            for (int i = 0; i < 10000; i++) {
              SessionManager.Instance().Start(track);
              foreach(Point point in points) {
            SessionManager.Instance().GPS(point.LatitudeDegrees(),
              longitude: point.LongitudeDegrees(),
              speed: point.speed,
              bearing: point.bearing,
              horizontalAccuracy: point.hAccuracy,
              verticalAccuracy: point.vAccuracy,
              timestamp: timestamp);
            timestamp++;
              }
              SessionManager.Instance().End();
            }
            stopWatch.Stop();
            label10000.Text = String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds);
            };
        }
Пример #7
0
 public void Start(Track track)
 {
     if (session == null) {
         this.track = track;
         TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
         int secondsSinceEpoch = (int)t.TotalSeconds;
         session = new Session(track, secondsSinceEpoch);
         currentLap = new Lap(session, track, session.startTime, 0);
         session.laps.Add(currentLap);
         nextGate = track.start;
         lastPoint = null;
         lapNumber = 0;
         splitStartTime = session.startTime;
         if (bestLap != null) { bestIndex = 0; }
         splitGaps = new double[track.NumSplits()];
     }
 }