use of nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample in project Gadgetbridge by Freeyourgadget.
the class MiBand2Support method createActivitySample.
public MiBandActivitySample createActivitySample(Device device, User user, int timestampInSeconds, SampleProvider provider) {
MiBandActivitySample sample = new MiBandActivitySample();
sample.setDevice(device);
sample.setUser(user);
sample.setTimestamp(timestampInSeconds);
sample.setProvider(provider);
return sample;
}
use of nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample in project Gadgetbridge by Freeyourgadget.
the class FetchActivityOperation method createSample.
private MiBandActivitySample createSample(byte category, byte intensity, byte steps, byte heartrate) {
MiBandActivitySample sample = new MiBandActivitySample();
sample.setRawKind(category & 0xff);
sample.setRawIntensity(intensity & 0xff);
sample.setSteps(steps & 0xff);
sample.setHeartRate(heartrate & 0xff);
return sample;
}
use of nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample in project Gadgetbridge by Freeyourgadget.
the class FetchActivityOperation method saveSamples.
private void saveSamples() {
if (samples.size() > 0) {
// save all the samples that we got
try (DBHandler handler = GBApplication.acquireDB()) {
DaoSession session = handler.getDaoSession();
SampleProvider<MiBandActivitySample> sampleProvider = new MiBandSampleProvider(getDevice(), session);
Device device = DBHelper.getDevice(getDevice(), session);
User user = DBHelper.getUser(session);
GregorianCalendar timestamp = (GregorianCalendar) startTimestamp.clone();
for (MiBandActivitySample sample : samples) {
sample.setDevice(device);
sample.setUser(user);
sample.setTimestamp((int) (timestamp.getTimeInMillis() / 1000));
sample.setProvider(sampleProvider);
if (LOG.isDebugEnabled()) {
// LOG.debug("sample: " + sample);
}
timestamp.add(Calendar.MINUTE, 1);
}
sampleProvider.addGBActivitySamples(samples.toArray(new MiBandActivitySample[0]));
saveLastSyncTimestamp(timestamp);
LOG.info("Mi2 activity data: last sample timestamp: " + DateTimeUtils.formatDateTime(timestamp.getTime()));
} catch (Exception ex) {
GB.toast(getContext(), "Error saving activity samples", Toast.LENGTH_LONG, GB.ERROR);
} finally {
samples.clear();
}
}
}
use of nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample in project Gadgetbridge by Freeyourgadget.
the class SampleProviderTest method testNoSamples.
@Test
public void testNoSamples() {
MiBandSampleProvider sampleProvider = new MiBandSampleProvider(dummyGBDevice, daoSession);
List<MiBandActivitySample> samples = sampleProvider.getAllActivitySamples(0, 0);
assertEquals(0, samples.size());
samples = sampleProvider.getAllActivitySamples(-1, 1);
assertEquals(0, samples.size());
samples = sampleProvider.getAllActivitySamples(1, -1);
assertEquals(0, samples.size());
// now specific activity kinds
samples = sampleProvider.getActivitySamples(0, 0);
assertEquals(0, samples.size());
samples = sampleProvider.getActivitySamples(-1, 1);
assertEquals(0, samples.size());
samples = sampleProvider.getActivitySamples(1, -1);
assertEquals(0, samples.size());
// and sleep
samples = sampleProvider.getSleepSamples(0, 0);
assertEquals(0, samples.size());
samples = sampleProvider.getSleepSamples(-1, 1);
assertEquals(0, samples.size());
samples = sampleProvider.getSleepSamples(1, -1);
assertEquals(0, samples.size());
}
use of nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample in project Gadgetbridge by Freeyourgadget.
the class SampleProviderTest method testSamples.
@Test
public void testSamples() {
MiBandSampleProvider sampleProvider = new MiBandSampleProvider(dummyGBDevice, daoSession);
User user = DBHelper.getUser(daoSession);
assertNotNull(user);
assertNotNull(user.getId());
Device device = DBHelper.getDevice(dummyGBDevice, daoSession);
assertNotNull(device);
MiBandActivitySample s1 = createSample(sampleProvider, MiBandSampleProvider.TYPE_ACTIVITY, 100, 10, 70, 1000, user, device);
sampleProvider.addGBActivitySample(s1);
// add again, should not throw or fail
sampleProvider.addGBActivitySample(s1);
MiBandActivitySample s2 = createSample(sampleProvider, MiBandSampleProvider.TYPE_ACTIVITY, 200, 20, 80, 1030, user, device);
sampleProvider.addGBActivitySample(s2);
MiBandActivitySample s3 = createSample(sampleProvider, MiBandSampleProvider.TYPE_DEEP_SLEEP, 1200, 10, 62, 4030, user, device);
MiBandActivitySample s4 = createSample(sampleProvider, MiBandSampleProvider.TYPE_LIGHT_SLEEP, 2000, 10, 60, 4030, user, device);
sampleProvider.addGBActivitySamples(new MiBandActivitySample[] { s3, s4 });
// first checks for irrelevant timestamps => no samples
List<MiBandActivitySample> samples = sampleProvider.getAllActivitySamples(0, 0);
assertEquals(0, samples.size());
samples = sampleProvider.getAllActivitySamples(-1, 1);
assertEquals(0, samples.size());
samples = sampleProvider.getAllActivitySamples(1, -1);
assertEquals(0, samples.size());
// now specific activity kinds
samples = sampleProvider.getActivitySamples(0, 0);
assertEquals(0, samples.size());
samples = sampleProvider.getActivitySamples(-1, 1);
assertEquals(0, samples.size());
samples = sampleProvider.getActivitySamples(1, -1);
assertEquals(0, samples.size());
// and sleep
samples = sampleProvider.getSleepSamples(0, 0);
assertEquals(0, samples.size());
samples = sampleProvider.getSleepSamples(-1, 1);
assertEquals(0, samples.size());
samples = sampleProvider.getSleepSamples(1, -1);
assertEquals(0, samples.size());
// finally checks for existing timestamps
List<MiBandActivitySample> allSamples = sampleProvider.getAllActivitySamples(0, 10000);
assertEquals(4, allSamples.size());
List<MiBandActivitySample> activitySamples = sampleProvider.getActivitySamples(0, 10000);
assertEquals(2, activitySamples.size());
List<MiBandActivitySample> sleepSamples = sampleProvider.getSleepSamples(0, 10000);
assertEquals(2, sleepSamples.size());
// now with more strict time ranges
allSamples = sampleProvider.getAllActivitySamples(0, 1300);
assertEquals(3, allSamples.size());
activitySamples = sampleProvider.getActivitySamples(10, 150);
assertEquals(1, activitySamples.size());
sleepSamples = sampleProvider.getSleepSamples(1500, 2500);
assertEquals(1, sleepSamples.size());
}
Aggregations