const timeZone = "Asia/Singapore";
const State = {
New: 0,
Learning: 1,
Review: 2,
Relearning: 3,
};
const Rating = {
Again: 1,
Hard: 2,
Good: 3,
Easy: 4,
};
class ReviewLog {
rating;
elapsed_days;
scheduled_days;
review;
state;
constructor(rating, elapsed_days, scheduled_days, review, state) {
this.rating = rating;
this.elapsed_days = elapsed_days;
this.scheduled_days = Math.abs(scheduled_days);
this.review = review;
this.state = state;
}
}
class Card {
due;
stability;
difficulty;
elapsed_days;
scheduled_days;
reps;
lapses;
state;
last_review;
constructor() {
this.due = new Date();
this.stability = 0;
this.difficulty = 0;
this.elapsed_days = 0;
this.scheduled_days = 0;
this.reps = 0;
this.lapses = 0;
this.state = State.New;
this.last_review = new Date();
}
}
class SchedulingInfo {
card;
review_log;
constructor(card, review_log) {
this.card = card;
this.review_log = review_log;
}
}
class SchedulingCards {
again;
hard;
good;
easy;
constructor(card) {
this.again = { ...card };
this.hard = { ...card };
this.good = { ...card };
this.easy = { ...card };
}
update_state(state) {
if (state == State.New) {
this.again.state = State.Learning;
this.hard.state = State.Learning;
this.good.state = State.Learning;
this.easy.state = State.Review;
this.again.lapses += 1;
} else if (state == State.Learning || state == State.Relearning) {
this.again.state = state;
this.hard.state = state;
this.good.state = State.Review;
this.easy.state = State.Review;
} else if (state == State.Review) {
this.again.state = State.Relearning;
this.hard.state = State.Review;
this.good.state = State.Review;
this.easy.state = State.Review;
this.again.lapses += 1;
}
}
schedule(now, hard_interval, good_interval, easy_interval) {
this.again.scheduled_days = 0;
this.hard.scheduled_days = hard_interval;
this.good.scheduled_days = good_interval;
this.easy.scheduled_days = easy_interval;