Skip to content

Commit

Permalink
Fix coding standard constant_identifier_names
Browse files Browse the repository at this point in the history
Signed-off-by: Son Bui <sonbv00@gmail.com>
  • Loading branch information
sonbui00 committed Apr 20, 2024
1 parent 148527f commit 0f100ff
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 112 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ printSchedulingCards(schedulingCards);

There are four ratings:
```dart
Rating.Again; // forget; incorrect response
Rating.Hard; // recall; correct response recalled with serious difficulty
Rating.Good; // recall; correct response after a hesitation
Rating.Easy; // recall; perfect response
Rating.again; // forget; incorrect response
Rating.hard; // recall; correct response recalled with serious difficulty
Rating.good; // recall; correct response after a hesitation
Rating.easy; // recall; perfect response
```


Get the new state of card for each rating:
```dart
var cardAgain = schedulingCards[Rating.Again]!.card;
var cardHard = schedulingCards[Rating.Hard]!.card;
var cardGood = schedulingCards[Rating.Good]!.card;
var cardEasy = schedulingCards[Rating.Easy]!.card;
var cardAgain = schedulingCards[Rating.again]!.card;
var cardHard = schedulingCards[Rating.hard]!.card;
var cardGood = schedulingCards[Rating.good]!.card;
var cardEasy = schedulingCards[Rating.easy]!.card;
```

Get the scheduled days for each rating:
Expand All @@ -48,12 +48,12 @@ cardEasy.scheduledDays;

Update the card after rating `Good`:
```dart
card = schedulingCards[Rating.Good]!.card;
card = schedulingCards[Rating.good]!.card;
```

Get the review log after rating `Good`:
```dart
var reviewLog = schedulingCards[Rating.Good]!.reviewLog;
var reviewLog = schedulingCards[Rating.good]!.reviewLog;
```

Get the due date for card:
Expand All @@ -63,10 +63,10 @@ due = card.due

There are four states:
```dart
State.New; // Never been studied
State.Learning; // Been studied for the first time recently
State.Review; // Graduate from learning state
State.Relearning; // Forgotten in review state
State.newState; // Never been studied
State.learning; // Been studied for the first time recently
State.review; // Graduate from learning state
State.relearning; // Forgotten in review state
```

## License
Expand Down
32 changes: 17 additions & 15 deletions example/fsrs_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ void main() {
var f = FSRS();
var card = Card();
var now = DateTime(2022, 11, 29, 12, 30, 0, 0);
print("Now: $now");
var schedulingCards = f.repeat(card, now);
printSchedulingCards(schedulingCards);
// printSchedulingCards(schedulingCards);

// There are four ratings:
Rating.Again; // forget; incorrect response
Rating.Hard; // recall; correct response recalled with serious difficulty
Rating.Good; // recall; correct response after a hesitation
Rating.Easy; // recall; perfect response
Rating.again; // forget; incorrect response
Rating.hard; // recall; correct response recalled with serious difficulty
Rating.good; // recall; correct response after a hesitation
Rating.easy; // recall; perfect response

// Get the new state of card for each rating:
var cardAgain = schedulingCards[Rating.Again]!.card;
var cardHard = schedulingCards[Rating.Hard]!.card;
var cardGood = schedulingCards[Rating.Good]!.card;
var cardEasy = schedulingCards[Rating.Easy]!.card;
var cardAgain = schedulingCards[Rating.again]!.card;
var cardHard = schedulingCards[Rating.hard]!.card;
var cardGood = schedulingCards[Rating.good]!.card;
var cardEasy = schedulingCards[Rating.easy]!.card;

// Get the scheduled days for each rating:
cardAgain.scheduledDays;
Expand All @@ -26,19 +27,20 @@ void main() {
cardEasy.scheduledDays;

// Update the card after rating `Good`:
card = schedulingCards[Rating.Good]!.card;
card = schedulingCards[Rating.easy]!.card;

// Get the review log after rating `Good`:
// ignore: unused_local_variable
var reviewLog = schedulingCards[Rating.Good]!.reviewLog;
var reviewLog = schedulingCards[Rating.good]!.reviewLog;

// Get the due date for card:
// ignore: unused_local_variable
var due = card.due;
print("Due: $due");

// There are four states:
State.New; // Never been studied
State.Learning; // Been studied for the first time recently
State.Review; // Graduate from learning state
State.Relearning; // Forgotten in review state
State.newState; // Never been studied
State.learning; // Been studied for the first time recently
State.review; // Graduate from learning state
State.relearning; // Forgotten in review state
}
42 changes: 21 additions & 21 deletions lib/src/fsrs_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FSRS {

Map<Rating, SchedulingInfo> repeat(Card card, DateTime now) {
card = Card.copyFrom(card);
if (card.state == State.New) {
if (card.state == State.newState) {
card.elapsedDays = 0;
} else {
card.elapsedDays = now.difference(card.lastReview).inDays;
Expand All @@ -26,7 +26,7 @@ class FSRS {
final s = SchedulingCards(card);
s.updateState(card.state);

if (card.state == State.New) {
if (card.state == State.newState) {
_initDS(s);

s.again.due = now.add(Duration(minutes: 1));
Expand All @@ -35,15 +35,15 @@ class FSRS {
final easyInterval = _nextInterval(s.easy.stability);
s.easy.scheduledDays = easyInterval;
s.easy.due = now.add(Duration(days: easyInterval));
} else if (card.state == State.Learning || card.state == State.Relearning) {
} else if (card.state == State.learning || card.state == State.relearning) {
final hardInterval = 0;
final goodInterval = _nextInterval(s.good.stability);
final easyInterval =
max(_nextInterval(s.easy.stability), goodInterval + 1);

s.schedule(now, hardInterval.toDouble(), goodInterval.toDouble(),
easyInterval.toDouble());
} else if (card.state == State.Review) {
} else if (card.state == State.review) {
final interval = card.elapsedDays;
final lastD = card.difficulty;
final lastS = card.stability;
Expand All @@ -63,14 +63,14 @@ class FSRS {
}

void _initDS(SchedulingCards s) {
s.again.difficulty = _initDifficulty(Rating.Again.val);
s.again.stability = _initStability(Rating.Again.val);
s.hard.difficulty = _initDifficulty(Rating.Hard.val);
s.hard.stability = _initStability(Rating.Hard.val);
s.good.difficulty = _initDifficulty(Rating.Good.val);
s.good.stability = _initStability(Rating.Good.val);
s.easy.difficulty = _initDifficulty(Rating.Easy.val);
s.easy.stability = _initStability(Rating.Easy.val);
s.again.difficulty = _initDifficulty(Rating.again.val);
s.again.stability = _initStability(Rating.again.val);
s.hard.difficulty = _initDifficulty(Rating.hard.val);
s.hard.stability = _initStability(Rating.hard.val);
s.good.difficulty = _initDifficulty(Rating.good.val);
s.good.stability = _initStability(Rating.good.val);
s.easy.difficulty = _initDifficulty(Rating.easy.val);
s.easy.stability = _initStability(Rating.easy.val);
}

double _initStability(int r) {
Expand Down Expand Up @@ -100,8 +100,8 @@ class FSRS {
}

double _nextRecallStability(double d, double s, double r, Rating rating) {
final hardPenalty = (rating == Rating.Hard) ? p.w[15] : 1;
final easyBonus = (rating == Rating.Easy) ? p.w[16] : 1;
final hardPenalty = (rating == Rating.hard) ? p.w[15] : 1;
final easyBonus = (rating == Rating.easy) ? p.w[16] : 1;
return s *
(1 +
exp(p.w[8]) *
Expand All @@ -121,16 +121,16 @@ class FSRS {

void _nextDS(
SchedulingCards s, double lastD, double lastS, double retrievability) {
s.again.difficulty = _nextDifficulty(lastD, Rating.Again.val);
s.again.difficulty = _nextDifficulty(lastD, Rating.again.val);
s.again.stability = _nextForgetStability(lastD, lastS, retrievability);
s.hard.difficulty = _nextDifficulty(lastD, Rating.Hard.val);
s.hard.difficulty = _nextDifficulty(lastD, Rating.hard.val);
s.hard.stability =
_nextRecallStability(lastD, lastS, retrievability, Rating.Hard);
s.good.difficulty = _nextDifficulty(lastD, Rating.Good.val);
_nextRecallStability(lastD, lastS, retrievability, Rating.hard);
s.good.difficulty = _nextDifficulty(lastD, Rating.good.val);
s.good.stability =
_nextRecallStability(lastD, lastS, retrievability, Rating.Good);
s.easy.difficulty = _nextDifficulty(lastD, Rating.Easy.val);
_nextRecallStability(lastD, lastS, retrievability, Rating.good);
s.easy.difficulty = _nextDifficulty(lastD, Rating.easy.val);
s.easy.stability =
_nextRecallStability(lastD, lastS, retrievability, Rating.Easy);
_nextRecallStability(lastD, lastS, retrievability, Rating.easy);
}
}
64 changes: 31 additions & 33 deletions lib/src/models.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
// ignore_for_file: constant_identifier_names

import 'dart:core';
import 'dart:math';
import 'dart:convert';

enum State {
New(0),
Learning(1),
Review(2),
Relearning(3);
newState(0),
learning(1),
review(2),
relearning(3);

const State(this.val);

final int val;
}

enum Rating {
Again(1),
Hard(2),
Good(3),
Easy(4);
again(1),
hard(2),
good(3),
easy(4);

const Rating(this.val);

Expand Down Expand Up @@ -55,7 +53,7 @@ class Card {
int scheduledDays = 0;
int reps = 0;
int lapses = 0;
State state = State.New;
State state = State.newState;
late DateTime lastReview;

@override
Expand Down Expand Up @@ -97,7 +95,7 @@ class Card {
const decay = -0.5;
final factor = pow(0.9, 1 / decay) - 1;

if (state == State.Review) {
if (state == State.review) {
final elapsedDays =
(now.difference(lastReview).inDays).clamp(0, double.infinity).toInt();
return pow(1 + factor * elapsedDays / stability, decay).toDouble();
Expand Down Expand Up @@ -128,21 +126,21 @@ class SchedulingCards {
}

void updateState(State state) {
if (state == State.New) {
again.state = State.Learning;
hard.state = State.Learning;
good.state = State.Learning;
easy.state = State.Review;
} else if (state == State.Learning || state == State.Relearning) {
if (state == State.newState) {
again.state = State.learning;
hard.state = State.learning;
good.state = State.learning;
easy.state = State.review;
} else if (state == State.learning || state == State.relearning) {
again.state = state;
hard.state = state;
good.state = State.Review;
easy.state = State.Review;
} else if (state == State.Review) {
again.state = State.Relearning;
hard.state = State.Review;
good.state = State.Review;
easy.state = State.Review;
good.state = State.review;
easy.state = State.review;
} else if (state == State.review) {
again.state = State.relearning;
hard.state = State.review;
good.state = State.review;
easy.state = State.review;
again.lapses++;
}
}
Expand All @@ -163,21 +161,21 @@ class SchedulingCards {

Map<Rating, SchedulingInfo> recordLog(Card card, DateTime now) {
return {
Rating.Again: SchedulingInfo(
Rating.again: SchedulingInfo(
again,
ReviewLog(Rating.Again, again.scheduledDays, card.elapsedDays, now,
ReviewLog(Rating.again, again.scheduledDays, card.elapsedDays, now,
card.state)),
Rating.Hard: SchedulingInfo(
Rating.hard: SchedulingInfo(
hard,
ReviewLog(Rating.Hard, hard.scheduledDays, card.elapsedDays, now,
ReviewLog(Rating.hard, hard.scheduledDays, card.elapsedDays, now,
card.state)),
Rating.Good: SchedulingInfo(
Rating.good: SchedulingInfo(
good,
ReviewLog(Rating.Good, good.scheduledDays, card.elapsedDays, now,
ReviewLog(Rating.good, good.scheduledDays, card.elapsedDays, now,
card.state)),
Rating.Easy: SchedulingInfo(
Rating.easy: SchedulingInfo(
easy,
ReviewLog(Rating.Easy, easy.scheduledDays, card.elapsedDays, now,
ReviewLog(Rating.easy, easy.scheduledDays, card.elapsedDays, now,
card.state)),
};
}
Expand Down
16 changes: 8 additions & 8 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import './models.dart';

void printSchedulingCards(Map<Rating, SchedulingInfo> schedulingCards) {
print("again.card: ${schedulingCards[Rating.Again]?.card}");
print("again.reviewLog: ${schedulingCards[Rating.Again]?.reviewLog}");
print("hard.card: ${schedulingCards[Rating.Hard]?.card}");
print("hard.reviewLog: ${schedulingCards[Rating.Hard]?.reviewLog}");
print("good.card: ${schedulingCards[Rating.Good]?.card}");
print("good.reviewLog: ${schedulingCards[Rating.Good]?.reviewLog}");
print("easy.card: ${schedulingCards[Rating.Easy]?.card}");
print("easy.reviewLog: ${schedulingCards[Rating.Easy]?.reviewLog}");
print("again.card: ${schedulingCards[Rating.again]?.card}");
print("again.reviewLog: ${schedulingCards[Rating.again]?.reviewLog}");
print("hard.card: ${schedulingCards[Rating.hard]?.card}");
print("hard.reviewLog: ${schedulingCards[Rating.hard]?.reviewLog}");
print("good.card: ${schedulingCards[Rating.good]?.card}");
print("good.reviewLog: ${schedulingCards[Rating.good]?.reviewLog}");
print("easy.card: ${schedulingCards[Rating.easy]?.card}");
print("easy.reviewLog: ${schedulingCards[Rating.easy]?.reviewLog}");
print("");
}
Loading

0 comments on commit 0f100ff

Please sign in to comment.