Search in sources :

Example 1 with SchedV2

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

the class Collection method createScheduler.

// This duplicates _loadScheduler (but returns the value and sets the report limit).
public AbstractSched createScheduler(int reportLimit) {
    int ver = schedVer();
    if (ver == 1) {
        mSched = new Sched(this);
    } else if (ver == 2) {
        mSched = new SchedV2(this);
    }
    mSched.setReportLimit(reportLimit);
    return mSched;
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Sched(com.ichi2.libanki.sched.Sched) SuppressLint(android.annotation.SuppressLint) SchedV2(com.ichi2.libanki.sched.SchedV2)

Example 2 with SchedV2

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

the class Collection method changeSchedulerVer.

public void changeSchedulerVer(Integer ver) throws ConfirmModSchemaException {
    if (ver == schedVer()) {
        return;
    }
    if (!fSupportedSchedulerVersions.contains(ver)) {
        throw new RuntimeException("Unsupported scheduler version");
    }
    modSchema();
    @SuppressLint("VisibleForTests") SchedV2 v2Sched = new SchedV2(this);
    clearUndo();
    if (ver == 1) {
        v2Sched.moveToV1();
    } else {
        v2Sched.moveToV2();
    }
    mConf.put("schedVer", ver);
    setMod();
    _loadScheduler();
}
Also used : SuppressLint(android.annotation.SuppressLint) SchedV2(com.ichi2.libanki.sched.SchedV2)

Example 3 with SchedV2

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

the class SchedV2Test method filteredDeckSchedulingOptionsRegressionTest.

/**
 * Reported by /u/CarelessSecretary9 on reddit:
 */
@Test
public void filteredDeckSchedulingOptionsRegressionTest() {
    Collection col = getCol();
    col.setCrt(1587852900L);
    // 30 minutes learn ahead. required as we have 20m delay
    col.getConf().put("collapseTime", 1800);
    long homeDeckId = addDeck("Poorretention");
    DeckConfig homeDeckConf = col.getDecks().confForDid(homeDeckId);
    JSONObject lapse = homeDeckConf.getJSONObject("lapse");
    lapse.put("minInt", 2);
    lapse.put("mult", 0.7d);
    lapse.put("delays", new JSONArray("[20]"));
    ensureLapseMatchesSppliedAnkiDesktopConfig(lapse);
    col.flush();
    long dynId = addDynamicDeck("Dyn");
    /*
        >>> pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 0, 'factor': 1300, 'flags': 0, 'id': 1510928829863, 'ivl': 25,
        'lapses': 5, 'left': 1004, 'mod': 1587921512, 'nid': 1510928805161, 'odid': 1587920944107,
        'odue': 0, 'ord': 0, 'queue': 2, 'reps': 22, 'type': 2, 'usn': -1}

         */
    Note n = addNoteUsingBasicModel("Hello", "World");
    Card c = getOnlyElement(n.cards());
    c.setType(Consts.CARD_TYPE_REV);
    c.setQueue(Consts.QUEUE_TYPE_REV);
    c.setIvl(25);
    c.setDue(0);
    c.setLapses(5);
    c.setFactor(1300);
    c.setLeft(1004);
    c.setODid(homeDeckId);
    c.setDid(dynId);
    c.flush();
    SchedV2 v2 = new SchedV2(col);
    Card schedCard = v2.getCard();
    assertThat(schedCard, Matchers.notNullValue());
    v2.answerCard(schedCard, Consts.BUTTON_ONE);
    assertThat("The lapsed card should now be counted as lrn", v2.mLrnCount, is(1));
    Card after = v2.getCard();
    assertThat("A card should be returned ", after, Matchers.notNullValue());
    /* Data from Anki - pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 1587941137, 'factor': 1300,
        'flags': 0, 'id': 1510928829863, 'ivl': 17, 'lapses': 6, 'left': 1001,
        'mod': 1587939720, 'nid': 1510928805161, 'odid': 1587920944107, 'odue': 0,
        'ord': 0, 'queue': 1, 'reps': 23, 'type': 3, 'usn': -1}
         */
    assertThat(after.getType(), is(Consts.CARD_TYPE_RELEARNING));
    assertThat(after.getQueue(), is(Consts.QUEUE_TYPE_LRN));
    assertThat(after.getLeft(), is(1001));
    assertThat("ivl is reduced by 70%", after.getIvl(), is(17));
    assertThat("One lapse is added", after.getLapses(), is(6));
    assertThat(v2.answerButtons(after), is(4));
    long one = v2.nextIvl(after, Consts.BUTTON_ONE);
    long two = v2.nextIvl(after, Consts.BUTTON_TWO);
    long three = v2.nextIvl(after, Consts.BUTTON_THREE);
    long four = v2.nextIvl(after, Consts.BUTTON_FOUR);
    // 20 mins
    assertThat("Again should pick the current step", one, is(1200L));
    // 30 mins
    assertThat("Repeating single step - 20 minutes * 1.5", two, is(1800L));
    // 17 days
    assertThat("Good should take the reduced interval (25 * 0.7)", three, is(1468800L));
    // 18 days
    assertThat("Easy should have a bonus day over good", four, is(1555200L));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) 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 4 with SchedV2

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

the class SchedV2Test method filteredDeckSchedulingOptionsRegressionTest.

/**
 * Reported by /u/CarelessSecretary9 on reddit:
 */
@Test
public void filteredDeckSchedulingOptionsRegressionTest() {
    Collection col = getCol();
    col.setCrt(1587852900L);
    // 30 minutes learn ahead. required as we have 20m delay
    col.set_config("collapseTime", 1800);
    long homeDeckId = addDeck("Poorretention");
    DeckConfig homeDeckConf = col.getDecks().confForDid(homeDeckId);
    JSONObject lapse = homeDeckConf.getJSONObject("lapse");
    lapse.put("minInt", 2);
    lapse.put("mult", 0.7d);
    lapse.put("delays", new JSONArray("[20]"));
    col.getDecks().save(homeDeckConf);
    ensureLapseMatchesSppliedAnkiDesktopConfig(lapse);
    col.flush();
    long dynId = addDynamicDeck("Dyn");
    /*
        >>> pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 0, 'factor': 1300, 'flags': 0, 'id': 1510928829863, 'ivl': 25,
        'lapses': 5, 'left': 1004, 'mod': 1587921512, 'nid': 1510928805161, 'odid': 1587920944107,
        'odue': 0, 'ord': 0, 'queue': 2, 'reps': 22, 'type': 2, 'usn': -1}

         */
    Note n = addNoteUsingBasicModel("Hello", "World");
    Card c = getOnlyElement(n.cards());
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setIvl(25);
    c.setDue(0);
    c.setLapses(5);
    c.setFactor(1300);
    c.setLeft(1004);
    c.setODid(homeDeckId);
    c.setDid(dynId);
    c.flush();
    SchedV2 v2 = new SchedV2(col);
    Card schedCard = v2.getCard();
    assertThat(schedCard, Matchers.notNullValue());
    v2.answerCard(schedCard, BUTTON_ONE);
    assertThat("The lapsed card should now be counted as lrn", v2.mLrnCount, is(1));
    Card after = v2.getCard();
    assertThat("A card should be returned ", after, Matchers.notNullValue());
    /* Data from Anki - pp(self.reviewer.card)
        {'data': '', 'did': 1587939535230, 'due': 1587941137, 'factor': 1300,
        'flags': 0, 'id': 1510928829863, 'ivl': 17, 'lapses': 6, 'left': 1001,
        'mod': 1587939720, 'nid': 1510928805161, 'odid': 1587920944107, 'odue': 0,
        'ord': 0, 'queue': 1, 'reps': 23, 'type': 3, 'usn': -1}
         */
    assertThat(after.getType(), is(Consts.CARD_TYPE_RELEARNING));
    assertThat(after.getQueue(), is(Consts.QUEUE_TYPE_LRN));
    assertThat(after.getLeft(), is(1001));
    assertThat("ivl is reduced by 70%", after.getIvl(), is(17));
    assertThat("One lapse is added", after.getLapses(), is(6));
    assertThat(v2.answerButtons(after), is(4));
    long one = v2.nextIvl(after, BUTTON_ONE);
    long two = v2.nextIvl(after, BUTTON_TWO);
    long three = v2.nextIvl(after, BUTTON_THREE);
    long four = v2.nextIvl(after, BUTTON_FOUR);
    // 20 mins
    assertThat("Again should pick the current step", one, is(1200L));
    // 30 mins
    assertThat("Repeating single step - 20 minutes * 1.5", two, is(1800L));
    // 17 days
    assertThat("Good should take the reduced interval (25 * 0.7)", three, is(1468800L));
    // 18 days
    assertThat("Easy should have a bonus day over good", four, is(1555200L));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) 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 5 with SchedV2

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

the class Collection method changeSchedulerVer.

public void changeSchedulerVer(Integer ver) throws ConfirmModSchemaException {
    if (ver == schedVer()) {
        return;
    }
    if (!fSupportedSchedulerVersions.contains(ver)) {
        throw new RuntimeException("Unsupported scheduler version");
    }
    modSchema();
    @SuppressLint("VisibleForTests") SchedV2 v2Sched = new SchedV2(this);
    clearUndo();
    if (ver == 1) {
        v2Sched.moveToV1();
    } else {
        v2Sched.moveToV2();
    }
    set_config("schedVer", ver);
    _loadScheduler();
}
Also used : SuppressLint(android.annotation.SuppressLint) SchedV2(com.ichi2.libanki.sched.SchedV2)

Aggregations

RobolectricTest (com.ichi2.anki.RobolectricTest)7 SchedV2 (com.ichi2.libanki.sched.SchedV2)7 Test (org.junit.Test)7 Card (com.ichi2.libanki.Card)5 Collection (com.ichi2.libanki.Collection)5 SuppressLint (android.annotation.SuppressLint)4 Note (com.ichi2.libanki.Note)4 AbstractSched (com.ichi2.libanki.sched.AbstractSched)3 Sched (com.ichi2.libanki.sched.Sched)3 DeckConfig (com.ichi2.libanki.DeckConfig)2 JSONArray (com.ichi2.utils.JSONArray)2 JSONObject (com.ichi2.utils.JSONObject)2 Config (org.robolectric.annotation.Config)2 Time (com.ichi2.libanki.utils.Time)1