2
* Copyright 2010 Google Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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
16
package org.opensatnav.android.stats;
18
import android.os.Parcel;
19
import android.os.Parcelable;
22
* Statistical data about a trip.
23
* The data in this class should be filled out by {@link TripStatistics}.
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
29
* @author Rodrigo Damazio
31
public class TripStatisticsData implements Parcelable {
34
* The start time for the trip. This is system time which might not match gps
40
* The total time that we believe the user was traveling in milliseconds.
45
* The total time of the trip in milliseconds.
46
* This is only updated when new points are received, so it may be stale.
51
* The total distance in meters that the user traveled on this trip.
56
* The total elevation gained on this trip in meters.
58
double totalElevationGain;
61
* The maximum speed in meters/second reported that we believe to be a valid
67
* The current speed in meters/second as reported by the gps.
72
* The current grade. This value is very noisy and not reported to the user.
77
* The min and max latitude values seen in this trip.
79
final ExtremityMonitor latitudeExtremities = new ExtremityMonitor();
82
* The min and max longitude values seen in this trip.
84
final ExtremityMonitor longitudeExtremities = new ExtremityMonitor();
87
* The min and max elevation seen on this trip in meters.
89
final ExtremityMonitor elevationExtremities = new ExtremityMonitor();
92
* The minimum and maximum grade calculations on this trip.
94
final ExtremityMonitor gradeExtremities = new ExtremityMonitor();
97
* Gets the time that this track started.
99
* @return The number of milliseconds since epoch to the time when this track
102
public long getStartTime() {
107
* Gets the total time that this track has been active.
109
* @return The total number of milliseconds the track was active
111
public long getTotalTime() {
116
* Gets the total distance the user traveled.
118
* @return The total distance traveled in meters
120
public double getTotalDistance() {
121
return totalDistance;
125
* Gets the the maximum speed for this track.
127
* @return The maximum speed in m/s.
129
public double getMaxSpeed() {
134
* Gets the the current speed for this track.
136
* @return The current speed in m/s
138
public double getCurrentSpeed() {
143
* Gets the moving time.
145
* @return The total number of milliseconds the user was moving
147
public long getMovingTime() {
152
* Gets the total elevation gain for this trip. This is calculated as the sum
153
* of all positive differences in the smoothed elevation.
155
* @return The elevation gain in meters for this trip
157
public double getTotalElevationGain() {
158
return totalElevationGain;
162
* Gets the current grade.
164
* @return The current grade
166
public double getCurrentGrade() {
171
* Returns the leftmost position (lowest longitude) of the track.
173
public int getLeft() {
174
return (int) (longitudeExtremities.getMin() * 1E6);
178
* Returns the rightmost position (highest longitude) of the track.
180
public int getRight() {
181
return (int) (longitudeExtremities.getMax() * 1E6);
185
* Returns the bottommost position (lowest latitude) of the track.
187
public int getBottom() {
188
return (int) (latitudeExtremities.getMin() * 1E6);
192
* Returns the topmost position (highest latitude) of the track.
194
public int getTop() {
195
return (int) (latitudeExtremities.getMax() * 1E6);
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.
202
* @return The smallest elevation reading for this trip
204
public double getMinElevation() {
205
return elevationExtremities.getMin();
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.
212
* @return The largest elevation reading for this trip
214
public double getMaxElevation() {
215
return elevationExtremities.getMax();
219
* Gets the maximum grade for this trip.
221
* @return The maximum grade for this trip
223
public double getMaxGrade() {
224
return gradeExtremities.getMax();
228
* Gets the minimum grade for this trip.
230
* @return The minimum grade for this trip
232
public double getMinGrade() {
233
return gradeExtremities.getMin();
236
// Parcelable interface and creator
239
* Creator of statistics data from parcels.
241
public static class Creator
242
implements Parcelable.Creator<TripStatisticsData> {
245
public TripStatisticsData createFromParcel(Parcel source) {
246
TripStatisticsData data = new TripStatisticsData();
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();
257
double minLat = source.readDouble();
258
double maxLat = source.readDouble();
259
data.latitudeExtremities.set(minLat, maxLat);
261
double minLong = source.readDouble();
262
double maxLong = source.readDouble();
263
data.longitudeExtremities.set(minLong, maxLong);
265
double minElev = source.readDouble();
266
double maxElev = source.readDouble();
267
data.elevationExtremities.set(minElev, maxElev);
269
double minGrade = source.readDouble();
270
double maxGrade = source.readDouble();
271
data.gradeExtremities.set(minGrade, maxGrade);
277
public TripStatisticsData[] newArray(int size) {
278
return new TripStatisticsData[size];
282
public static final Creator CREATOR = new Creator();
285
public int describeContents() {
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);
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());
b'\\ No newline at end of file'