Search in sources :

Example 56 with JSONObject

use of com.ichi2.utils.JSONObject 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 JSONObject

use of com.ichi2.utils.JSONObject 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 JSONObject

use of com.ichi2.utils.JSONObject 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 59 with JSONObject

use of com.ichi2.utils.JSONObject 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)

Example 60 with JSONObject

use of com.ichi2.utils.JSONObject in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _answerLrnCard.

// Overriden
protected void _answerLrnCard(@NonNull Card card, @Consts.BUTTON_TYPE int ease) {
    JSONObject conf = _lrnConf(card);
    @Consts.CARD_TYPE int type;
    if (card.getType() == Consts.CARD_TYPE_REV || card.getType() == Consts.CARD_TYPE_RELEARNING) {
        type = Consts.CARD_TYPE_REV;
    } else {
        type = Consts.CARD_TYPE_NEW;
    }
    // lrnCount was decremented once when card was fetched
    int lastLeft = card.getLeft();
    boolean leaving = false;
    // immediate graduate?
    if (ease == Consts.BUTTON_FOUR) {
        _rescheduleAsRev(card, conf, true);
        leaving = true;
    // next step?
    } else if (ease == Consts.BUTTON_THREE) {
        // graduation time?
        if ((card.getLeft() % 1000) - 1 <= 0) {
            _rescheduleAsRev(card, conf, false);
            leaving = true;
        } else {
            _moveToNextStep(card, conf);
        }
    } else if (ease == Consts.BUTTON_TWO) {
        _repeatStep(card, conf);
    } else {
        // move back to first step
        _moveToFirstStep(card, conf);
    }
    _logLrn(card, ease, conf, leaving, type, lastLeft);
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Aggregations

JSONObject (com.ichi2.utils.JSONObject)272 JSONArray (com.ichi2.utils.JSONArray)110 ArrayList (java.util.ArrayList)59 Test (org.junit.Test)55 Collection (com.ichi2.libanki.Collection)46 IOException (java.io.IOException)40 RobolectricTest (com.ichi2.anki.RobolectricTest)34 JSONException (com.ichi2.utils.JSONException)34 Note (com.ichi2.libanki.Note)33 Model (com.ichi2.libanki.Model)31 HashMap (java.util.HashMap)31 SuppressLint (android.annotation.SuppressLint)29 JSONObject (org.json.JSONObject)27 Response (okhttp3.Response)25 JSONException (org.json.JSONException)24 NonNull (androidx.annotation.NonNull)23 Card (com.ichi2.libanki.Card)21 File (java.io.File)21 Map (java.util.Map)20 Intent (android.content.Intent)19