/[cits3200i]/branches/gps-running-clean-r116/HighScorePlugin/Source/Goal.cs


UCC Code Repository

Contents of /branches/gps-running-clean-r116/HighScorePlugin/Source/Goal.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations) (download)
Sun Sep 5 15:48:34 2010 UTC (11 years, 3 months ago) by rvvs89
File size: 7887 byte(s)
Branching a local copy of the HEAD revision of the gps-running project on Google Code.
We will probably have to use this project as a template for our own plugins if we want to support SportTracks 2.1.
1 /*
2 Copyright (C) 2007, 2008 Kristian Bisgaard Lassen
3 Copyright (C) 2010 Kristian Helkjaer Lassen
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 using System;
20 using System.Collections.Generic;
21 using System.Text;
22 using System.Diagnostics;
23 using ZoneFiveSoftware.Common.Visuals;
24 using GpsRunningPlugin.Properties;
25 using GpsRunningPlugin.Util;
26
27 namespace GpsRunningPlugin.Source
28 {
29 public abstract class Goal
30 {
31 public Goal(bool upperBound, GoalParameter domain, GoalParameter image)
32 {
33 this.UpperBound = upperBound;
34 this.Domain = domain;
35 this.Image = image;
36 }
37
38 readonly public bool UpperBound;
39
40 readonly public GoalParameter Domain, Image;
41
42 public abstract String ToString(String speedUnit);
43
44 public abstract String ImageToString(string speedUnit);
45 }
46
47 public class PointGoal : Goal
48 {
49 public PointGoal(double goal, bool upperBound, GoalParameter domain, GoalParameter image)
50 :
51 base(upperBound, domain, image)
52 {
53 this.Value = goal;
54 }
55
56 readonly public double Value;
57
58 public override String ToString(String speedUnit)
59 {
60 String str;
61 switch (Domain)
62 {
63 case GoalParameter.Distance:
64 if (UpperBound) str = Resources.LongestDistanceTraveled;
65 else str = Resources.ShortestDistanceTraveled;
66 break;
67 case GoalParameter.Time:
68 if (UpperBound) str = Resources.LongestTimeSpent;
69 else str = Resources.ShortestTimeSpent;
70 break;
71 case GoalParameter.Elevation:
72 if (UpperBound) str = Resources.BiggestElevationDifference;
73 else str = Resources.SmallestElevationDifference;
74 break;
75 default:
76 throw new Exception();
77 }
78 str += " ";
79 switch (Image)
80 {
81 case GoalParameter.Distance:
82 str += Resources.OnADistanceOf + " " + UnitUtil.Distance.ToString(Value,"u");
83 break;
84 case GoalParameter.Time:
85 str += Resources.OnATimeOf + " " + UnitUtil.Time.ToString(Value, "u");
86 break;
87 case GoalParameter.Elevation:
88 str += Resources.OnAnElevationOf + " " + UnitUtil.Elevation.ToString(Value, "u");
89 break;
90 default:
91 throw new Exception();
92 }
93 return str;
94 }
95
96 public override String ImageToString(string speedUnit)
97 {
98 switch (Image)
99 {
100 case GoalParameter.Distance:
101 return UnitUtil.Distance.ToString(Value, "u");
102 case GoalParameter.Time:
103 return UnitUtil.Time.ToString(Value);
104 case GoalParameter.Elevation:
105 return UnitUtil.Elevation.ToString(Value, "u");;
106 }
107 return null;
108 }
109 }
110
111 public class IntervalsGoal : Goal
112 {
113 public IntervalsGoal(IList<IList<double>> intervals, bool upperBound,
114 GoalParameter domain, GoalParameter image)
115 :
116 base(upperBound, domain, image)
117 {
118 this.Intervals = intervals;
119 }
120
121 readonly public IList<IList<double>> Intervals;
122
123 private string getInfo(string speedUnit, double min, double max, int format)
124 {
125 string str;
126 string from;
127 string to;
128
129 if (speedUnit.Equals(CommonResources.Text.LabelPace))
130 {
131 from = UnitUtil.Pace.ToString(max);
132 to = UnitUtil.Pace.ToString(min);
133 str = Resources.WithAPaceBetween;
134 }
135 else
136 {
137 from = UnitUtil.Speed.ToString(min);
138 to = UnitUtil.Speed.ToString(max);
139 str = Resources.WithASpeedBetween;
140 }
141 if (0 == format)
142 {
143 str += " " + from + " " + UnitUtil.Pace.LabelAbbr +
144 " " + StringResources.And.ToLower() + " " +
145 to + " " + UnitUtil.Pace.LabelAbbr;
146 } else {
147 str = from + "\n-\n" + to;
148 }
149 return str;
150 }
151
152 public override string ToString(String speedUnit)
153 {
154 String str;
155 switch (Domain)
156 {
157 case GoalParameter.Distance:
158 if (UpperBound) str = Resources.LongestDistanceTraveled;
159 else str = Resources.ShortestDistanceTraveled;
160 break;
161 case GoalParameter.Time:
162 if (UpperBound) str = Resources.LongestTimeSpent;
163 else str = Resources.ShortestTimeSpent;
164 break;
165 case GoalParameter.Elevation:
166 if (UpperBound) str = Resources.BiggestElevationDifference;
167 else str = Resources.SmallestElevationDifference;
168 break;
169 default:
170 throw new Exception();
171 }
172 str += " ";
173 switch (Image)
174 {
175 case GoalParameter.PulseZone:
176 str += Resources.WithAHRBetween;
177 str += " " + Intervals[0][0] + " - " + Intervals[0][1];
178 break;
179 case GoalParameter.SpeedZone:
180 str += getInfo(speedUnit, Intervals[0][0], Intervals[0][1], 0);
181 break;
182 case GoalParameter.PulseZoneSpeedZone:
183 str += Resources.WithAHRBetween;
184 str += " "+Intervals[0][0]+" - "+Intervals[0][1];
185 str += " "+StringResources.And.ToLower()+" ";
186 str += getInfo(speedUnit, Intervals[1][0], Intervals[1][1], 0);
187 break;
188 }
189 return str;
190 }
191
192 public override String ImageToString(string speedUnit)
193 {
194 String str = null;
195 switch (Image)
196 {
197 case GoalParameter.PulseZone:
198 str = Intervals[0][0] + "\n-\n" + Intervals[0][1];
199 break;
200 case GoalParameter.SpeedZone:
201 str = getInfo(speedUnit, Intervals[0][0], Intervals[0][1], 1);
202 break;
203 case GoalParameter.PulseZoneSpeedZone:
204 String res = Intervals[0][0] + "\n" + Intervals[0][1]+"\n/\n";
205 str = getInfo(speedUnit, Intervals[1][0], Intervals[1][1], 1);
206 break;
207 }
208 return str;
209 }
210 }
211
212 public enum GoalParameter
213 {
214 Distance, Time, Elevation, PulseZone, SpeedZone, CadenceZone, PulseZoneSpeedZone
215 }
216 }
217

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26