~opensatnav-admins/opensatnav/release-1.0

« back to all changes in this revision

Viewing changes to src/org/opensatnav/android/stats/TripStatisticsData.java

  • Committer: Kieran Fleming
  • Date: 2010-12-13 13:13:48 UTC
  • Revision ID: kieran.fleming@gmail.com-20101213131348-pixo12i0wjf11jk3
Add all the missing stuff from the failed package rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Google Inc.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 
5
 * use this file except in compliance with the License. You may obtain a copy of
 
6
 * the License at
 
7
 * 
 
8
 * http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
 * License for the specific language governing permissions and limitations under
 
14
 * the License.
 
15
 */
 
16
package org.opensatnav.android.stats;
 
17
 
 
18
import android.os.Parcel;
 
19
import android.os.Parcelable;
 
20
 
 
21
/**
 
22
 * Statistical data about a trip.
 
23
 * The data in this class should be filled out by {@link TripStatistics}.
 
24
 *
 
25
 * TODO: Remove delegate methods from TripStatistics
 
26
 *       (detail is getTotalTime)
 
27
 * TODO: Make Waypoint and Track use this instead of having the same fields
 
28
 *
 
29
 * @author Rodrigo Damazio
 
30
 */
 
31
public class TripStatisticsData implements Parcelable {
 
32
 
 
33
  /**
 
34
   * The start time for the trip. This is system time which might not match gps
 
35
   * time.
 
36
   */
 
37
  long startTime;
 
38
 
 
39
  /**
 
40
   * The total time that we believe the user was traveling in milliseconds.
 
41
   */
 
42
  long movingTime;
 
43
 
 
44
  /**
 
45
   * The total time of the trip in milliseconds.
 
46
   * This is only updated when new points are received, so it may be stale.
 
47
   */
 
48
  long totalTime;
 
49
 
 
50
  /**
 
51
   * The total distance in meters that the user traveled on this trip.
 
52
   */
 
53
  double totalDistance;
 
54
 
 
55
  /**
 
56
   * The total elevation gained on this trip in meters.
 
57
   */
 
58
  double totalElevationGain;
 
59
 
 
60
  /**
 
61
   * The maximum speed in meters/second reported that we believe to be a valid
 
62
   * speed.
 
63
   */
 
64
  double maxSpeed;
 
65
 
 
66
  /**
 
67
   * The current speed in meters/second as reported by the gps.
 
68
   */
 
69
  double currentSpeed;
 
70
 
 
71
  /**
 
72
   * The current grade. This value is very noisy and not reported to the user.
 
73
   */
 
74
  double currentGrade;
 
75
 
 
76
  /**
 
77
   * The min and max latitude values seen in this trip.
 
78
   */
 
79
  final ExtremityMonitor latitudeExtremities = new ExtremityMonitor();
 
80
 
 
81
  /**
 
82
   * The min and max longitude values seen in this trip.
 
83
   */
 
84
  final ExtremityMonitor longitudeExtremities = new ExtremityMonitor();
 
85
 
 
86
  /**
 
87
   * The min and max elevation seen on this trip in meters.
 
88
   */
 
89
  final ExtremityMonitor elevationExtremities = new ExtremityMonitor();
 
90
 
 
91
  /**
 
92
   * The minimum and maximum grade calculations on this trip.
 
93
   */
 
94
  final ExtremityMonitor gradeExtremities = new ExtremityMonitor();
 
95
 
 
96
  /**
 
97
   * Gets the time that this track started.
 
98
   * 
 
99
   * @return The number of milliseconds since epoch to the time when this track
 
100
   *         started
 
101
   */
 
102
  public long getStartTime() {
 
103
    return startTime;
 
104
  }
 
105
 
 
106
  /**
 
107
   * Gets the total time that this track has been active.
 
108
   * 
 
109
   * @return The total number of milliseconds the track was active
 
110
   */
 
111
  public long getTotalTime() {
 
112
    return totalTime;
 
113
  }
 
114
 
 
115
  /**
 
116
   * Gets the total distance the user traveled.
 
117
   * 
 
118
   * @return The total distance traveled in meters
 
119
   */
 
120
  public double getTotalDistance() {
 
121
    return totalDistance;
 
122
  }
 
123
 
 
124
  /**
 
125
   * Gets the the maximum speed for this track.
 
126
   * 
 
127
   * @return The maximum speed in m/s.
 
128
   */
 
129
  public double getMaxSpeed() {
 
130
    return maxSpeed;
 
131
  }
 
132
 
 
133
  /**
 
134
   * Gets the the current speed for this track.
 
135
   * 
 
136
   * @return The current speed in m/s
 
137
   */
 
138
  public double getCurrentSpeed() {
 
139
    return currentSpeed;
 
140
  }
 
141
 
 
142
  /**
 
143
   * Gets the moving time.
 
144
   * 
 
145
   * @return The total number of milliseconds the user was moving
 
146
   */
 
147
  public long getMovingTime() {
 
148
    return movingTime;
 
149
  }
 
150
 
 
151
  /**
 
152
   * Gets the total elevation gain for this trip. This is calculated as the sum
 
153
   * of all positive differences in the smoothed elevation.
 
154
   * 
 
155
   * @return The elevation gain in meters for this trip
 
156
   */
 
157
  public double getTotalElevationGain() {
 
158
    return totalElevationGain;
 
159
  }
 
160
 
 
161
  /**
 
162
   * Gets the current grade.
 
163
   * 
 
164
   * @return The current grade
 
165
   */
 
166
  public double getCurrentGrade() {
 
167
    return currentGrade;
 
168
  }
 
169
 
 
170
  /**
 
171
   * Returns the leftmost position (lowest longitude) of the track.
 
172
   */
 
173
  public int getLeft() {
 
174
    return (int) (longitudeExtremities.getMin() * 1E6);
 
175
  }
 
176
 
 
177
  /**
 
178
   * Returns the rightmost position (highest longitude) of the track.
 
179
   */
 
180
  public int getRight() {
 
181
    return (int) (longitudeExtremities.getMax() * 1E6);
 
182
  }
 
183
 
 
184
  /**
 
185
   * Returns the bottommost position (lowest latitude) of the track.
 
186
   */
 
187
  public int getBottom() {
 
188
    return (int) (latitudeExtremities.getMin() * 1E6);
 
189
  }
 
190
 
 
191
  /**
 
192
   * Returns the topmost position (highest latitude) of the track.
 
193
   */
 
194
  public int getTop() {
 
195
    return (int) (latitudeExtremities.getMax() * 1E6);
 
196
  }
 
197
 
 
198
  /**
 
199
   * Gets the minimum elevation seen on this trip. This is calculated from the
 
200
   * smoothed elevation so this can actually be more than the current elevation.
 
201
   * 
 
202
   * @return The smallest elevation reading for this trip
 
203
   */
 
204
  public double getMinElevation() {
 
205
    return elevationExtremities.getMin();
 
206
  }
 
207
 
 
208
  /**
 
209
   * Gets the maximum elevation seen on this trip. This is calculated from the
 
210
   * smoothed elevation so this can actually be less than the current elevation.
 
211
   * 
 
212
   * @return The largest elevation reading for this trip
 
213
   */
 
214
  public double getMaxElevation() {
 
215
    return elevationExtremities.getMax();
 
216
  }
 
217
 
 
218
  /**
 
219
   * Gets the maximum grade for this trip.
 
220
   * 
 
221
   * @return The maximum grade for this trip
 
222
   */
 
223
  public double getMaxGrade() {
 
224
    return gradeExtremities.getMax();
 
225
  }
 
226
 
 
227
  /**
 
228
   * Gets the minimum grade for this trip.
 
229
   * 
 
230
   * @return The minimum grade for this trip
 
231
   */
 
232
  public double getMinGrade() {
 
233
    return gradeExtremities.getMin();
 
234
  }
 
235
 
 
236
  // Parcelable interface and creator
 
237
 
 
238
  /**
 
239
   * Creator of statistics data from parcels.
 
240
   */
 
241
  public static class Creator
 
242
      implements Parcelable.Creator<TripStatisticsData> {
 
243
 
 
244
    @Override
 
245
    public TripStatisticsData createFromParcel(Parcel source) {
 
246
      TripStatisticsData data = new TripStatisticsData();
 
247
 
 
248
      data.startTime = source.readLong();
 
249
      data.movingTime = source.readLong();
 
250
      data.totalTime = source.readLong();
 
251
      data.totalDistance = source.readDouble();
 
252
      data.totalElevationGain = source.readDouble();
 
253
      data.maxSpeed = source.readDouble();
 
254
      data.currentSpeed = source.readDouble();
 
255
      data.currentGrade = source.readDouble();
 
256
 
 
257
      double minLat = source.readDouble();
 
258
      double maxLat = source.readDouble();
 
259
      data.latitudeExtremities.set(minLat, maxLat);
 
260
 
 
261
      double minLong = source.readDouble();
 
262
      double maxLong = source.readDouble();
 
263
      data.longitudeExtremities.set(minLong, maxLong);
 
264
 
 
265
      double minElev = source.readDouble();
 
266
      double maxElev = source.readDouble();
 
267
      data.elevationExtremities.set(minElev, maxElev);
 
268
 
 
269
      double minGrade = source.readDouble();
 
270
      double maxGrade = source.readDouble();
 
271
      data.gradeExtremities.set(minGrade, maxGrade);
 
272
 
 
273
      return data;
 
274
    }
 
275
 
 
276
    @Override
 
277
    public TripStatisticsData[] newArray(int size) {
 
278
      return new TripStatisticsData[size];
 
279
    }
 
280
  }
 
281
 
 
282
  public static final Creator CREATOR = new Creator();
 
283
 
 
284
  @Override
 
285
  public int describeContents() {
 
286
    return 0;
 
287
  }
 
288
 
 
289
  @Override
 
290
  public void writeToParcel(Parcel dest, int flags) {
 
291
    dest.writeLong(startTime);
 
292
    dest.writeLong(movingTime);
 
293
    dest.writeLong(totalTime);
 
294
    dest.writeDouble(totalDistance);
 
295
    dest.writeDouble(totalElevationGain);
 
296
    dest.writeDouble(maxSpeed);
 
297
    dest.writeDouble(currentSpeed);
 
298
    dest.writeDouble(currentGrade);
 
299
 
 
300
    dest.writeDouble(latitudeExtremities.getMin());
 
301
    dest.writeDouble(latitudeExtremities.getMax());
 
302
    dest.writeDouble(longitudeExtremities.getMin());
 
303
    dest.writeDouble(longitudeExtremities.getMax());
 
304
    dest.writeDouble(elevationExtremities.getMin());
 
305
    dest.writeDouble(elevationExtremities.getMax());
 
306
    dest.writeDouble(gradeExtremities.getMin());
 
307
    dest.writeDouble(gradeExtremities.getMax());
 
308
  }
 
309
}
 
 
b'\\ No newline at end of file'