[chronojump] Check sprints before sending R to avoid freeze time on R



commit f763135c07f2c99469567fc2f7793a2204866ba8
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Apr 9 13:44:31 2018 +0200

    Check sprints before sending R to avoid freeze time on R

 po/POTFILES.in    |    1 +
 src/gui/sprint.cs |    8 +++++
 src/sprint.cs     |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 08b9ed3..3accd4a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -110,6 +110,7 @@ src/report.cs
 src/runType.cs
 src/server.cs
 src/serverPing.cs
+src/sprint.cs
 src/sqlite/country.cs
 src/sqlite/encoder.cs
 src/sqlite/main.cs
diff --git a/src/gui/sprint.cs b/src/gui/sprint.cs
index 8b777d1..8a83a72 100644
--- a/src/gui/sprint.cs
+++ b/src/gui/sprint.cs
@@ -250,6 +250,14 @@ LogB.Information("SPRINT add 6");
                        return false;
                }
 
+               if(! sprint.IsDataOk())
+               {
+                       new DialogMessage(Constants.MessageTypes.WARNING,
+                                       Catalog.GetString("This data does not seem a sprint.") + "\n\n" +
+                                       sprint.ErrorMessage);
+                       return false;
+               }
+
                Util.FileDelete(UtilEncoder.GetSprintImage());
 
                image_sprint.Sensitive = false;
diff --git a/src/sprint.cs b/src/sprint.cs
index 245e263..1b5acc4 100644
--- a/src/sprint.cs
+++ b/src/sprint.cs
@@ -21,6 +21,7 @@
 using System;
 using System.IO;               //for detect OS
 using System.Collections.Generic; //List<T>
+using Mono.Unix;
 
 public class Sprint
 {
@@ -31,6 +32,7 @@ public class Sprint
        private double mass;
        private double personHeight;
        private double tempC;
+       private string errorMessage;
 
        public Sprint(string positions, string splitTimes,
                        double mass, double personHeight, double tempC)
@@ -40,6 +42,8 @@ public class Sprint
                this.mass = mass;
                this.personHeight = personHeight;
                this.tempC = tempC;
+
+               errorMessage = "";
        }
 
        /*
@@ -138,6 +142,82 @@ public class Sprint
                return splitTimesList;
        }
 
+       /*
+        * if there are double contacts problems and first contacts are very close,
+        * R algorithm gets very slow and program seems frozen
+        */
+       public bool IsDataOk()
+       {
+               List<double> speedsL = speedAsDoubleL();
+               double speedMax = -1;
+               int trackMax = 1;
+               int count = 1;
+
+               foreach(double speed in speedsL)
+               {
+                       LogB.Information("speed: " + speed.ToString());
+                       if(speedMax < 0)
+                               speedMax = speed;
+                       else if( (2 * speed) < speedMax)
+                       {
+                               errorMessage = string.Format(
+                                                       Catalog.GetString("Track {0} ({1} m/s) is much faster 
than track {2} ({3} m/s)."),
+                                                       trackMax, Math.Round(speedMax,2), count, 
Math.Round(speed, 2));
+                               return false;
+                       }
+                       else if(speed > speedMax)
+                       {
+                               speedMax = speed;
+                               trackMax = count;
+                       }
+
+                       count ++;
+               }
+
+               errorMessage = "";
+               return true;
+       }
+
+       private List<double> speedAsDoubleL()
+       {
+               List<double> speedsL = new List<double>();
+               List<double> positionsL = positionsAsDoubleL();
+               List<double> splitTimesL = splitTimesAsDoubleL();
+
+               //start with 1 because at 0 is the first contact
+               for(int i = 1; i < positionsL.Count ; i ++)
+               {
+                       double speed = 1.0 * (positionsL[i] - positionsL[i-1]) /
+                               (1.0 * (splitTimesL[i] - splitTimesL[i-1]));
+                       speedsL.Add(speed);
+               }
+               return speedsL;
+       }
+
+       private List<double> positionsAsDoubleL()
+       {
+               List<double> l = new List<double>();
+               string [] positionsFull = positions.Split(new char[] {';'});
+               foreach(string p in positionsFull)
+               {
+                       double d = Convert.ToDouble(Util.ChangeDecimalSeparator(p));
+                       l.Add(d);
+               }
+               return l;
+       }
+
+       private List<double> splitTimesAsDoubleL()
+       {
+               List<double> l = new List<double>();
+               string [] splitTimesFull = splitTimes.Split(new char[] {';'});
+               foreach(string s in splitTimesFull)
+               {
+                       double d = Convert.ToDouble(Util.ChangeDecimalSeparator(s));
+                       l.Add(d);
+               }
+               return l;
+       }
+
        public string Positions {
                get { return positions; }
        }
@@ -145,4 +225,8 @@ public class Sprint
        public string SplitTimes {
                get { return splitTimes; }
        }
+
+       public string ErrorMessage {
+               get { return errorMessage; }
+       }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]