## sm2 0.1.4

Implementation of SM-2 in DART.

SM-2 is a simple spaced repetition algorithm. It calculates the number of days to wait before reviewing a piece of information based on how easily the the information was remembered today.

# The algorithm requires four inputs #

The algorithm requires four inputs: `quality`, `repetitions`, `previous ease factor`, and `previous interval`. The last three inputs are taken from the output of a previous call to SM-2. (On the first call, default values are used.)

## Quality #

An integer from 0-5 indicating how easily the information was remembered today. This could correspond to a button such as "Difficult" or "Very Easy."

The official algorithm description explains the meaning of each number:

``````5 - perfect response
4 - correct response after a hesitation
3 - correct response recalled with serious difficulty
2 - incorrect response; where the correct one seemed easy to recall
1 - incorrect response; the correct one remembered
0 - complete blackout.
``````

## Repetitions (integer) #

The number of times the information has been reviewed prior to this review. `repetitions` should equal zero for the first review.

SM-2 uses this value to define specific intervals for the first and second reviews. SM-2 will also reset this value to zero when `quality` is less than 3.

## Previous ease factor (float) #

A floating point number (≥ 1.3) generated by the last iteration of the SM-2 algorithm. `previous ease factor` should equal 2.5 for the first review.

The ease factor is used to determine the number of days to wait before reviewing again. Each call to SM-2 adjusts this number up or down based on `quality`.

## Previous interval (integer) #

Generated by the last iteration of the SM-2 algorithm. Indicates the number of days to wait between reviews.

This previous interval is used when calculating the new interval. `previous interval` should equal zero for the first review.

# Outputs #

The algorithm returns three outputs: `interval`, `repetitions`, and `ease factor`. All three values should be saved and passed to the next call to SM-2 as inputs.

## Interval (integer) #

An integer number indicating the number of days to wait before the next review.

## Repetitions (integer) #

The number of times the the information has been reviewed as of this review.

This value is maintained between calls to the algorithm and used for calculating `interval`. The number increments after each successful review. SM-2 will reset `repetitions` to zero if `quality` is less than 3.

## Ease factor #

A floating point number (≥ 1.3) which is adjusted up or down based on how easily the information was remembered.

This value is maintained between calls to the algorithm and is used for calculating `interval`.

# Steps #

If `quality` is greater than or equal to 3, indicating a correct response:

1. If `repetitions` is 0 (first review), set `interval` to 1 day.
2. If `repetitions` is 1 (second review), set `interval` to 6 days.
3. If `repetitions` is greater than 1 (subsequent reviews), set `interval` to `previous interval * previous ease factor`. (See note about recursion below.)
4. Round `interval` up to the next whole number.
5. Increment `repetitions` by 1.
6. Set `ease factor` to `previous ease factor + (0.1 - (5 - quality) * (0.08 + (5 - quality ) * 0.02))`. (See formula description below.)

If `quality` is less than 3, indicating an incorrect response:

1. Set `repetitions` to 0.
2. Set `interval` to 1.
3. Set `ease factor` to `previous ease factor` (no change).

If `ease factor` is less than 1.3:

1. Set `ease factor` to 1.3.

Return `interval`, `repetitions` and `ease factor`.

# Ease factor formula #

After the first two reviews, `ease factor` is adjusted using this formula:

`previous ease factor + (0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02))`

The magic numbers come from the official algorithm description.

This increases `ease factor` when `quality` is 5, makes no change when `quality` is 4, and decreases `ease factor` by varying amounts when `quality` is lower than 4. The lower `quality` is, the more `ease factor` is decreased.

## 0.1.0 #

• Initial Open Source release.

example/lib/main.dart

``````import 'package:flutter/material.dart';
import 'package:sm2/main.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {

final sm = Sm();

@override
@override
Widget build(BuildContext context) {
SmResponse smResponse = sm.calc(
quality: 0,
repetitions: 0,
previousInterval: 2.5,
previousEaseFactor: 0
);
return Scaffold(
appBar: AppBar(
title: Text('Spaced Repetition'),
centerTitle: true,
),
body: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Repetitions: \${smResponse.repetitions}"),
Text("Interval: \${smResponse.interval}"),
Text("Ease Factor: \${smResponse.easeFactor}")
],
),
),
);
}
}
``````

## Use this package as a library

### 1. Depend on it

``````
dependencies:
sm2: ^0.1.4

``````

### 2. Install it

You can install packages from the command line:

with Flutter:

``````
\$ flutter pub get

``````

Alternatively, your editor might support `flutter pub get`. Check the docs for your editor to learn more.

### 3. Import it

Now in your Dart code, you can use:

``````
import 'package:sm2/sm2.dart';
``````
 Popularity: Describes how popular the package is relative to other packages. [more] 27 Health: Code health derived from static analysis. [more] 100 Maintenance: Reflects how tidy and up-to-date the package is. [more] 90 Overall: Weighted score of the above. [more] 61

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

• Dart: 2.7.1
• pana: 0.13.6
• Flutter: 1.12.13+hotfix.8

#### Health suggestions

Format `lib/sm2.dart`.

Run `flutter format` to format `lib/sm2.dart`.

#### Maintenance issues and suggestions

Make sure `dartdoc` successfully runs on your package's source files. (-10 points)

exitCode: 255 stdout: parsing /tmp/pub-dartlang-dartdocSKJVWC/pkg/lib/SmResponse.dart... parsing /tmp/pub-dartlang-dartdocSKJVWC/pkg/lib/main.dart... parsing /tmp/pub-dartlang-dartdocSKJVWC/pkg/lib/sm2.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/collection/collection.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/developer/developer.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/internal/internal.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/_interceptors/interceptors.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/io/io.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/isolate/isolate.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/convert/convert.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/async/async.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/typed_data/typed_data.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/_empty.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/js_util/js_util_dart2js.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/html/html_dart2js.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/math/math.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/core/core.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/_http/http.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/ui/ui.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/js/js_dart2js.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/ffi/ffi.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/wasm/wasm.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/_interceptors/js_array.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/_interceptors/js_number.dart... parsing /flutter/bin/cache/pkg/sky_engine/lib/_interceptors/js_string.dart... Initialized dartdoc with 22 libraries in 24.7 seconds documenting sm2 Generating docs for library SmResponse from package:sm2/SmResponse.dart... Generating docs for library sm2 from package:sm2/main.dart... Generating docs for library sm2 from package:sm2/sm2.dart... Validating docs... Documented 3 public libraries in 1.2 seconds stderr: Documenting sm2... warning: no canonical library found for SmResponse.SmResponse.hashCode, not linking, from SmResponse.SmResponse.hashCode: (file:///flutter/bin/cache/pkg/sky_engine/lib/core/object.dart:94:20) warning: no canonical library found for SmResponse.SmResponse.runtimeType, not linking, from SmResponse.SmResponse.runtimeType: (file:///flutter/bin/cache/pkg/sky_engine/lib/core/object.dart:116:21) warning: no canonical library found for SmResponse.SmResponse.noSuchMethod, not linking, from SmResponse.SmResponse.noSuchMethod: (file:///flutter/bin/cache/pkg/sky_engine/lib/core/object.dart:111:20) warning: no canonical library found for SmResponse.SmResponse.toString, not linking, from SmResponse.SmResponse.toString: (file:///flutter/bin/cache/pkg/sky_engine/lib/core/object.dart:99:19) warning: no canonical library found for SmResponse.SmResponse.==, not linking, from SmResponse.SmResponse.==: (file:///flutter/bin/cache/pkg/sky_engine/lib/core/object.dart:62:26) warning: sm2 has no library level documentation comments, from sm2: (file:///tmp/pub-dartlang-dartdocSKJVWC/pkg/lib/main.dart:1:9) error: failed to write file at: sm2/sm2-library.html for symbol sm2: (file:///tmp/pub-dartlang-dartdocSKJVWC/pkg/lib/sm2.dart:1:1) conflicting with file already generated by sm2: (file:///tmp/pub-dartlang-dartdocSKJVWC/pkg/lib/main.dart:1:9) Dartdoc generates a path and filename to write to for each symbol. sm2 conflicts with another symbol in the generated path, and therefore can not be written out. Changing the name, library name, or class name (if appropriate) of one of the conflicting items can resolve the conflict. Alternatively, use the @nodoc tag in one symbol's documentation comments to hide it. found 6 warnings and 1 error Unhandled exception: dartdoc encountered 1 errors while processing. #0 Dartdoc.generateDocs (package:dartdoc/dartdoc.dart:202:7)

#### Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test