Exemplo n.º 1
0
 public Goal(bool upperBound, GoalParameter domain, GoalParameter image, int order)
 {
     this.UpperBound = upperBound;
     this.Domain = domain;
     this.Image = image;
     this.Order = order;
 }
Exemplo n.º 2
0
 public double getValue(GoalParameter gp, string speedUnit)
 {
     switch (gp)
     {
         case GoalParameter.Distance:
             return UnitUtil.Distance.ConvertFrom(this.Meters);
         case GoalParameter.Time:
             return this.Seconds;
         case GoalParameter.Elevation:
             return UnitUtil.Elevation.ConvertFrom(this.Elevations);
         case GoalParameter.PulseZone:
             return this.AveragePulse;
         case GoalParameter.SpeedZone:
             double speed = this.Meters / this.Seconds;
             return UnitUtil.PaceOrSpeed.ConvertFrom(speedUnit.Equals(CommonResources.Text.LabelPace), speed);
         case GoalParameter.PulseZoneSpeedZone:
             return this.AveragePulse;
     }
     throw new Exception();
 }
Exemplo n.º 3
0
        private static bool load()
        {
            //Backwards compatibility, read old preferences file
            String prefsPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "HighScorePlugin" + Path.DirectorySeparatorChar + "preferences.xml";

            if (!File.Exists(prefsPath)) return false;
            XmlDocument document = new XmlDocument();
            XmlReader reader = new XmlTextReader(prefsPath);
            document.Load(reader);
            XmlNode root = document.FirstChild;
            if (!root.Name.Equals("highscore")) return false;
            try
            {
                foreach (XmlNode elm in root.ChildNodes)
                {
                    if (elm.Name.Equals("distances"))
                    {
                        if (elm.Attributes["values"].Value.Length > 0)
                        {
                            String[] values = elm.Attributes["values"].Value.Split(';');
                            foreach (String distance in values)
                            {
                                distances.Add(parseDouble(distance), true);
                            }
                        }
                    }
                    else if (elm.Name.Equals("times"))
                    {
                        if (elm.Attributes["values"].Value.Length > 0)
                        {
                            String[] values = elm.Attributes["values"].Value.Split(';');
                            foreach (String value in values)
                            {
                                int seconds = int.Parse(value);
                                if (!times.ContainsKey(seconds))
                                    times.Add(seconds, new TimeSpan(0, 0, seconds));
                            }
                        }
                    }
                    else if (elm.Name.Equals("elevations"))
                    {
                        if (elm.Attributes["values"].Value.Length > 0)
                        {
                            String[] values = elm.Attributes["values"].Value.Split(';');
                            foreach (String elevation in values)
                            {
                                elevations.Add(parseDouble(elevation), true);
                            }
                        }
                    }
                    else if (elm.Name.Equals("pulseZones"))
                    {
                        if (elm.Attributes["values"].Value.Length > 0)
                        {
                            String[] values = elm.Attributes["values"].Value.Split(';');
                            foreach (String value in values)
                            {
                                String[] pair = value.Split(' ');
                                double min = parseDouble(pair[0]);
                                double max = parseDouble(pair[1]);
                                if (pulseZones.ContainsKey(min))
                                {
                                    if (!pulseZones[min].ContainsKey(max))
                                    {
                                        pulseZones[min].Add(max, true);
                                    }
                                }
                                else
                                {
                                    SortedList<double, bool> list = new SortedList<double, bool>();
                                    list.Add(max, true);
                                    pulseZones.Add(min, list);
                                }
                            }
                        }
                    }
                    else if (elm.Name.Equals("speedZones"))
                    {
                        if (elm.Attributes["values"].Value.Length > 0)
                        {
                            String[] values = elm.Attributes["values"].Value.Split(';');
                            foreach (String value in values)
                            {
                                String[] pair = value.Split(' ');
                                double min = parseDouble(pair[0]);
                                double max = parseDouble(pair[1]);
                                if (speedZones.ContainsKey(min))
                                {
                                    if (!speedZones[min].ContainsKey(max))
                                    {
                                        speedZones[min].Add(max, true);
                                    }
                                }
                                else
                                {
                                    SortedList<double, bool> list = new SortedList<double, bool>();
                                    list.Add(max, true);
                                    speedZones.Add(min, list);
                                }
                            }
                        }
                    }
                    else if (elm.Name.Equals("view"))
                    {
                        domain = (GoalParameter) Enum.Parse(typeof(GoalParameter),elm.Attributes["domain"].Value,true);
                        image = (GoalParameter)Enum.Parse(typeof(GoalParameter), elm.Attributes["image"].Value, true);
                        upperBound = bool.Parse(elm.Attributes["upperBound"].Value);
                        windowSize = new Size(int.Parse(elm.Attributes["viewWidth"].Value),
                                                    int.Parse(elm.Attributes["viewHeight"].Value));
                        if (elm.Attributes["showTable"] == null)
                            showTable = true;
                        else
                            showTable = bool.Parse(elm.Attributes["showTable"].Value);
                        if (elm.Attributes["ignoreManualData"] == null)
                            ignoreManualData = true;
                        else
                            ignoreManualData = bool.Parse(elm.Attributes["ignoreManualData"].Value);
                    }
                }
            }
            catch (Exception)
            {
                reader.Close();
                return false;
            }
            reader.Close();
            return true;
        }
Exemplo n.º 4
0
        public static void ReadOptions(XmlDocument xmlDoc, XmlNamespaceManager nsmgr, XmlElement pluginNode)
        {
            String attr, attr2;

            attr = pluginNode.GetAttribute(xmlTags.settingsVersion);
            if (attr.Length > 0) { settingsVersion = (Int16)XmlConvert.ToInt16(attr); }
            if (0 == settingsVersion)
            {
                // No settings in Preferences.System found, try read old files
                load();
            }

            attr = pluginNode.GetAttribute(xmlTags.distances);
            if (attr.Length > 0)
            {
                distances.Clear();
                String[] values = attr.Split(';');
                foreach (String distance in values)
                {
                    distances.Add(parseDouble(distance), true);
                }
            }
            attr = pluginNode.GetAttribute(xmlTags.times);
            if (attr.Length > 0)
            {
                times.Clear();
                String[] values = attr.Split(';');
                foreach (String value in values)
                {
                    int seconds = int.Parse(value);
                    if (!times.ContainsKey(seconds))
                    {
                        times.Add(seconds, new TimeSpan(0, 0, seconds));
                    }
                }
            }
            attr = pluginNode.GetAttribute(xmlTags.elevations);
            if (attr.Length > 0)
            {
                elevations.Clear();
                String[] values = attr.Split(';');
                foreach (String elevation in values)
                {
                    elevations.Add(parseDouble(elevation), true);
                }
            }
            attr = pluginNode.GetAttribute(xmlTags.pulseZones);
            if (attr.Length > 0)
            {
                pulseZones.Clear();
                String[] values = attr.Split(';');
                foreach (String value in values)
                {
                    String[] pair = value.Split(' ');
                    double min = parseDouble(pair[0]);
                    double max = parseDouble(pair[1]);
                    if (pulseZones.ContainsKey(min))
                    {
                        if (!pulseZones[min].ContainsKey(max))
                        {
                            pulseZones[min].Add(max, true);
                        }
                    }
                    else
                    {
                        SortedList<double, bool> list = new SortedList<double, bool>();
                        list.Add(max, true);
                        pulseZones.Add(min, list);
                    }
                }
            }
            attr = pluginNode.GetAttribute(xmlTags.speedZones);
            if (attr.Length > 0)
            {
                speedZones.Clear();
                String[] values = attr.Split(';');
                foreach (String value in values)
                {
                    String[] pair = value.Split(' ');
                    double min = parseDouble(pair[0]);
                    double max = parseDouble(pair[1]);
                    if (speedZones.ContainsKey(min))
                    {
                        if (!speedZones[min].ContainsKey(max))
                        {
                            speedZones[min].Add(max, true);
                        }
                    }
                    else
                    {
                        SortedList<double, bool> list = new SortedList<double, bool>();
                        list.Add(max, true);
                        speedZones.Add(min, list);
                    }
                }
            }

            attr = pluginNode.GetAttribute(xmlTags.domain);
            if (attr.Length > 0) { domain = (GoalParameter)Enum.Parse(typeof(GoalParameter), attr, true); }
            attr = pluginNode.GetAttribute(xmlTags.image);
            if (attr.Length > 0) { image = (GoalParameter)Enum.Parse(typeof(GoalParameter), attr, true); }
            attr = pluginNode.GetAttribute(xmlTags.upperBound);
            if (attr.Length > 0) { upperBound = XmlConvert.ToBoolean(attr); }
            attr = pluginNode.GetAttribute(xmlTags.showTable);
            if (attr.Length > 0) { showTable = XmlConvert.ToBoolean(attr); }
            attr = pluginNode.GetAttribute(xmlTags.ignoreManualData);
            if (attr.Length > 0) { ignoreManualData = XmlConvert.ToBoolean(attr); }
            attr = pluginNode.GetAttribute(xmlTags.minGrade);
            if (attr.Length > 0) { minGrade = XmlConvert.ToDouble(attr); }
            attr = pluginNode.GetAttribute(xmlTags.showTrailsHint);
            if (attr.Length > 0) { showTrailsHint = XmlConvert.ToBoolean(attr); }

            attr = pluginNode.GetAttribute(xmlTags.viewWidth);
            attr2 = pluginNode.GetAttribute(xmlTags.viewHeight);
            if (attr.Length > 0 && attr2.Length > 0)
            {
                windowSize = new Size(XmlConvert.ToInt16(attr), XmlConvert.ToInt16(attr2));
            }
        }
Exemplo n.º 5
0
 public static void defaults()
 {
     resetLists();
     domain = GoalParameter.Time;
     image = GoalParameter.Distance;
     upperBound = false;
     showTable = true;
     ignoreManualData = true;
     minGrade = -0.02;
     showTrailsHint = true;
     windowSize = new Size(600, 500);
 }
Exemplo n.º 6
0
 public static void generateGoals(GoalParameter domain, GoalParameter image, bool upperBound, IList<Goal> goals)
 {
     switch (image)
     {
         case GoalParameter.Distance:
             foreach (double distance in Settings.distances.Keys)
             {
                 goals.Add(new PointGoal(distance, upperBound,
                             domain, GoalParameter.Distance));
             }
             break;
         case GoalParameter.Time:
             foreach (int time in Settings.times.Keys)
             {
                 goals.Add(new PointGoal(time, upperBound,
                             domain, GoalParameter.Time));
             }
             break;
         case GoalParameter.Elevation:
             foreach (double elevation in Settings.elevations.Keys)
             {
                 goals.Add(new PointGoal(elevation, upperBound,
                             domain, GoalParameter.Elevation));
             }
             break;
         case GoalParameter.PulseZone:
             foreach (double min in Settings.pulseZones.Keys)
             {
                 foreach (double max in Settings.pulseZones[min].Keys)
                 {
                     IList<IList<double>> intervals = new List<IList<double>>();
                     IList<double> interval = new List<double>();
                     interval.Add(min);
                     interval.Add(max);
                     intervals.Add(interval);
                     goals.Add(new IntervalsGoal(intervals, upperBound,
                                 domain, GoalParameter.PulseZone));
                 }
             }
             break;
         //case GoalParameter.SpeedZone:
         //    foreach (double min in Settings.speedZones.Keys)
         //    {
         //        foreach (double max in Settings.speedZones[min].Keys)
         //        {
         //            IList<IList<double>> intervals = new List<IList<double>>();
         //            IList<double> interval = new List<double>();
         //            interval.Add(min);
         //            interval.Add(max);
         //            intervals.Add(interval);
         //            goals.Add(new IntervalsGoal(intervals, upperBound,
         //                        domain, GoalParameter.SpeedZone));
         //        }
         //    }
         //    break;
         case GoalParameter.PulseZoneSpeedZone:
             foreach (double minPulse in Settings.pulseZones.Keys)
             {
                 foreach (double maxPulse in Settings.pulseZones[minPulse].Keys)
                 {
                     foreach (double minSpeed in Settings.speedZones.Keys)
                     {
                         foreach (double maxSpeed in Settings.speedZones[minSpeed].Keys)
                         {
                             IList<IList<double>> intervals = new List<IList<double>>();
                             IList<double> interval = new List<double>();
                             interval.Add(minPulse);
                             interval.Add(maxPulse);
                             intervals.Add(interval);
                             interval = new List<double>();
                             interval.Add(minSpeed);
                             interval.Add(maxSpeed);
                             intervals.Add(interval);
                             goals.Add(new IntervalsGoal(intervals, upperBound,
                                 domain, GoalParameter.PulseZoneSpeedZone));
                         }
                     }
                 }
             }
             break;
     }
 }
Exemplo n.º 7
0
 public static bool IsZoneGoal(GoalParameter gp)
 {
     return (gp != GoalParameter.Time && gp != GoalParameter.Distance && gp != GoalParameter.Elevation);
 }
Exemplo n.º 8
0
 public IntervalsGoal(IList<IList<double>> intervals, bool upperBound, 
     GoalParameter domain, GoalParameter image)
     : base(upperBound, domain, image)
 {
     this.Intervals = intervals;
 }
Exemplo n.º 9
0
 public PointGoal(double goal, bool upperBound, GoalParameter domain, GoalParameter image)
     : base(upperBound, domain, image)
 {
     this.Value = goal;
 }
Exemplo n.º 10
0
 public Goal(bool upperBound, GoalParameter domain, GoalParameter image) : this(upperBound, domain, image, 1)
 {
 }
Exemplo n.º 11
0
 public static void setAxisType(IAxis axis, GoalParameter goal)
 {
     switch (goal)
     {
         case GoalParameter.Time:
             axis.Formatter = new Formatter.SecondsToTime(); 
             return;
         case GoalParameter.Distance:
             axis.Formatter = new Formatter.General(UnitUtil.Distance.DefaultDecimalPrecision); 
             return;
         case GoalParameter.Elevation:
             axis.Formatter = new Formatter.General(UnitUtil.Elevation.DefaultDecimalPrecision); 
             return;
         //case GoalParameter.SpeedZone:
         //    ArrayList categories = new ArrayList();
         //    ArrayList keys = new ArrayList();
         //    int index = 0;
         //    foreach (double from in Settings.speedZones.Keys)
         //    {
         //        foreach (double to in Settings.speedZones[from].Keys)
         //        {
         //            categories.Add(UnitUtil.Speed.ToString(from) + "-" + UnitUtil.Speed.ToString(to));
         //            keys.Add(index++);
         //        }
         //    }
         //    axis.Formatter = new Formatter.Category(categories, keys);
         //    return;
         default:
             axis.Formatter = new Formatter.General(); 
             return;
     }
 }
Exemplo n.º 12
0
 public static String getGoalParameterLabel(GoalParameter gp, String speedUnit)
 {
     switch (gp)
     {
         case GoalParameter.Distance:
             return UnitUtil.Distance.LabelAxis;
         case GoalParameter.Time:
             return UnitUtil.Time.LabelAxis;
         case GoalParameter.Elevation:
             return UnitUtil.Elevation.LabelAxis;
         case GoalParameter.PulseZone:
             return UnitUtil.HeartRate.LabelAxis;
         case GoalParameter.SpeedZone:
             if (speedUnit.Equals(CommonResources.Text.LabelPace)) return UnitUtil.Pace.LabelAxis;
             return UnitUtil.Speed.LabelAxis;
         case GoalParameter.PulseZoneSpeedZone:
             return UnitUtil.HeartRate.LabelAxis;
     }
     throw new Exception();
 }
Exemplo n.º 13
0
 public static string translateToLanguage(GoalParameter goalParameter)
 {
     if (goalParameter.Equals(GoalParameter.PulseZone))
         return StringResources.HRZone;
     if (goalParameter.Equals(GoalParameter.SpeedZone))
         return StringResources.SpeedZone;
     if (goalParameter.Equals(GoalParameter.PulseZoneSpeedZone))
         return Resources.HRAndSpeedZones;
     if (goalParameter.Equals(GoalParameter.Distance))
         return CommonResources.Text.LabelDistance;
     if (goalParameter.Equals(GoalParameter.Elevation))
         return CommonResources.Text.LabelElevation;
     if (goalParameter.Equals(GoalParameter.Time))
         return CommonResources.Text.LabelTime;
     return null;
 }
Exemplo n.º 14
0
 public IList<double[]> getGoalZoneTrack(GoalParameter goal)
 {
     IList<double[]> result = new List<double[]>();
     switch (goal)
     {
         case GoalParameter.PulseZone:
             result.Add(this.aPulse);
             break;
         case GoalParameter.SpeedZone:
             result.Add(this.aSpeed);
             break;
         case GoalParameter.PulseZoneSpeedZone:
             result.Add(this.aPulse);
             result.Add(this.aSpeed);
             break;
     }
     return result;
 }
Exemplo n.º 15
0
 public double[] getGoalTrack(GoalParameter goal)
 {
     switch (goal)
     {
         case GoalParameter.Distance:
             return this.aDistance;
         case GoalParameter.Time:
             return this.aTime;
         case GoalParameter.Elevation:
             return this.aElevation;
     }
     return null;
 }