Search in sources :

Example 41 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class DeckAdapter method processNodes.

private void processNodes(List<AbstractDeckTreeNode> nodes) {
    for (AbstractDeckTreeNode node : nodes) {
        // We don't hide it if it's the only deck or if it has sub-decks.
        if (node.getFullDeckName().contains("::")) {
            // 只添加一级节点
            continue;
        }
        if (node.getDid() == 1 && nodes.size() > 1 && !node.hasChildren()) {
            if (mCol.getDb().queryScalar("select 1 from cards where did = 1") == 0) {
                continue;
            }
        }
        // If any of this node's parents are collapsed, don't add it to the deck list
        for (Deck parent : mCol.getDecks().parents(node.getDid())) {
            // If a deck has a parent it means it's a subdeck so set a flag
            mHasSubdecks = true;
            if (parent.optBoolean("collapsed")) {
                return;
            }
        }
        mDeckList.add(node);
        // Add this node's counts to the totals if it's a parent deck
        if (node.getDepth() == 0) {
            if (node.shouldDisplayCounts()) {
                mNew += node.getNewCount();
                mRev += node.getLrnCount();
                mRev += node.getRevCount();
            }
        }
        // Process sub-decks
        if (node.getChildren() != null)
            processNodes(node.getChildren());
    }
}
Also used : Deck(com.ichi2.libanki.Deck) AbstractDeckTreeNode(com.ichi2.libanki.sched.AbstractDeckTreeNode)

Example 42 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class DeckInfoListAdapter method processNodes.

private void processNodes(List<AbstractDeckTreeNode> nodes) {
    for (AbstractDeckTreeNode node : nodes) {
        Timber.i("节点审核:%s", node.getFullDeckName());
        // We don't hide it if it's the only deck or if it has sub-decks.
        if (node.getDid() == 1 && nodes.size() > 1 && !node.hasChildren()) {
            if (mCol.getDb().queryScalar("select 1 from cards where did = 1") == 0) {
                continue;
            }
        }
        // If any of this node's parents are collapsed, don't add it to the deck list
        for (Deck parent : mCol.getDecks().parents(node.getDid())) {
            if (parent == null) {
                continue;
            }
            Timber.i("我的父节点关闭啦:%s:%s", parent.optString("name"), parent.optBoolean("collapsed"));
            // mHasSubdecks = true;    // If a deck has a parent it means it's a subdeck so set a flag
            if (parent.optBoolean("collapsed")) {
                return;
            }
        }
        if (/*node.getDid()!=mCurrentDeck.optLong("id")&&*/
        node.getDepth() > Decks.path(mCurrentDeck.optString("name")).length - 1) {
            Timber.i("添加节点到目录:%s", node.getFullDeckName());
            mDeckList.add(node);
        }
        // Add this node's counts to the totals if it's a parent deck
        if (node.getDepth() == 0) {
            if (node.shouldDisplayCounts()) {
                mNew += node.getNewCount();
                mRev += node.getLrnCount();
                mRev += node.getRevCount();
            }
        }
        // Process sub-decks
        processNodes(node.getChildren());
    }
}
Also used : Deck(com.ichi2.libanki.Deck) AbstractDeckTreeNode(com.ichi2.libanki.sched.AbstractDeckTreeNode)

Example 43 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class Syncer method sanityCheck.

public JSONObject sanityCheck() {
    JSONObject result = new JSONObject();
    try {
        if (mCol.getDb().queryScalar("SELECT count() FROM cards WHERE nid NOT IN (SELECT id FROM notes)") != 0) {
            Timber.e("Sync - SanityCheck: there are cards without mother notes");
            result.put("client", "missing notes");
            return result;
        }
        if (mCol.getDb().queryScalar("SELECT count() FROM notes WHERE id NOT IN (SELECT DISTINCT nid FROM cards)") != 0) {
            Timber.e("Sync - SanityCheck: there are notes without cards");
            result.put("client", "missing cards");
            return result;
        }
        if (mCol.getDb().queryScalar("SELECT count() FROM cards WHERE usn = -1") != 0) {
            Timber.e("Sync - SanityCheck: there are unsynced cards");
            result.put("client", "cards had usn = -1");
            return result;
        }
        if (mCol.getDb().queryScalar("SELECT count() FROM notes WHERE usn = -1") != 0) {
            Timber.e("Sync - SanityCheck: there are unsynced notes");
            result.put("client", "notes had usn = -1");
            return result;
        }
        if (mCol.getDb().queryScalar("SELECT count() FROM revlog WHERE usn = -1") != 0) {
            Timber.e("Sync - SanityCheck: there are unsynced revlogs");
            result.put("client", "revlog had usn = -1");
            return result;
        }
        if (mCol.getDb().queryScalar("SELECT count() FROM graves WHERE usn = -1") != 0) {
            Timber.e("Sync - SanityCheck: there are unsynced graves");
            result.put("client", "graves had usn = -1");
            return result;
        }
        for (Deck g : mCol.getDecks().all()) {
            if (g.getInt("usn") == -1) {
                Timber.e("Sync - SanityCheck: unsynced deck: " + g.getString("name"));
                result.put("client", "deck had usn = -1");
                return result;
            }
        }
        for (Map.Entry<String, Integer> tag : mCol.getTags().allItems()) {
            if (tag.getValue() == -1) {
                Timber.e("Sync - SanityCheck: there are unsynced tags");
                result.put("client", "tag had usn = -1");
                return result;
            }
        }
        boolean found = false;
        for (JSONObject m : mCol.getModels().all()) {
            if (mCol.getServer()) {
                // the web upgrade was mistakenly setting usn
                if (m.getInt("usn") < 0) {
                    m.put("usn", 0);
                    found = true;
                }
            } else {
                if (m.getInt("usn") == -1) {
                    Timber.e("Sync - SanityCheck: unsynced model: " + m.getString("name"));
                    result.put("client", "model had usn = -1");
                    return result;
                }
            }
        }
        if (found) {
            mCol.getModels().save();
        }
        // check for missing parent decks
        mCol.getSched().deckDueList();
        // return summary of deck
        JSONArray check = new JSONArray();
        JSONArray counts = new JSONArray();
        // #5666 - not in libAnki
        // We modified mReportLimit inside the scheduler, and this causes issues syncing dynamic decks.
        AbstractSched syncScheduler = mCol.createScheduler(SYNC_SCHEDULER_REPORT_LIMIT);
        for (int c : syncScheduler.recalculateCounts()) {
            counts.put(c);
        }
        check.put(counts);
        check.put(mCol.getDb().queryScalar("SELECT count() FROM cards"));
        check.put(mCol.getDb().queryScalar("SELECT count() FROM notes"));
        check.put(mCol.getDb().queryScalar("SELECT count() FROM revlog"));
        check.put(mCol.getDb().queryScalar("SELECT count() FROM graves"));
        check.put(mCol.getModels().all().size());
        check.put(mCol.getDecks().all().size());
        check.put(mCol.getDecks().allConf().size());
        result.put("client", check);
        return result;
    } catch (JSONException e) {
        Timber.e(e, "Syncer.sanityCheck()");
        throw new RuntimeException(e);
    }
}
Also used : JSONObject(com.ichi2.utils.JSONObject) AbstractSched(com.ichi2.libanki.sched.AbstractSched) JSONArray(com.ichi2.utils.JSONArray) Deck(com.ichi2.libanki.Deck) JSONException(com.ichi2.utils.JSONException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method getCard.

/**
 * Pop the next card from the queue. null if finished.
 */
@Nullable
public Card getCard() {
    _checkDay();
    // check day deal with cutoff if required. No need to do it in resets
    if (!mHaveCounts) {
        resetCounts(false);
    }
    if (!mHaveQueues) {
        resetQueues(false);
    }
    @Nullable Card card = _getCard();
    if (card != null) {
        mCol.log(card);
        incrReps();
        // In upstream, counts are decremented when the card is
        // gotten; i.e. in _getLrnCard, _getRevCard and
        // _getNewCard. This can not be done anymore since we use
        // those methods to pre-fetch the next card. Instead we
        // decrement the counts here, when the card is returned to
        // the reviewer.
        decrementCounts(card);
        setCurrentCard(card);
        card.startTimer();
    } else {
        discardCurrentCard();
    }
    return card;
}
Also used : Nullable(androidx.annotation.Nullable) Card(com.ichi2.libanki.Card) Nullable(androidx.annotation.Nullable)

Example 45 with Counts

use of com.ichi2.libanki.sched.Counts in project AnkiChinaAndroid by ankichinateam.

the class DeckDueTreeNode method setChildren.

public void setChildren(@NonNull List<DeckDueTreeNode> children, boolean addRev) {
    super.setChildren(children, addRev);
    // tally up children counts
    for (DeckDueTreeNode ch : children) {
        mLrnCount += ch.getLrnCount();
        mNewCount += ch.getNewCount();
        if (addRev) {
            mRevCount += ch.getRevCount();
        }
    }
    // limit the counts to the deck's limits
    JSONObject conf = getCol().getDecks().confForDid(getDid());
    if (conf.getInt("dyn") == 0) {
        JSONObject deck = getCol().getDecks().get(getDid());
        limitNewCount(conf.getJSONObject("new").getInt("perDay") - deck.getJSONArray("newToday").getInt(1));
        if (addRev) {
            limitRevCount(conf.getJSONObject("rev").getInt("perDay") - deck.getJSONArray("revToday").getInt(1));
        }
    }
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Aggregations

Collection (com.ichi2.libanki.Collection)47 Card (com.ichi2.libanki.Card)43 Test (org.junit.Test)39 RobolectricTest (com.ichi2.anki.RobolectricTest)38 Note (com.ichi2.libanki.Note)38 Deck (com.ichi2.libanki.Deck)12 DeckConfig (com.ichi2.libanki.DeckConfig)11 JSONArray (com.ichi2.utils.JSONArray)11 JSONObject (com.ichi2.utils.JSONObject)10 JSONException (com.ichi2.utils.JSONException)6 HashMap (java.util.HashMap)6 Resources (android.content.res.Resources)4 Nullable (androidx.annotation.Nullable)4 Model (com.ichi2.libanki.Model)4 AbstractDeckTreeNode (com.ichi2.libanki.sched.AbstractDeckTreeNode)4 IOException (java.io.IOException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JSONObject (org.json.JSONObject)4 Cursor (android.database.Cursor)3 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)3