1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-28 07:50:11 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java
cpfeiffer 7c597b325a Big refactoring: move classes and packages around to get a better structure
- model package contains mostly shared interfaces (UI+service), not named GB*
- impl package contains implementations of those interfaces, named GB*
  the impl classes should not be used by the service (not completely done)
- the service classes should mostly use classes inside the service and deviceevents
  packages (tbd)

Every device now has two packages:
- devices/[device name] for UI related functionality
- service[device name] for lowlevel communication
2015-08-03 23:09:49 +02:00

73 lines
2.7 KiB
Java

package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
public class ActivityAnalysis {
public ActivityAmounts calculateActivityAmounts(List<ActivitySample> samples) {
ActivityAmount deepSleep = new ActivityAmount(ActivityKind.TYPE_DEEP_SLEEP);
ActivityAmount lightSleep = new ActivityAmount(ActivityKind.TYPE_LIGHT_SLEEP);
ActivityAmount activity = new ActivityAmount(ActivityKind.TYPE_ACTIVITY);
ActivityAmount previousAmount = null;
ActivitySample previousSample = null;
for (ActivitySample sample : samples) {
ActivityAmount amount = null;
switch (sample.getKind()) {
case ActivityKind.TYPE_DEEP_SLEEP:
amount = deepSleep;
break;
case ActivityKind.TYPE_LIGHT_SLEEP:
amount = lightSleep;
break;
case ActivityKind.TYPE_ACTIVITY:
default:
amount = activity;
break;
}
if (previousSample != null) {
long timeDifference = sample.getTimestamp() - previousSample.getTimestamp();
if (previousSample.getRawKind() == sample.getRawKind()) {
amount.addSeconds(timeDifference);
} else {
long sharedTimeDifference = (long) (timeDifference / 2.0f);
previousAmount.addSeconds(sharedTimeDifference);
amount.addSeconds(sharedTimeDifference);
}
} else {
// nothing to do, we can only calculate when we have the next sample
}
previousAmount = amount;
previousSample = sample;
}
ActivityAmounts result = new ActivityAmounts();
if (deepSleep.getTotalSeconds() > 0) {
result.addAmount(deepSleep);
}
if (lightSleep.getTotalSeconds() > 0) {
result.addAmount(lightSleep);
}
if (activity.getTotalSeconds() > 0) {
result.addAmount(activity);
}
result.calculatePercentages();
return result;
}
public int calculateTotalSteps(List<ActivitySample> samples) {
int totalSteps = 0;
for (ActivitySample sample : samples) {
totalSteps += sample.getSteps();
}
return totalSteps;
}
}