@Override public void storeTelemetryData(Telemetry t) { boolean pause = true; double powerWatts = 0.0; if (t.isAvailable(SourceDataEnum.ROUTE_SPEED)) { // for trainings with video speed. These are only video trainigs with // slope (or even with positions) pause = false; // smooth route speed a bit, in GPX speed is calculated on distance // and might be very jumpy. double routeSpeed; if (t.getRouteSpeed() >= 1.0) { routeSpeed = speedRoll.add(t.getRouteSpeed()); } else { routeSpeed = speedRoll.getAverage(); } powerWatts = Power.getPower(weight, t.getGradient() / 100.0, routeSpeed); } else if (t.isAvailable(SourceDataEnum.TARGET_POWER)) { // in TRN mode.. current power equals target power, and speed is // calculated on power pause = false; powerWatts = t.getDouble(SourceDataEnum.TARGET_POWER); } else { // route without video or free run.. Another profile must be taken. // In fact if power is taken from sensor, speed doesn't have to be // valid and training is paused without a reason.. } setPause(pause ? PauseMsgEnum.NO_MOVEMENT : PauseMsgEnum.RUNNING); setValue(SourceDataEnum.POWER, powerWatts); }
public FitImporter(String fileName) { FileInputStream fitFile = null; try { Decode decode = new Decode(); MesgBroadcaster broadcaster = new MesgBroadcaster(decode); decode.addListener((MesgDefinitionListener) this); decode.addListener((MesgListener) this); fitFile = new FileInputStream(fileName); broadcaster.run(fitFile); // calculate powers here??? if (!isPower) { for (Telemetry point : data) { int p = (int) Power.getPower(userPrefs.getTotalWeight(), point.getGradient(), point.getSpeed()); if (p > userPrefs.getMaxPower() && (p > (last.getPower() * 2.0))) { // We are above FTP and power has doubled, remove power // spikes p = (int) (last.getPower() * 1.05); } if (p > (userPrefs.getMaxPower() * 4)) { // power is 4 x FTP, this is a spike p = last.getPower(); } if (p > 0) { point.setPower(p); } else { point.setPower(0); } } // for } } catch (Exception fex) { try { fitFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } fex.printStackTrace(); } finally { if (fitFile != null) { try { fitFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }