Search in sources :

Example 76 with Card

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

the class CardDaoImpl method getRandomReviewedCards.

public List<Card> getRandomReviewedCards(Category filterCategory, int limit) {
    try {
        LearningDataDao learningDataDao = getHelper().getLearningDataDao();
        QueryBuilder<LearningData, Integer> learnQb = learningDataDao.queryBuilder();
        learnQb.selectColumns("id");
        learnQb.where().gt("acqReps", "0");
        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);
    }
}
Also used : SQLException(java.sql.SQLException) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 77 with Card

use of org.liberty.android.fantastischmemo.entity.Card 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);
    }
}
Also used : SQLException(java.sql.SQLException) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 78 with Card

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

the class CardDaoImpl method searchPrevCard.

@SuppressWarnings("unchecked")
public Card searchPrevCard(String criteria, int ordinal) {
    QueryBuilder<Card, Integer> qb = queryBuilder();
    try {
        Where<Card, Integer> where = qb.where();
        where.and(where.lt("ordinal", ordinal), where.or(where.like("question", criteria), where.like("answer", criteria), where.like("note", criteria)));
        qb.setWhere(where);
        qb.orderBy("ordinal", false);
        PreparedQuery<Card> pq = qb.prepare();
        Card nc = queryForFirst(pq);
        return nc;
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 79 with Card

use of org.liberty.android.fantastischmemo.entity.Card 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);
    }
}
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 80 with Card

use of org.liberty.android.fantastischmemo.entity.Card 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);
    }
}
Also used : SQLException(java.sql.SQLException) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) Card(org.liberty.android.fantastischmemo.entity.Card)

Aggregations

Card (org.liberty.android.fantastischmemo.entity.Card)95 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)61 SmallTest (android.support.test.filters.SmallTest)43 Test (org.junit.Test)43 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)41 Category (org.liberty.android.fantastischmemo.entity.Category)30 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)28 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)25 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)20 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)13 File (java.io.File)12 ArrayList (java.util.ArrayList)11 SQLException (java.sql.SQLException)9 QueueManager (org.liberty.android.fantastischmemo.queue.QueueManager)9 IOException (java.io.IOException)6 Date (java.util.Date)6 LearnQueueManager (org.liberty.android.fantastischmemo.queue.LearnQueueManager)6 URL (java.net.URL)5 FileWriter (java.io.FileWriter)4 Scheduler (org.liberty.android.fantastischmemo.scheduler.Scheduler)4