Search in sources :

Example 16 with LearningData

use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.

the class DefaultSchedulerTest method testScheduleNewCardFailure.

@SmallTest
@Test
public void testScheduleNewCardFailure() {
    LearningData newLd = defaultScheduler.schedule(newCardLearningData, 0, false);
    assertTrue(defaultScheduler.isCardForReview(newLd));
    assertFalse(defaultScheduler.isCardNew(newLd));
    assertFalse(defaultScheduler.isCardLearned(newLd));
    assertEquals(0, (int) newLd.getGrade());
}
Also used : LearningData(org.liberty.android.fantastischmemo.entity.LearningData) SmallTest(android.support.test.filters.SmallTest) AbstractPreferencesTest(org.liberty.android.fantastischmemo.test.AbstractPreferencesTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Example 17 with LearningData

use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.

the class CardDaoTest method testGetCardsForReviewExclusionList.

@SmallTest
@Test
public void testGetCardsForReviewExclusionList() {
    // Setup cards that is schedule for review
    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.8);
    learningDataDao.update(c13Ld);
    learningDataDao.refresh(c14.getLearningData());
    LearningData c14Ld = c14.getLearningData();
    c14Ld.setAcqReps(1);
    c14Ld.setNextLearnDate(testDate);
    c14Ld.setEasiness((float) 2.6);
    learningDataDao.update(c14Ld);
    learningDataDao.refresh(c15.getLearningData());
    LearningData c15Ld = c15.getLearningData();
    c15Ld.setAcqReps(1);
    c15Ld.setNextLearnDate(testDate);
    c15Ld.setEasiness((float) 2.6);
    learningDataDao.update(c15Ld);
    // Create exclusion list
    List<Card> exclusionList = new ArrayList<Card>();
    exclusionList.add(c13);
    exclusionList.add(c15);
    List<Card> cards = cardDao.getCardsForReview(null, exclusionList, 50, ReviewOrdering.HardestFirst);
    // Only card 14 is there
    assertEquals(1, cards.size());
    assertEquals(14, (int) cards.get(0).getId());
}
Also used : ArrayList(java.util.ArrayList) LearningDataDao(org.liberty.android.fantastischmemo.dao.LearningDataDao) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Date(java.util.Date) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 18 with LearningData

use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.

the class CardDaoImpl method getNewCards.

public List<Card> getNewCards(Category filterCategory, Iterable<Card> exclusion, int limit) {
    try {
        LearningDataDao learningDataDao = getHelper().getLearningDataDao();
        CategoryDao categoryDao = getHelper().getCategoryDao();
        QueryBuilder<LearningData, Integer> learnQb = learningDataDao.queryBuilder();
        learnQb.selectColumns("id");
        learnQb.where().eq("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);
        cardQb.join(learnQb).orderByRaw("cards.ordinal").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);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Card(org.liberty.android.fantastischmemo.entity.Card) LearningData(org.liberty.android.fantastischmemo.entity.LearningData)

Example 19 with LearningData

use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.

the class LearningDataDaoImpl method resetLearningData.

public void resetLearningData(LearningData ld) {
    ld.cloneFromLearningData(new LearningData());
    update(ld);
}
Also used : LearningData(org.liberty.android.fantastischmemo.entity.LearningData)

Example 20 with LearningData

use of org.liberty.android.fantastischmemo.entity.LearningData in project AnyMemo by helloworld1.

the class CardListActivity method markAsForgotten.

private void markAsForgotten(Card card) {
    LearningData newLd = scheduler.schedule(card.getLearningData(), 1, schedulingAlgorithmParameters.getEnableNoise());
    dbOpenHelper.getLearningDataDao().updateLearningData(newLd);
    card.setLearningData(newLd);
    cardListAdapter.notifyDataSetChanged();
}
Also used : LearningData(org.liberty.android.fantastischmemo.entity.LearningData)

Aggregations

LearningData (org.liberty.android.fantastischmemo.entity.LearningData)42 Card (org.liberty.android.fantastischmemo.entity.Card)25 SmallTest (android.support.test.filters.SmallTest)15 Test (org.junit.Test)15 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)15 Category (org.liberty.android.fantastischmemo.entity.Category)15 Date (java.util.Date)11 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)9 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)8 AbstractPreferencesTest (org.liberty.android.fantastischmemo.test.AbstractPreferencesTest)8 ArrayList (java.util.ArrayList)7 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)7 SQLException (java.sql.SQLException)5 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)5 File (java.io.File)4 IOException (java.io.IOException)3 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 FileReader (java.io.FileReader)2 FileWriter (java.io.FileWriter)2