use of com.ichi2.anki.CardBrowser.Column.EASE 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);
}
use of com.ichi2.anki.CardBrowser.Column.EASE in project AnkiChinaAndroid by ankichinateam.
the class SchedV2 method _earlyReviewIvl.
/**
* next interval for card when answered early+correctly
*/
private int _earlyReviewIvl(@NonNull Card card, @Consts.BUTTON_TYPE int ease) {
if (card.getODid() == 0 || card.getType() != Consts.CARD_TYPE_REV || card.getFactor() == 0) {
throw new RuntimeException("Unexpected card parameters");
}
if (ease <= 1) {
throw new RuntimeException("Ease must be greater than 1");
}
long elapsed = card.getIvl() - (card.getODue() - mToday);
@NonNull JSONObject conf = _revConf(card);
double easyBonus = 1;
// early 3/4 reviews shouldn't decrease previous interval
double minNewIvl = 1;
double factor;
if (ease == Consts.BUTTON_TWO) {
factor = conf.optDouble("hardFactor", 1.2);
// hard cards shouldn't have their interval decreased by more than 50%
// of the normal factor
minNewIvl = factor / 2;
} else if (ease == 3) {
factor = card.getFactor() / 1000.0;
} else {
// ease == 4
factor = card.getFactor() / 1000.0;
double ease4 = conf.getDouble("ease4");
// 1.3 -> 1.15
easyBonus = ease4 - (ease4 - 1) / 2;
}
double ivl = Math.max(elapsed * factor, 1);
// cap interval decreases
ivl = Math.max(card.getIvl() * minNewIvl, ivl) * easyBonus;
return _constrainedIvl(ivl, conf, 0, false);
}
use of com.ichi2.anki.CardBrowser.Column.EASE in project AnkiChinaAndroid by ankichinateam.
the class SchedTest method test_reviewsV1.
@Test
public void test_reviewsV1() throws Exception {
Collection col = getColV1();
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
// set the card up as a review card, due 8 days ago
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setDue(col.getSched().getToday() - 8);
c.setFactor(STARTING_FACTOR);
c.setReps(3);
c.setLapses(1);
c.setIvl(100);
c.startTimer();
c.flush();
// save it for later use as well
Card cardcopy = c.clone();
// failing it should put it in the learn queue with the default options
// //////////////////////////////////////////////////////////////////////////////////////////////////
// different delay to new
col.reset();
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 2, 20 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, 1);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
// it should be due tomorrow, with an interval of 1
assertEquals(col.getSched().getToday() + 1, c.getODue());
assertEquals(1, c.getIvl());
// but because it's in the learn queue, its current due time should be in
// the future
assertThat(c.getDue(), is(greaterThanOrEqualTo(col.getTime().intTime())));
assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(118L)));
// factor should have been decremented
assertEquals(2300, c.getFactor());
// check counters
assertEquals(2, c.getLapses());
assertEquals(4, c.getReps());
// check ests.
assertEquals(120, col.getSched().nextIvl(c, 1));
assertEquals(20 * 60, col.getSched().nextIvl(c, 2));
// try again with an ease of 2 instead
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, 2);
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// the new interval should be (100 + 8/4) * 1.2 = 122
assertTrue(checkRevIvl(col, c, 122));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been decremented
assertEquals(2350, c.getFactor());
// check counters
assertEquals(1, c.getLapses());
assertEquals(4, c.getReps());
// ease 3
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, 3);
// the new interval should be (100 + 8/2) * 2.5 = 260
assertTrue(checkRevIvl(col, c, 260));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been left alone
assertEquals(STARTING_FACTOR, c.getFactor());
// ease 4
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, 4);
// the new interval should be (100 + 8) * 2.5 * 1.3 = 351
assertTrue(checkRevIvl(col, c, 351));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been increased
assertEquals(2650, c.getFactor());
}
use of com.ichi2.anki.CardBrowser.Column.EASE in project Anki-Android by ankidroid.
the class SchedTest method test_reviewsV1.
@Test
public void test_reviewsV1() throws Exception {
Collection col = getColV1();
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
// set the card up as a review card, due 8 days ago
Card c = note.cards().get(0);
c.setType(CARD_TYPE_REV);
c.setQueue(QUEUE_TYPE_REV);
c.setDue(col.getSched().getToday() - 8);
c.setFactor(STARTING_FACTOR);
c.setReps(3);
c.setLapses(1);
c.setIvl(100);
c.startTimer();
c.flush();
// save it for later use as well
Card cardcopy = c.clone();
// failing it should put it in the learn queue with the default options
// //////////////////////////////////////////////////////////////////////////////////////////////////
// different delay to new
col.reset();
DeckConfig conf = col.getSched()._cardConf(c);
conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 2, 20 }));
col.getDecks().save(conf);
col.getSched().answerCard(c, BUTTON_ONE);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
// it should be due tomorrow, with an interval of 1
assertEquals(col.getSched().getToday() + 1, c.getODue());
assertEquals(1, c.getIvl());
// but because it's in the learn queue, its current due time should be in
// the future
assertThat(c.getDue(), is(greaterThanOrEqualTo(col.getTime().intTime())));
assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(118L)));
// factor should have been decremented
assertEquals(2300, c.getFactor());
// check counters
assertEquals(2, c.getLapses());
assertEquals(4, c.getReps());
// check ests.
assertEquals(120, col.getSched().nextIvl(c, BUTTON_ONE));
assertEquals(20 * 60, col.getSched().nextIvl(c, BUTTON_TWO));
// try again with an ease of 2 instead
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, BUTTON_TWO);
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// the new interval should be (100 + 8/4) * 1.2 = 122
assertTrue(checkRevIvl(col, c, 122));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been decremented
assertEquals(2350, c.getFactor());
// check counters
assertEquals(1, c.getLapses());
assertEquals(4, c.getReps());
// ease 3
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, BUTTON_THREE);
// the new interval should be (100 + 8/2) * 2.5 = 260
assertTrue(checkRevIvl(col, c, 260));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been left alone
assertEquals(STARTING_FACTOR, c.getFactor());
// ease 4
// //////////////////////////////////////////////////////////////////////////////////////////////////
c = cardcopy.clone();
c.flush();
col.getSched().answerCard(c, BUTTON_FOUR);
// the new interval should be (100 + 8) * 2.5 * 1.3 = 351
assertTrue(checkRevIvl(col, c, 351));
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
// factor should have been increased
assertEquals(2650, c.getFactor());
}
use of com.ichi2.anki.CardBrowser.Column.EASE in project Anki-Android by ankidroid.
the class AbstractFlashcardViewer method answerCard.
protected void answerCard(@Consts.BUTTON_TYPE int ease) {
if (mInAnswer) {
return;
}
mIsSelecting = false;
int buttonNumber = getCol().getSched().answerButtons(mCurrentCard);
// Detect invalid ease for current card (e.g. by using keyboard shortcut or gesture).
if (buttonNumber < ease) {
return;
}
// Temporarily sets the answer indicator dots appearing below the toolbar
mPreviousAnswerIndicator.displayAnswerIndicator(ease, buttonNumber);
mSoundPlayer.stopSounds();
mCurrentEase = ease;
new SchedulerService.AnswerAndGetCard(mCurrentCard, mCurrentEase).runWithHandler(answerCardHandler(true));
}
Aggregations