use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class GPXExporterTest method readActivityPoints.
private List<ActivityPoint> readActivityPoints(String resourcePath) throws IOException, ParseException {
final List<ActivityPoint> points = new ArrayList<>();
try (final InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String nextLine = reader.readLine();
while (nextLine != null) {
final String[] pieces = nextLine.split("\\s+");
final ActivityPoint point = new ActivityPoint();
point.setLocation(new GPSCoordinate(Double.parseDouble(pieces[0]), Double.parseDouble(pieces[1]), Double.parseDouble(pieces[2])));
final int dateIndex;
if (pieces.length == 5) {
point.setHeartRate(Integer.parseInt(pieces[3]));
dateIndex = 4;
} else {
dateIndex = 3;
}
// Not sure about this parser but seemed safe to use
point.setTime(ISO8601Utils.parse(pieces[dateIndex], new ParsePosition(0)));
points.add(point);
nextLine = reader.readLine();
}
}
}
return points;
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class HuamiActivityDetailsParser method consumeHeartRate.
private int consumeHeartRate(byte[] bytes, int offset, long timeOffsetSeconds) {
int v1 = BLETypeConversions.toUint16(bytes[offset]);
int v2 = BLETypeConversions.toUint16(bytes[offset + 1]);
int v3 = BLETypeConversions.toUint16(bytes[offset + 2]);
int v4 = BLETypeConversions.toUint16(bytes[offset + 3]);
int v5 = BLETypeConversions.toUint16(bytes[offset + 4]);
int v6 = BLETypeConversions.toUint16(bytes[offset + 5]);
if (v2 == 0 && v3 == 0 && v4 == 0 && v5 == 0 && v6 == 0) {
// new version
LOG.info("detected heart rate in 'new' version format");
ActivityPoint ap = getActivityPointFor(timeOffsetSeconds);
ap.setHeartRate(v1);
add(ap);
} else {
ActivityPoint ap = getActivityPointFor(v1);
ap.setHeartRate(v2);
add(ap);
ap = getActivityPointFor(v3);
ap.setHeartRate(v4);
add(ap);
ap = getActivityPointFor(v5);
ap.setHeartRate(v6);
add(ap);
}
return 6;
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class HuamiActivityDetailsParser method fixupMissingTimestamps.
private void fixupMissingTimestamps(ActivityTrack activityTrack) {
try {
int pointer = 0;
List<ActivityPoint> activityPointList = activityTrack.getTrackPoints();
Date gpsStartTime = null;
List<ActivityPoint> entriesToFixUp = new ArrayList<>();
while (pointer < activityPointList.size() - 1) {
ActivityPoint activityPoint = activityPointList.get(pointer);
if (activityPoint.getLocation() == null) {
pointer++;
continue;
}
if (activityPoint.getTime().equals(activityPointList.get(pointer + 1).getTime())) {
entriesToFixUp.add(activityPoint);
} else {
// found the first activity point with a proper timestamp
entriesToFixUp.add(activityPoint);
gpsStartTime = activityPointList.get(pointer + 1).getTime();
break;
}
pointer++;
}
if (gpsStartTime != null) {
// now adjust those entries without a timestamp
long differenceInSec = TimeUnit.SECONDS.convert(Math.abs(gpsStartTime.getTime() - baseDate.getTime()), TimeUnit.MILLISECONDS);
double multiplier = (double) differenceInSec / (double) (entriesToFixUp.size());
for (int j = 0; j < entriesToFixUp.size(); j++) {
long timeOffsetSeconds = Math.round(j * multiplier);
entriesToFixUp.get(j).setTime(makeAbsolute(timeOffsetSeconds));
}
}
} catch (Exception ex) {
LOG.warn("Error cleaning activity details", ex);
}
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class GPXExporterTest method createTestTrack.
private ActivityTrack createTestTrack(List<ActivityPoint> points) {
final User user = new User();
user.setName("Test User");
Device device = new Device();
device.setName("Test Device");
final ActivityTrack track = new ActivityTrack();
track.setName("Test Track");
track.setBaseTime(new Date());
track.setUser(user);
track.setDevice(device);
for (final ActivityPoint point : points) {
track.addTrackPoint(point);
}
return track;
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class GPXExporterTest method shouldCreateValidGpxFromSimulatedDataWithHeartrate.
@Test
public void shouldCreateValidGpxFromSimulatedDataWithHeartrate() throws IOException, ParseException, GPXTrackEmptyException, ParserConfigurationException, SAXException {
final List<ActivityPoint> points = readActivityPoints("/GPXExporterTest-SampleTracksHR.csv");
final GPXExporter gpxExporter = new GPXExporter();
gpxExporter.setCreator("Gadgetbridge Test");
final ActivityTrack track = createTestTrack(points);
final File tempFile = File.createTempFile("gpx-exporter-test-track", ".gpx");
tempFile.deleteOnExit();
gpxExporter.performExport(track, tempFile);
validateGpxFile(tempFile);
}
Aggregations