Line | Hits | Source |
---|---|---|
1 | package net.sf.tourviewer.lib; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Date; | |
5 | import java.util.List; | |
6 | ||
7 | public class Tour implements Comparable { | |
8 | ||
9 | 0 | private boolean autoStatistics = true; |
10 | double avgAltitudeInc; | |
11 | double avgPulse; | |
12 | double avgSlope; | |
13 | double avgSpeed; | |
14 | double avgTemperature; | |
15 | private Bike bike; | |
16 | private long distance; | |
17 | private String endLocation; | |
18 | private Date endTime; | |
19 | 0 | private List<Marker> markers = new ArrayList<Marker>(); |
20 | int maxAltitude; | |
21 | private String note; | |
22 | 0 | private List<TourRecord> records = new ArrayList<TourRecord>(); |
23 | private String startLocation; | |
24 | private Date startTime; | |
25 | private String title; | |
26 | int totalAltitudeDown; | |
27 | int totalAltitudeUp; | |
28 | private long travelTime; | |
29 | private Type type; | |
30 | ||
31 | public Tour() | |
32 | 0 | { |
33 | 0 | } |
34 | ||
35 | public void addMarker(Marker marker) | |
36 | { | |
37 | 0 | markers.add(marker); |
38 | 0 | } |
39 | ||
40 | public void addRecord(TourRecord record) | |
41 | { | |
42 | 0 | if (!records.isEmpty()) { |
43 | 0 | TourRecord previous = records.get(records.size() - 1); |
44 | 0 | previous.setNext(record); |
45 | 0 | record.setPrevious(previous); |
46 | ||
47 | 0 | if (isAutoStatistics()) { |
48 | 0 | maxAltitude = Math.max(maxAltitude, record.getAltitude()); |
49 | 0 | updateStatistics(previous, record); |
50 | } | |
51 | 0 | } |
52 | 0 | else if (isAutoStatistics()) { |
53 | 0 | maxAltitude = record.getAltitude(); |
54 | } | |
55 | 0 | records.add(record); |
56 | 0 | } |
57 | ||
58 | public int compareTo(Object o) | |
59 | { | |
60 | 0 | return getStartTime().compareTo(((Tour)o).getStartTime()); |
61 | } | |
62 | ||
63 | public double getAvgAltitudeInc() | |
64 | { | |
65 | 0 | return avgAltitudeInc; |
66 | } | |
67 | ||
68 | public double getAvgPulse() | |
69 | { | |
70 | 0 | return avgPulse; |
71 | } | |
72 | ||
73 | public double getAvgSlope() | |
74 | { | |
75 | 0 | return avgSlope; |
76 | } | |
77 | ||
78 | public double getAvgSpeed() | |
79 | { | |
80 | 0 | return avgSpeed; |
81 | } | |
82 | ||
83 | public double getAvgTemperature() | |
84 | { | |
85 | 0 | return avgTemperature; |
86 | } | |
87 | ||
88 | public Bike getBike() | |
89 | { | |
90 | 0 | return bike; |
91 | } | |
92 | ||
93 | public long getDistance() | |
94 | { | |
95 | 0 | return distance; |
96 | } | |
97 | ||
98 | public String getEndLocation() | |
99 | { | |
100 | 0 | return endLocation; |
101 | } | |
102 | ||
103 | public Date getEndTime() | |
104 | { | |
105 | 0 | return endTime; |
106 | } | |
107 | ||
108 | public int getMaxAltitude() | |
109 | { | |
110 | 0 | return maxAltitude; |
111 | } | |
112 | ||
113 | public String getNote() | |
114 | { | |
115 | 0 | return note; |
116 | } | |
117 | ||
118 | public TourRecord[] getRecords() { | |
119 | 0 | return records.toArray(new TourRecord[0]); |
120 | } | |
121 | ||
122 | public String getStartLocation() | |
123 | { | |
124 | 0 | return startLocation; |
125 | } | |
126 | ||
127 | public Date getStartTime() | |
128 | { | |
129 | 0 | return startTime; |
130 | } | |
131 | ||
132 | public String getTitle() | |
133 | { | |
134 | 0 | return title; |
135 | } | |
136 | ||
137 | public int getTotalAltitudeDown() | |
138 | { | |
139 | 0 | return totalAltitudeDown; |
140 | } | |
141 | ||
142 | ||
143 | public int getTotalAltitudeUp() | |
144 | { | |
145 | 0 | return totalAltitudeUp; |
146 | } | |
147 | ||
148 | public long getTravelTime() | |
149 | { | |
150 | 0 | return travelTime; |
151 | } | |
152 | ||
153 | ||
154 | public Type getType() | |
155 | { | |
156 | 0 | return type; |
157 | } | |
158 | ||
159 | public boolean isAutoStatistics() | |
160 | { | |
161 | 0 | return autoStatistics; |
162 | } | |
163 | ||
164 | public void setAutoStatistics(boolean autoStatistics) | |
165 | { | |
166 | 0 | this.autoStatistics = autoStatistics; |
167 | 0 | } |
168 | ||
169 | public void setAvgAltitudeInc(double avgAltitudeInc) | |
170 | { | |
171 | 0 | this.avgAltitudeInc = avgAltitudeInc; |
172 | 0 | } |
173 | ||
174 | public void setAvgPulse(double avgPulse) | |
175 | { | |
176 | 0 | this.avgPulse = avgPulse; |
177 | 0 | } |
178 | ||
179 | public void setAvgSlope(double avgSlope) | |
180 | { | |
181 | 0 | this.avgSlope = avgSlope; |
182 | 0 | } |
183 | ||
184 | public void setAvgSpeed(double avgSpeed) | |
185 | { | |
186 | 0 | this.avgSpeed = avgSpeed; |
187 | 0 | } |
188 | ||
189 | public void setAvgTemperature(double avgTemperature) | |
190 | { | |
191 | 0 | this.avgTemperature = avgTemperature; |
192 | 0 | } |
193 | ||
194 | public void setBike(Bike bike) | |
195 | { | |
196 | 0 | this.bike = bike; |
197 | 0 | } |
198 | ||
199 | ||
200 | public void setDistance(long distance) | |
201 | { | |
202 | 0 | this.distance = distance; |
203 | 0 | } |
204 | ||
205 | public void setEndLocation(String endLocation) | |
206 | { | |
207 | 0 | this.endLocation = endLocation; |
208 | 0 | } |
209 | ||
210 | public void setEndTime(Date endTime) | |
211 | { | |
212 | 0 | this.endTime = endTime; |
213 | 0 | } |
214 | ||
215 | public void setMaxAltitude(int maxAltitude) | |
216 | { | |
217 | 0 | this.maxAltitude = maxAltitude; |
218 | 0 | } |
219 | ||
220 | public void setNote(String note) | |
221 | { | |
222 | 0 | this.note = note; |
223 | 0 | } |
224 | ||
225 | public void setStartLocation(String startLocation) | |
226 | { | |
227 | 0 | this.startLocation = startLocation; |
228 | 0 | } |
229 | ||
230 | public void setStartTime(Date startTime) | |
231 | { | |
232 | 0 | this.startTime = startTime; |
233 | 0 | } |
234 | ||
235 | public void setTitle(String title) | |
236 | { | |
237 | 0 | this.title = title; |
238 | 0 | } |
239 | ||
240 | public void setTotalAltitudeDown(int totalAltitudeDown) | |
241 | { | |
242 | 0 | this.totalAltitudeDown = totalAltitudeDown; |
243 | 0 | } |
244 | ||
245 | public void setTotalAltitudeUp(int totalAltitudeUp) | |
246 | { | |
247 | 0 | this.totalAltitudeUp = totalAltitudeUp; |
248 | 0 | } |
249 | ||
250 | public void setTravelTime(long travelTime) | |
251 | { | |
252 | 0 | this.travelTime = travelTime; |
253 | 0 | } |
254 | ||
255 | public void setType(Type type) | |
256 | { | |
257 | 0 | this.type = type; |
258 | 0 | } |
259 | ||
260 | @Override | |
261 | public String toString() | |
262 | { | |
263 | 0 | return getClass().getName() + String.format("[type=%s,distance=%d,startTime=%tF %tT,endTime=%tF %tT]", |
264 | type, distance, startTime, startTime, endTime, endTime); | |
265 | } | |
266 | ||
267 | ||
268 | private void updateStatistics(TourRecord previous, TourRecord current) | |
269 | { | |
270 | 0 | int altitudeDiff = current.getAltitude() - previous.getAltitude(); |
271 | 0 | avgAltitudeInc = current.getAltitude(); |
272 | 0 | if (altitudeDiff > 0) { |
273 | 0 | totalAltitudeUp += altitudeDiff; |
274 | 0 | } |
275 | else { | |
276 | 0 | totalAltitudeDown += -altitudeDiff; |
277 | } | |
278 | ||
279 | 0 | long timeDiff = (current.getTime().getTime() - previous.getTime().getTime()) / 1000; |
280 | 0 | long distanceDiff = current.getDistance() - previous.getDistance(); |
281 | 0 | if (distanceDiff != 0 && timeDiff > 0) { |
282 | 0 | long newTravelTime = travelTime + timeDiff; |
283 | 0 | double leftShare = travelTime / newTravelTime; |
284 | 0 | double rightShare = timeDiff / newTravelTime; |
285 | ||
286 | 0 | long slope = (altitudeDiff > 0) ? distanceDiff / altitudeDiff : 0; |
287 | 0 | avgSlope = avgSlope * leftShare + slope * rightShare; |
288 | 0 | double speed = (distanceDiff / timeDiff) * 3.6; |
289 | 0 | avgSpeed = avgSpeed * leftShare + speed * rightShare; |
290 | 0 | avgTemperature = avgTemperature * leftShare + current.getTemperature() * rightShare; |
291 | 0 | avgPulse = avgPulse * leftShare + current.getPulse() * rightShare; |
292 | ||
293 | 0 | travelTime = newTravelTime; |
294 | } | |
295 | 0 | } |
296 | ||
297 | ||
298 | public enum Type { BIKE, JOGGING, SKI, SKI_BIKE, OTHER } | |
299 | ||
300 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |