Search in sources :

Example 51 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class Sched method _deckRevLimitSingle.

/**
 * Maximal number of rev card still to see today in deck d. It's computed as:
 * the number of rev card to see by day according
 * minus the number of rev cards seen today in deck d or a descendant
 * plus the number of extra cards to see today in deck d, a parent or a descendant.
 *
 * Limits of its ancestors are not applied.  Current card is treated the same way as other cards.
 * @param considerCurrentCard Whether current card should be conted if it is in this deck
 */
@Override
protected int _deckRevLimitSingle(@NonNull Deck d, boolean considerCurrentCard) {
    if (d.isDyn()) {
        return mReportLimit;
    }
    long did = d.getLong("id");
    DeckConfig c = mCol.getDecks().confForDid(did);
    int lim = Math.max(0, c.getJSONObject("rev").getInt("perDay") - d.getJSONArray("revToday").getInt(1));
    if (considerCurrentCard && currentCardIsInQueueWithDeck(Consts.QUEUE_TYPE_REV, did)) {
        lim--;
    }
    // So currentCard does not have to be taken into consideration in this method
    return lim;
}
Also used : DeckConfig(com.ichi2.libanki.DeckConfig)

Example 52 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class Sched method _newConf.

/**
 * Tools ******************************************************************** ***************************
 */
@Override
@NonNull
protected JSONObject _newConf(@NonNull Card card) {
    DeckConfig conf = _cardConf(card);
    if (!card.isInDynamicDeck()) {
        return conf.getJSONObject("new");
    }
    // dynamic deck; override some attributes, use original deck for others
    DeckConfig oconf = mCol.getDecks().confForDid(card.getODid());
    JSONArray delays = conf.optJSONArray("delays");
    if (delays == null) {
        delays = oconf.getJSONObject("new").getJSONArray("delays");
    }
    JSONObject dict = new JSONObject();
    // original deck
    dict.put("ints", oconf.getJSONObject("new").getJSONArray("ints"));
    dict.put("initialFactor", oconf.getJSONObject("new").getInt("initialFactor"));
    dict.put("bury", oconf.getJSONObject("new").optBoolean("bury", true));
    // overrides
    dict.put("delays", delays);
    dict.put("separate", conf.getBoolean("separate"));
    dict.put("order", Consts.NEW_CARDS_DUE);
    dict.put("perDay", mReportLimit);
    return dict;
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray) DeckConfig(com.ichi2.libanki.DeckConfig) NonNull(androidx.annotation.NonNull)

Example 53 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class AbstractSchedTest method siblingCorrectlyBuried.

@Test
public void siblingCorrectlyBuried() {
    // #6903
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    DeckConfig dconf = col.getDecks().getConf(1);
    assertThat(dconf, notNullValue());
    dconf.getJSONObject("new").put("bury", true);
    getCol().getDecks().save(dconf);
    final int nbNote = 2;
    Note[] notes = new Note[nbNote];
    for (int i = 0; i < nbNote; i++) {
        Note note = addNoteUsingBasicAndReversedModel("front", "back");
        notes[i] = note;
    }
    col.reset();
    for (int i = 0; i < nbNote; i++) {
        Card card = sched.getCard();
        Counts counts = sched.counts(card);
        // imitate what the reviewer does
        sched.setCurrentCard(card);
        // Actual number of new card.
        assertThat(counts.getNew(), is(greaterThan(nbNote - i)));
        // Maximal number potentially shown,
        assertThat(counts.getNew(), is(lessThanOrEqualTo(nbNote * 2 - i)));
        // because decrementing does not consider burying sibling
        assertEquals(0, counts.getLrn());
        assertEquals(0, counts.getRev());
        assertEquals(notes[i].firstCard().getId(), card.getId());
        assertEquals(Consts.QUEUE_TYPE_NEW, card.getQueue());
        sched.answerCard(card, sched.answerButtons(card));
    }
    Card card = sched.getCard();
    assertNull(card);
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 54 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class AbstractSchedTest method undoAndRedo.

protected void undoAndRedo(boolean preload) {
    Collection col = getCol();
    DeckConfig conf = col.getDecks().confForDid(1);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 3, 5, 10 }));
    col.getDecks().save(conf);
    col.set_config("collapseTime", 20 * 60);
    AbstractSched sched = col.getSched();
    addNoteUsingBasicModel("foo", "bar");
    col.reset();
    advanceRobolectricLooper();
    Card card = sched.getCard();
    assertNotNull(card);
    assertEquals(new Counts(1, 0, 0), sched.counts(card));
    if (preload) {
        sched.preloadNextCard();
    }
    sched.answerCard(card, sched.getGoodNewButton());
    advanceRobolectricLooper();
    card = sched.getCard();
    assertNotNull(card);
    assertEquals(new Counts(0, (schedVersion == 1) ? 3 : 1, 0), sched.counts(card));
    if (preload) {
        sched.preloadNextCard();
    }
    sched.answerCard(card, sched.getGoodNewButton());
    advanceRobolectricLooper();
    card = sched.getCard();
    assertNotNull(card);
    assertEquals(new Counts(0, (schedVersion == 1) ? 2 : 1, 0), sched.counts(card));
    if (preload) {
        sched.preloadNextCard();
        advanceRobolectricLooper();
    }
    assertNotNull(card);
    card = nonTaskUndo(col);
    advanceRobolectricLooper();
    assertNotNull(card);
    assertEquals(new Counts(0, (schedVersion == 1) ? 3 : 1, 0), sched.counts(card));
    sched.count();
    if (preload) {
        sched.preloadNextCard();
        advanceRobolectricLooper();
    }
    sched.answerCard(card, sched.getGoodNewButton());
    advanceRobolectricLooper();
    card = sched.getCard();
    assertNotNull(card);
    if (preload) {
        sched.preloadNextCard();
    }
    assertEquals(new Counts(0, (schedVersion == 1) ? 2 : 1, 0), sched.counts(card));
    assertNotNull(card);
}
Also used : JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card)

Example 55 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class AbstractSchedTest method ensureUndoCorrectCounts.

@Test
public void ensureUndoCorrectCounts() {
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    DeckConfig dconf = col.getDecks().getConf(1);
    assertThat(dconf, notNullValue());
    dconf.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(dconf);
    for (int i = 0; i < 20; i++) {
        Note note = col.newNote();
        note.setField(0, "a");
        col.addNote(note);
    }
    col.reset();
    assertThat(col.cardCount(), is(20));
    assertThat(sched.newCount(), is(10));
    Card card = sched.getCard();
    assertThat(sched.newCount(), is(9));
    assertThat(sched.counts(card).getNew(), is(10));
    sched.answerCard(card, sched.getGoodNewButton());
    sched.getCard();
    nonTaskUndo(col);
    card.load();
    assertThat(sched.newCount(), is(9));
    assertThat(sched.counts(card).getNew(), is(10));
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

DeckConfig (com.ichi2.libanki.DeckConfig)85 Collection (com.ichi2.libanki.Collection)57 Card (com.ichi2.libanki.Card)50 Test (org.junit.Test)49 RobolectricTest (com.ichi2.anki.RobolectricTest)48 Note (com.ichi2.libanki.Note)47 JSONArray (com.ichi2.utils.JSONArray)42 JSONObject (com.ichi2.utils.JSONObject)27 Deck (com.ichi2.libanki.Deck)14 NonNull (androidx.annotation.NonNull)12 Cursor (android.database.Cursor)5 JSONException (com.ichi2.utils.JSONException)5 ArrayList (java.util.ArrayList)5 Model (com.ichi2.libanki.Model)4 HashMap (java.util.HashMap)4 SuppressLint (android.annotation.SuppressLint)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ContentValues (android.content.ContentValues)2 Intent (android.content.Intent)2