use of nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription in project Gadgetbridge by Freeyourgadget.
the class EntitiesTest method testActivityDescription.
@Test
public void testActivityDescription() {
User user = DBHelper.getUser(daoSession);
assertNotNull(user);
ActivityDescriptionDao descDao = daoSession.getActivityDescriptionDao();
assertEquals(0, descDao.count());
List<ActivityDescription> list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertTrue(list.isEmpty());
ActivityDescription desc = DBHelper.createActivityDescription(user, 10, 100, daoSession);
assertNotNull(desc);
assertEquals(user, desc.getUser());
assertEquals(10, desc.getTimestampFrom());
assertEquals(100, desc.getTimestampTo());
List<Tag> tagList = desc.getTagList();
assertEquals(0, tagList.size());
Tag t1 = DBHelper.getTag(user, "Table Tennis", daoSession);
assertNotNull(t1);
assertEquals("Table Tennis", t1.getName());
t1.setDescription("Table tennis training for Olympia");
tagList.add(t1);
list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertEquals(1, list.size());
ActivityDescription desc1 = list.get(0);
assertEquals(desc, desc1);
assertEquals(1, desc1.getTagList().size());
// check for partial range overlaps
list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
assertEquals(1, list.size());
// Now with a second, adjacent ActivityDescription
ActivityDescription desc2 = DBHelper.createActivityDescription(user, 101, 200, daoSession);
list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
assertEquals(1, list.size());
// Now with a third, partially overlapping ActivityDescription
ActivityDescription desc3 = DBHelper.createActivityDescription(user, 5, 15, daoSession);
list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
assertEquals(3, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
assertEquals(2, list.size());
}
use of nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription in project Gadgetbridge by Freeyourgadget.
the class DBHelper method findActivityDecriptions.
@NonNull
public static List<ActivityDescription> findActivityDecriptions(@NonNull User user, int tsFrom, int tsTo, @NonNull DaoSession session) {
Property tsFromProperty = ActivityDescriptionDao.Properties.TimestampFrom;
Property tsToProperty = ActivityDescriptionDao.Properties.TimestampTo;
Property userIdProperty = ActivityDescriptionDao.Properties.UserId;
QueryBuilder<ActivityDescription> qb = session.getActivityDescriptionDao().queryBuilder();
qb.where(userIdProperty.eq(user.getId()), isAtLeastPartiallyInRange(qb, tsFromProperty, tsToProperty, tsFrom, tsTo));
List<ActivityDescription> descriptions = qb.build().list();
return descriptions;
}
use of nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription in project Gadgetbridge by Freeyourgadget.
the class DBHelper method createActivityDescription.
@NonNull
public static ActivityDescription createActivityDescription(@NonNull User user, int tsFrom, int tsTo, @NonNull DaoSession session) {
ActivityDescription desc = new ActivityDescription();
desc.setUser(user);
desc.setTimestampFrom(tsFrom);
desc.setTimestampTo(tsTo);
session.getActivityDescriptionDao().insertOrReplace(desc);
return desc;
}
Aggregations