use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.
the class CardDaoImpl method getRandomCards.
public List<Card> getRandomCards(Category filterCategory, int limit) {
try {
LearningDataDao learningDataDao = getHelper().getLearningDataDao();
QueryBuilder<LearningData, Integer> learnQb = learningDataDao.queryBuilder();
learnQb.selectColumns("id");
QueryBuilder<Card, Integer> cardQb = this.queryBuilder();
Where<Card, Integer> where = cardQb.where().in("learningData_id", learnQb);
if (filterCategory != null) {
where.and().eq("category_id", filterCategory.getId());
}
cardQb.setWhere(where);
// Return random ordered cards
cardQb.orderByRaw("random()");
cardQb.limit((long) limit);
List<Card> cs = cardQb.query();
for (Card c : cs) {
learningDataDao.refresh(c.getLearningData());
}
return cs;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.
the class CardDaoImpl method getCardsForReview.
public List<Card> getCardsForReview(Category filterCategory, Iterable<Card> exclusion, int limit, ReviewOrdering reviewOrdering) {
try {
LearningDataDao learningDataDao = getHelper().getLearningDataDao();
CategoryDao categoryDao = getHelper().getCategoryDao();
QueryBuilder<LearningData, Integer> learnQb = learningDataDao.queryBuilder();
learnQb.selectColumns("id");
learnQb.where().le("nextLearnDate", Calendar.getInstance().getTime()).and().gt("acqReps", "0");
QueryBuilder<Card, Integer> cardQb = this.queryBuilder();
// The "isNotNull" statement is dummy so the "and()" can be cascaded
// for the following conditions
Where<Card, Integer> where = cardQb.where().isNotNull("learningData_id");
if (filterCategory != null) {
where.and().eq("category_id", filterCategory.getId());
}
if (exclusion != null) {
List<Integer> exclusionList = new ArrayList<Integer>();
for (Card c : exclusion) {
exclusionList.add(c.getId());
}
where.and().notIn("id", exclusionList);
}
cardQb.setWhere(where);
// Order by easiness so the hard cards (smaller easiness) will be reviewed first.
String orderByClause = "learning_data.easiness, cards.ordinal";
// If randomized, it is order by random
if (reviewOrdering == ReviewOrdering.Random) {
orderByClause = "random()";
}
cardQb.join(learnQb).orderByRaw(orderByClause).limit((long) limit);
List<Card> cs = cardQb.query();
for (Card c : cs) {
categoryDao.refresh(c.getCategory());
learningDataDao.refresh(c.getLearningData());
}
return cs;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.
the class CardDaoImpl method getCardsByCategory.
public List<Card> getCardsByCategory(Category filterCategory, boolean random, int limit) {
try {
LearningDataDao learningDataDao = getHelper().getLearningDataDao();
QueryBuilder<LearningData, Integer> learnQb = learningDataDao.queryBuilder();
learnQb.selectColumns("id");
QueryBuilder<Card, Integer> cardQb = this.queryBuilder();
Where<Card, Integer> where = cardQb.where().in("learningData_id", learnQb);
if (filterCategory != null) {
where.and().eq("category_id", filterCategory.getId());
}
cardQb.setWhere(where);
// Return random ordered cards
if (random) {
cardQb.orderByRaw("random()");
}
cardQb.limit((long) limit);
List<Card> cs = cardQb.query();
for (Card c : cs) {
learningDataDao.refresh(c.getLearningData());
}
return cs;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.
the class CardDaoTest method testReviewCardsOrderOfSameEasiness.
@SmallTest
@Test
public void testReviewCardsOrderOfSameEasiness() throws SQLException {
CardDao cardDao = helper.getCardDao();
Card c13 = cardDao.queryForId(13);
Card c14 = cardDao.queryForId(14);
Card c15 = cardDao.queryForId(15);
LearningDataDao learningDataDao = helper.getLearningDataDao();
Date testDate = new Date((new Date().getTime() - 1));
learningDataDao.refresh(c13.getLearningData());
LearningData c13Ld = c13.getLearningData();
c13Ld.setAcqReps(1);
c13Ld.setNextLearnDate(testDate);
c13Ld.setEasiness((float) 2.7);
learningDataDao.update(c13Ld);
learningDataDao.refresh(c14.getLearningData());
LearningData c14Ld = c14.getLearningData();
c14Ld.setAcqReps(1);
c14Ld.setNextLearnDate(testDate);
c14Ld.setEasiness((float) 2.7);
learningDataDao.update(c14Ld);
learningDataDao.refresh(c15.getLearningData());
LearningData c15Ld = c15.getLearningData();
c15Ld.setAcqReps(1);
c15Ld.setNextLearnDate(testDate);
c15Ld.setEasiness((float) 2.7);
learningDataDao.update(c15Ld);
List<Card> cards = cardDao.getCardsForReview(null, null, 50, ReviewOrdering.HardestFirst);
assertEquals(3, cards.size());
assertEquals(13, (int) cards.get(0).getOrdinal());
assertEquals(14, (int) cards.get(1).getOrdinal());
assertEquals(15, (int) cards.get(2).getOrdinal());
}
use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.
the class CardListActivity method markAsLearned.
private void markAsLearned(Card card) {
LearningData newLd = scheduler.schedule(card.getLearningData(), 5, schedulingAlgorithmParameters.getEnableNoise());
dbOpenHelper.getLearningDataDao().updateLearningData(newLd);
card.setLearningData(newLd);
cardListAdapter.notifyDataSetChanged();
}
Aggregations