Skip to content

Commit

Permalink
Fix issue #37with power playback and #67 GPX extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzof committed Aug 11, 2015
1 parent 07ae532 commit 18f418e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
14 changes: 10 additions & 4 deletions src/com/wattzap/model/ant/DummySpeedCadenceListener.java
Expand Up @@ -52,7 +52,6 @@ public class DummySpeedCadenceListener extends Thread implements
int resistance;
Power power;
boolean virtualPower;
private double levels = 1;

private static Logger logger = LogManager
.getLogger("DummySpeedCadenceListener");
Expand Down Expand Up @@ -89,6 +88,7 @@ public void run() {
// if ant disabled always use this calculation
if ((virtualPower || !UserPreferences.INSTANCE.isAntEnabled())
&& routeData != null) {

if (routeData.routeType() == RouteReader.SLOPE) {
p = routeData.getPoint(distance);

Expand Down Expand Up @@ -122,11 +122,16 @@ public void run() {
// what would be our real speed for those watts -
// show
// in odo

double realSpeed = power.getRealSpeed(mass,
p.getGradient() / 100, powerWatts);
speed = (realSpeed * 3600) / 1000;
}
} else {
// here we are a power file
// TODO For power files we just want to play at normal
// speed. OK we no there is no ANT here.

p = routeData.getPoint(distance);
// power comes from video (gradient)
// powerWatts = (int) ((p.getGradient()) +
Expand All @@ -150,15 +155,15 @@ public void run() {
t.setVirtualSpeed(bd.intValue());
t.setResistance(UserPreferences.INSTANCE
.getResistance());
// speed = p.getSpeed(); // FIXME what about RLV
if (routeData.getExtension().equals("pwr")) {
speed = p.getSpeed();
}
}
}
} else {
speed = power.getRealSpeed(mass, 0, powerWatts) * 3.6;
}

// t.setHeartRate((int) (110 + (powerWatts * 60 / 400)));
// t.setCadence((int) (60 + ((powerWatts * 40 / 300))));
t.setPower(powerWatts);

if (routeData != null) {
Expand All @@ -181,6 +186,7 @@ public void run() {
t.setSpeed(speed);
t.setDistanceMeters(distance * 1000);
t.setTime(System.currentTimeMillis());

MessageBus.INSTANCE.send(Messages.SPEED, t);

// d = s * t
Expand Down
39 changes: 29 additions & 10 deletions src/com/wattzap/utils/GpxImporter.java
Expand Up @@ -12,7 +12,7 @@
*
* You should have received a copy of the GNU General Public License
* along with Wattzap. If not, see <http://www.gnu.org/licenses/>.
*/
*/
package com.wattzap.utils;

import java.text.ParseException;
Expand Down Expand Up @@ -43,7 +43,7 @@
*/
public class GpxImporter extends DefaultHandler {
State currentState = State.UNDEFINED;
StringBuilder buffer;
StringBuilder buffer = new StringBuilder();
// GPX files have two data formats
private static final SimpleDateFormat msdateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Expand All @@ -69,7 +69,8 @@ public GpxImporter() {
currentState = State.UNDEFINED;
data = new ArrayList<Telemetry>();
distance = 0;
tzOffset = Calendar.getInstance().getTimeZone().getRawOffset() + Calendar.getInstance().getTimeZone().getDSTSavings();
tzOffset = Calendar.getInstance().getTimeZone().getRawOffset()
+ Calendar.getInstance().getTimeZone().getDSTSavings();
}

public void startElement(String uri, String name, String qName,
Expand All @@ -82,34 +83,39 @@ public void startElement(String uri, String name, String qName,
point.setLatitude(Double.parseDouble(atts.getValue("lat")));
point.setLongitude(Double.parseDouble(atts.getValue("lon")));
}
} else {
} else if (currentState == State.TRKPT) {
if ("extensions".equalsIgnoreCase(name)) {
currentState = State.EXTENSION;
}
}
if (buffer.length() > 0) {
buffer = new StringBuilder();
}
}

public void endElement(String uri, String name, String qName) {

if (currentState == State.TRKPT) {
if ("time".equalsIgnoreCase(name)) {
try {
String t = buffer.toString().trim();
if (t.length() == 20) {
// there are two different formats of time stamp
Date d = timestampFormatter.parse(t);
point.setTime(d.getTime()+tzOffset);
point.setTime(d.getTime() + tzOffset);
} else if (t.length() == 24) {
Date d = msdateFormat.parse(t);
point.setTime(d.getTime()+tzOffset);
point.setTime(d.getTime() + tzOffset);
}

} catch (ParseException e) {
logger.error(e + " " + buffer);
}
}
if ("ele".equalsIgnoreCase(name)) {
} else if ("ele".equalsIgnoreCase(name)) {
point.setElevation(gAve.add(Double.parseDouble(buffer
.toString())));

} else if ("trkpt".equalsIgnoreCase(name)) {

index++;
int current = data.size();
if (current > 0) {
Expand Down Expand Up @@ -173,6 +179,19 @@ public void endElement(String uri, String name, String qName) {
data.add(point);
currentState = State.UNDEFINED;
}
} else if (currentState == State.EXTENSION) {
// System.out.println(name);
if ("extensions".equalsIgnoreCase(name)) {
currentState = State.TRKPT;
} else if ("atemp".equalsIgnoreCase(name)) {
System.out.println("temp " + buffer);
} else if ("hr".equalsIgnoreCase(name)) {
point.setHeartRate(Integer.parseInt(buffer
.toString()));
} else if ("cad".equalsIgnoreCase(name)) {
point.setCadence(Integer.parseInt(buffer
.toString()));
}
}
}

Expand All @@ -184,6 +203,6 @@ public void characters(char ch[], int start, int length) {
}

public enum State {
TRKPT, UNDEFINED
TRKPT, EXTENSION, UNDEFINED
}
}

0 comments on commit 18f418e

Please sign in to comment.