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());
}
}
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());
}
}
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);
}
}
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;
}
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));
}
}
}
Aggregations