File: SpeedData.java

package info (click to toggle)
gpsprune 10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,220 kB
  • ctags: 3,013
  • sloc: java: 22,662; sh: 23; makefile: 16; python: 15
file content (83 lines) | stat: -rw-r--r-- 2,253 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package tim.prune.gui.profile;

import tim.prune.I18nManager;
import tim.prune.config.Config;
import tim.prune.data.DataPoint;
import tim.prune.data.Distance;
import tim.prune.data.Track;
import tim.prune.data.Distance.Units;

/**
 * Class to provide a source of speed data for the profile chart
 */
public class SpeedData extends ProfileData
{
	/** Flag for metric units */
	private boolean _metric = true;

	/**
	 * Constructor
	 * @param inTrack track object
	 */
	public SpeedData(Track inTrack) {
		super(inTrack);
	}

	/**
	 * Get the data and populate the instance arrays
	 */
	public void init()
	{
		initArrays();
		_metric = Config.getConfigBoolean(Config.KEY_METRIC_UNITS);
		_hasData = false;
		_minValue = _maxValue = 0.0;
		if (_track != null) {
			DataPoint prevPrevPoint = null, prevPoint = null, point = null;
			for (int i=0; i<_track.getNumPoints(); i++)
			{
				point = _track.getPoint(i);
				if (prevPrevPoint != null && prevPrevPoint.hasTimestamp()
					&& prevPoint != null && prevPoint.hasTimestamp()
					&& point != null && point.hasTimestamp())
				{
					// All three points have timestamps
					double seconds = point.getTimestamp().getSecondsSince(prevPrevPoint.getTimestamp());
					if (seconds > 0)
					{
						double distInRads = DataPoint.calculateRadiansBetween(prevPrevPoint, prevPoint)
							+ DataPoint.calculateRadiansBetween(prevPoint, point);
						double dist = Distance.convertRadiansToDistance(distInRads, _metric?Units.KILOMETRES:Units.MILES);
						// Store the value and maintain max and min values
						double value = dist / seconds * 60.0 * 60.0;
						_pointValues[i-1] = value;
						if (value < _minValue || _minValue == 0.0) {_minValue = value;}
						if (value > _maxValue) {_maxValue = value;}

						_hasData = true;
						_pointHasData[i-1] = true;
					}
				}
				// Exchange points
				prevPrevPoint = prevPoint;
				prevPoint = point;
			}
		}
	}

	/**
	 * @return text description including units
	 */
	public String getLabel()
	{
		return I18nManager.getText("fieldname.speed") + " ("
			+ I18nManager.getText(_metric?"units.kmh":"units.mph") + ")";
	}

	/**
	 * @return key for message when no speeds present
	 */
	public String getNoDataKey() {
		return "display.notimestamps";
	}
}