Search in sources :

Example 26 with LearningData

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

the class CardDaoTest method testReviewCardsOrderOfAllDifferentEasiness.

@SmallTest
@Test
public void testReviewCardsOrderOfAllDifferentEasiness() throws SQLException {
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    setupThreeCategories();
    Card c2 = cardDao.queryForId(2);
    Card c5 = cardDao.queryForId(5);
    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.6);
    learningDataDao.update(c14Ld);
    learningDataDao.refresh(c15.getLearningData());
    LearningData c15Ld = c15.getLearningData();
    c15Ld.setAcqReps(1);
    c15Ld.setNextLearnDate(testDate);
    c15Ld.setEasiness((float) 2.8);
    learningDataDao.update(c15Ld);
    learningDataDao.refresh(c2.getLearningData());
    LearningData c2Ld = c2.getLearningData();
    c2Ld.setAcqReps(1);
    c2Ld.setNextLearnDate(testDate);
    c2Ld.setEasiness((float) 3.0);
    learningDataDao.update(c2Ld);
    learningDataDao.refresh(c5.getLearningData());
    LearningData c5Ld = c5.getLearningData();
    c5Ld.setAcqReps(1);
    c5Ld.setNextLearnDate(testDate);
    c5Ld.setEasiness((float) 2.9);
    learningDataDao.update(c5Ld);
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    List<Card> cards = cardDao.getCardsForReview(ct, null, 50, ReviewOrdering.HardestFirst);
    assertEquals(2, cards.size());
    assertEquals(5, (int) cards.get(0).getOrdinal());
    assertEquals(2, (int) cards.get(1).getOrdinal());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) 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 27 with LearningData

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

the class CardDaoTest method testCreateCard.

@SmallTest
@Test
public void testCreateCard() throws Exception {
    CardDao cardDao = helper.getCardDao();
    Card c = new Card();
    c.setCategory(new Category());
    c.setLearningData(new LearningData());
    cardDao.createCard(c);
    // Should create a new card
    assertEquals(29, cardDao.countOf());
    // The new card's id and ordinal should be correct
    assertEquals(29, (int) c.getId());
    assertEquals(29, (int) c.getOrdinal());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) 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 28 with LearningData

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

the class LearnQueuingManagerTest method updateFailureCardLearningData.

private void updateFailureCardLearningData(Card card) {
    LearningData ld = card.getLearningData();
    ld.setAcqReps(1);
    // Make sure to review
    ld.setNextLearnDate(new Date(new Date().getTime() - 1));
    ld.setGrade(0);
}
Also used : LearningData(org.liberty.android.fantastischmemo.entity.LearningData) Date(java.util.Date)

Example 29 with LearningData

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

the class DefaultSchedulerTest method testScheduleLearnedCardSuccess.

@SmallTest
@Test
public void testScheduleLearnedCardSuccess() {
    LearningData newLd = defaultScheduler.schedule(learnedCardLearningData, 5, false);
    assertFalse(defaultScheduler.isCardForReview(newLd));
    assertFalse(defaultScheduler.isCardNew(newLd));
    assertTrue(defaultScheduler.isCardLearned(newLd));
}
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 30 with LearningData

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

the class CSVImporter method convert.

public void convert(String src, String dest) throws Exception {
    if (!new File(dest).exists()) {
        amFileUtil.createDbFileWithDefaultSettings(new File(dest));
    }
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(dest);
    CSVReader reader;
    if (separator == null) {
        reader = new CSVReader(new FileReader(src));
    } else {
        reader = new CSVReader(new FileReader(src), separator);
    }
    try {
        final CardDao cardDao = helper.getCardDao();
        String[] nextLine;
        final List<Card> cardList = new LinkedList<Card>();
        while ((nextLine = reader.readNext()) != null) {
            if (nextLine.length < 2) {
                throw new Exception("Malformed CSV file. Please make sure the CSV's first column is question, second one is answer and the optinal third one is category");
            }
            String note = "";
            String category = "";
            if (nextLine.length >= 3) {
                category = nextLine[2];
            }
            if (nextLine.length >= 4) {
                note = nextLine[3];
            }
            Card card = new Card();
            Category cat = new Category();
            LearningData ld = new LearningData();
            cat.setName(category);
            card.setCategory(cat);
            card.setLearningData(ld);
            card.setQuestion(nextLine[0]);
            card.setAnswer(nextLine[1]);
            card.setNote(note);
            cardList.add(card);
        }
        cardDao.createCards(cardList);
    } finally {
        AnyMemoDBOpenHelperManager.releaseHelper(helper);
        reader.close();
    }
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CSVReader(com.opencsv.CSVReader) LinkedList(java.util.LinkedList) Card(org.liberty.android.fantastischmemo.entity.Card) AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) FileReader(java.io.FileReader) File(java.io.File) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) CardDao(org.liberty.android.fantastischmemo.dao.CardDao)

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