use of com.google.api.services.fitness.model.DataPoint in project BachelorPraktikum by lucasbuschlinger.
the class GoogleFitness method fetchActivitiesPerDay.
/**
* Fetches all activities at a specific day.
* @param day - a date as unix timestamp
*/
private void fetchActivitiesPerDay(final long day) {
long[] startEnd = getStartEndDay(day);
AggregateBy aggregate = new AggregateBy();
aggregate.setDataTypeName("com.google.activity.segment");
AggregateRequest agg = new AggregateRequest();
agg.setStartTimeMillis(startEnd[0]);
agg.setEndTimeMillis(startEnd[1]);
agg.setAggregateBy(Arrays.asList(aggregate));
try {
Fitness.Users.Dataset.Aggregate request = fitnessService.users().dataset().aggregate("me", agg);
AggregateResponse rep = request.execute();
List<DataPoint> activitiesByDataSource = rep.getBucket().get(0).getDataset().get(0).getPoint();
List<Activity> activities = new ArrayList<>();
for (DataPoint dp : activitiesByDataSource) {
activities.add(new Activity(dp.getStartTimeNanos() / NANO_TO_MILLISECONDS_DIVISOR, dp.getEndTimeNanos() / NANO_TO_MILLISECONDS_DIVISOR, dp.getValue().get(0).getIntVal()));
}
for (int i = 0; i < activities.size() - 1; i++) {
Activity currentActivity = activities.get(i);
Activity nextActivity = activities.get(i + 1);
if (currentActivity.getActivityId() == nextActivity.getActivityId() && currentActivity.getEndTime() - nextActivity.getStartTime() <= UNIX_TIME_FIVE_MINUTES) {
currentActivity.setEndTime(nextActivity.getEndTime());
activities.remove(i + 1);
}
}
LocationHistory.getInstance().addActivities(startEnd[0], activities);
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.google.api.services.fitness.model.DataPoint 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();
}
}
use of com.google.api.services.fitness.model.DataPoint in project BachelorPraktikum by lucasbuschlinger.
the class GoogleFitness method fetchLocationsPerDay.
/**
* Fetches all locations at a specific day.
* @param day - a date as unix timestamp
*/
private void fetchLocationsPerDay(final long day) {
long[] startEnd = getStartEndDay(day);
AggregateBy aggregate = new AggregateBy();
aggregate.setDataTypeName("com.google.location.sample");
AggregateRequest agg = new AggregateRequest();
agg.setStartTimeMillis(startEnd[0]);
agg.setEndTimeMillis(startEnd[1]);
agg.setAggregateBy(Arrays.asList(aggregate));
try {
Fitness.Users.Dataset.Aggregate request = fitnessService.users().dataset().aggregate("me", agg);
AggregateResponse rep = request.execute();
List<DataPoint> activitiesByDataSource = rep.getBucket().get(0).getDataset().get(0).getPoint();
List<Coordinate> locations = new ArrayList<>();
for (DataPoint dp : activitiesByDataSource) {
Coordinate coord = new Coordinate(dp.getStartTimeNanos() / NANO_TO_MILLISECONDS_DIVISOR, dp.getValue().get(1).getFpVal(), dp.getValue().get(0).getFpVal(), (int) Math.ceil(dp.getValue().get(2).getFpVal()));
if (dp.getValue().size() > 3) {
coord.setAltitude(dp.getValue().get(3).getFpVal().intValue());
}
locations.add(coord);
}
LocationHistory.getInstance().addLocations(startEnd[0], locations);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations