use of de.opendiabetes.vault.plugin.importer.googlecrawler.models.HeartRate in project BachelorPraktikum by lucasbuschlinger.
the class GoogleFitness method fetchHeartRatePerDay.
/**
* Fetches the heart rate at a specific day.
* @param day - a date as unix timestamp
*/
private void fetchHeartRatePerDay(final long day) {
long[] startEnd = getStartEndDay(day);
AggregateBy aggregate = new AggregateBy();
aggregate.setDataTypeName("com.google.heart_rate.bpm");
AggregateRequest aggregateRequest = new AggregateRequest();
aggregateRequest.setStartTimeMillis(startEnd[0]);
aggregateRequest.setEndTimeMillis(startEnd[1]);
aggregateRequest.setAggregateBy(Arrays.asList(aggregate));
try {
Fitness.Users.Dataset.Aggregate request = fitnessService.users().dataset().aggregate("me", aggregateRequest);
AggregateResponse rep = request.execute();
if (rep.getBucket().get(0).getDataset().get(0).getPoint().size() != 0) {
List<DataPoint> activitiesByDataSource = rep.getBucket().get(0).getDataset().get(0).getPoint();
List<HeartRate> heartRates = new ArrayList<>();
for (DataPoint dp : activitiesByDataSource) {
heartRates.add(new HeartRate(dp.getStartTimeNanos() / NANO_TO_MILLISECONDS_DIVISOR, dp.getValue().get(0).getIntVal()));
}
LocationHistory.getInstance().addHeartRates(startEnd[0], heartRates);
}
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations