Search in sources :

Example 56 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _startingLeft.

// Overriden: V1 has type rev for relearinng
protected int _startingLeft(@NonNull Card card) {
    JSONObject conf;
    if (card.getType() == Consts.CARD_TYPE_RELEARNING) {
        conf = _lapseConf(card);
    } else {
        conf = _lrnConf(card);
    }
    int tot = conf.getJSONArray("delays").length();
    int tod = _leftToday(conf.getJSONArray("delays"), tot);
    return tot + tod * 1000;
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 57 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _rescheduleLapse.

// Overriden
protected int _rescheduleLapse(@NonNull Card card) {
    JSONObject conf;
    conf = _lapseConf(card);
    card.setLapses(card.getLapses() + 1);
    card.setFactor(Math.max(1300, card.getFactor() - 200));
    int delay;
    boolean suspended = _checkLeech(card, conf) && card.getQueue() == Consts.QUEUE_TYPE_SUSPENDED;
    if (conf.getJSONArray("delays").length() != 0 && !suspended) {
        card.setType(Consts.CARD_TYPE_RELEARNING);
        delay = _moveToFirstStep(card, conf);
    } else {
        // no relearning steps
        _updateRevIvlOnFail(card, conf);
        _rescheduleAsRev(card, conf, false);
        // need to reset the queue after rescheduling
        if (suspended) {
            card.setQueue(Consts.QUEUE_TYPE_SUSPENDED);
        }
        delay = 0;
    }
    return delay;
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 58 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _updateStats.

public void _updateStats(@NonNull Card card, @NonNull String type, long cnt) {
    String key = type + "Today";
    long did = card.getDid();
    List<Deck> list = mCol.getDecks().parents(did);
    list.add(mCol.getDecks().get(did));
    for (Deck g : list) {
        JSONArray a = g.getJSONArray(key);
        // add
        a.put(1, a.getLong(1) + cnt);
        mCol.getDecks().save(g);
    }
}
Also used : JSONArray(com.ichi2.utils.JSONArray) Deck(com.ichi2.libanki.Deck)

Example 59 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _nextRevIvl.

/**
 * Interval management ******************************************************
 * *****************************************
 */
/**
 * Next interval for CARD, given EASE.
 */
protected int _nextRevIvl(@NonNull Card card, @Consts.BUTTON_TYPE int ease, boolean fuzz) {
    long delay = _daysLate(card);
    JSONObject conf = _revConf(card);
    double fct = card.getFactor() / 1000.0;
    double hardFactor = conf.optDouble("hardFactor", 1.2);
    int hardMin;
    if (hardFactor > 1) {
        hardMin = card.getIvl();
    } else {
        hardMin = 0;
    }
    int ivl2 = _constrainedIvl(card.getIvl() * hardFactor, conf, hardMin, fuzz);
    if (ease == Consts.BUTTON_TWO) {
        return ivl2;
    }
    int ivl3 = _constrainedIvl((card.getIvl() + delay / 2) * fct, conf, ivl2, fuzz);
    if (ease == Consts.BUTTON_THREE) {
        return ivl3;
    }
    int ivl4 = _constrainedIvl(((card.getIvl() + delay) * fct * conf.getDouble("ease4")), conf, ivl3, fuzz);
    return ivl4;
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 60 with CARD

use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _lapseConf.

// Overridden: different delays for filtered cards.
@NonNull
protected JSONObject _lapseConf(@NonNull Card card) {
    DeckConfig conf = _cardConf(card);
    // normal deck
    if (card.getODid() == 0) {
        return conf.getJSONObject("lapse");
    }
    // dynamic deck; override some attributes, use original deck for others
    DeckConfig oconf = mCol.getDecks().confForDid(card.getODid());
    JSONObject dict = new JSONObject();
    // original deck
    dict.put("minInt", oconf.getJSONObject("lapse").getInt("minInt"));
    dict.put("leechFails", oconf.getJSONObject("lapse").getInt("leechFails"));
    dict.put("leechAction", oconf.getJSONObject("lapse").getInt("leechAction"));
    dict.put("mult", oconf.getJSONObject("lapse").getDouble("mult"));
    dict.put("delays", oconf.getJSONObject("lapse").getJSONArray("delays"));
    // overrides
    dict.put("resched", conf.getBoolean("resched"));
    return dict;
}
Also used : JSONObject(com.ichi2.utils.JSONObject) DeckConfig(com.ichi2.libanki.DeckConfig) NonNull(androidx.annotation.NonNull)

Aggregations

Card (com.ichi2.libanki.Card)222 Test (org.junit.Test)212 Collection (com.ichi2.libanki.Collection)179 Note (com.ichi2.libanki.Note)173 RobolectricTest (com.ichi2.anki.RobolectricTest)168 JSONObject (com.ichi2.utils.JSONObject)114 JSONArray (com.ichi2.utils.JSONArray)80 DeckConfig (com.ichi2.libanki.DeckConfig)72 ArrayList (java.util.ArrayList)48 NonNull (androidx.annotation.NonNull)33 Deck (com.ichi2.libanki.Deck)32 Intent (android.content.Intent)29 JSONException (com.ichi2.utils.JSONException)27 Model (com.ichi2.libanki.Model)26 Context (android.content.Context)23 SuppressLint (android.annotation.SuppressLint)22 Cursor (android.database.Cursor)22 HashMap (java.util.HashMap)21 Matchers.containsString (org.hamcrest.Matchers.containsString)20 List (java.util.List)17