Skip to content

Commit

Permalink
Merge pull request #19 from open-spaced-repetition/feat-access-level
Browse files Browse the repository at this point in the history
feat: access level
  • Loading branch information
ningkaiqiang authored Nov 16, 2024
2 parents 9e0bc91 + da1c9d0 commit 16afd57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Sources/FSRS/Algorithm/FSRS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class FSRS: FSRSAlgorithm {
* const recordLogItem = f.repeat(card, new Date(), Rating.Again, nextAfterHandler);
* ```
*/
func next(
public func next(
card: Card,
now: Date,
grade: Rating,
Expand Down Expand Up @@ -220,7 +220,7 @@ public class FSRS: FSRSAlgorithm {
* const rollbackFromAfterHandler = f.rollback(card, log, cardAfterHandler);
* ```
*/
func rollback(
public func rollback(
card: Card,
log: ReviewLog,
completion: ((Card) -> Card)? = nil
Expand Down Expand Up @@ -319,7 +319,7 @@ public class FSRS: FSRSAlgorithm {
* const forgetFromAfterHandler = f.forget(card, date_scheduler(now, 1, true), false, forgetAfterHandler);
* ```
*/
func forget(
public func forget(
card: Card,
now: Date,
resetCount: Bool = false,
Expand Down Expand Up @@ -394,7 +394,7 @@ public class FSRS: FSRSAlgorithm {
console.log(results_short)
* ```
*/
func reschedule(
public func reschedule(
currentCard: Card,
reviews: [ReviewLog],
options: RescheduleOptions
Expand Down
51 changes: 28 additions & 23 deletions Sources/FSRS/Models/FSRSModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum CardState: Int, Codable {
public enum Rating: Int, Codable, Equatable, CaseIterable {
case manual = 0, again = 1, hard, good, easy

var stringValue: String {
public var stringValue: String {
switch self {
case .manual: return "manual"
case .again: return "again"
Expand All @@ -36,16 +36,16 @@ public enum Rating: Int, Codable, Equatable, CaseIterable {
}
}

public struct ReviewLog: Equatable, Codable {
var rating: Rating // Rating of the review (Again, Hard, Good, Easy)
var state: CardState? // State of the review (New, Learning, Review, Relearning)
var due: Date? // Date of the last scheduling
var stability: Double? // Memory stability during the review
var difficulty: Double? // Difficulty of the card during the review
var elapsedDays: Double // Number of days elapsed since the last review
var lastElapsedDays: Double // Number of days between the last two reviews
var scheduledDays: Double // Number of days until the next review
var review: Date // Date of the review
public struct ReviewLog: Equatable, Codable, Hashable {
public var rating: Rating // Rating of the review (Again, Hard, Good, Easy)
public var state: CardState? // State of the review (New, Learning, Review, Relearning)
public var due: Date? // Date of the last scheduling
public var stability: Double? // Memory stability during the review
public var difficulty: Double? // Difficulty of the card during the review
public var elapsedDays: Double // Number of days elapsed since the last review
public var lastElapsedDays: Double // Number of days between the last two reviews
public var scheduledDays: Double // Number of days until the next review
public var review: Date // Date of the review

public init(
rating: Rating,
Expand All @@ -69,7 +69,7 @@ public struct ReviewLog: Equatable, Codable {
self.review = review
}

var newLog: ReviewLog {
public var newLog: ReviewLog {
ReviewLog(
rating: rating,
state: state,
Expand All @@ -84,7 +84,7 @@ public struct ReviewLog: Equatable, Codable {
}
}

public struct Card: Equatable, Codable {
public struct Card: Equatable, Codable, Hashable {
public var due: Date // Date when the card is next due for review
public var stability: Double // A measure of how well the information is retained
public var difficulty: Double // Reflects the inherent difficulty of the card content
Expand Down Expand Up @@ -117,7 +117,7 @@ public struct Card: Equatable, Codable {
self.lastReview = lastReview
}

var newCard: Card {
public var newCard: Card {
Card(
due: due,
stability: stability,
Expand All @@ -143,19 +143,24 @@ public struct Card: Equatable, Codable {
}
}

public struct RecordLogItem: Codable, Equatable {
public struct RecordLogItem: Codable, Equatable, Hashable {
public var card: Card
var log: ReviewLog
public var log: ReviewLog

public init(card: Card, log: ReviewLog) {
self.card = card
self.log = log
}
}

public typealias RecordLog = [Rating: RecordLogItem]

public struct FSRSParameters: Codable, Equatable {
var requestRetention: Double
var maximumInterval: Double
var w: [Double]
var enableFuzz: Bool
var enableShortTerm: Bool
public var requestRetention: Double
public var maximumInterval: Double
public var w: [Double]
public var enableFuzz: Bool
public var enableShortTerm: Bool

public init(
requestRetention: Double? = nil,
Expand All @@ -178,11 +183,11 @@ public struct FSRSReview: Codable {
* 0-4: Manual, Again, Hard, Good, Easy
* = revlog.rating
*/
var rating: Rating
public var rating: Rating
/**
* The number of days that passed
* = revlog.elapsed_days
* = round(revlog[-1].review - revlog[-2].review)
*/
var deltaT: Double
public var deltaT: Double
}

0 comments on commit 16afd57

Please sign in to comment.