Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into 51-streak-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alanxoc3 committed Sep 30, 2020
2 parents 1957ff7 + 817315f commit 486d6c4
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 105 deletions.
13 changes: 0 additions & 13 deletions internal/file/argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ type Config struct {
Files []string
}

// For debugging
func (c *Config) String() string {
return fmt.Sprintf(`IsReview %t
IsMemorize %t
IsDone %t
IsPrint %t
IsStream %t
Editor "%s"
Number %d
MetaFile "%s"
Files %s`, c.IsReview, c.IsMemorize, c.IsDone, c.IsPrint, c.IsStream, c.Editor, c.Number, c.MetaFile, c.Files)
}

func getDefaultEditor() string {
if val, present := os.LookupEnv("EDITOR"); present {
return val
Expand Down
13 changes: 13 additions & 0 deletions internal/hash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package internal_test

import (
"testing"

"github.com/alanxoc3/concards/internal"
"github.com/stretchr/testify/assert"
)

func TestNewHash(t *testing.T) {
h := internal.NewHash("a")
assert.Equal(t, "a0000000000000000000000000000000", h.String())
}
4 changes: 0 additions & 4 deletions internal/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func (h Hash) String() string {
return fmt.Sprintf("%x", [16]byte(h))
}

func (h Hash) IsZero() bool {
return [16]byte{} == [16]byte(h)
}

func AssertLogic(condition bool, message string) {
if !condition {
panic(fmt.Sprintf("Logic Error: %s\nPlease report this at: https://github.com/alanxoc3/concards/issues", message))
Expand Down
8 changes: 0 additions & 8 deletions internal/meta/algs.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package meta

type algFunc func(Outcome) float64
type AnswerClassification uint8

const (
YesWasYes AnswerClassification = 1 << iota
YesWasNo
NoWasYes
NoWasNo
)

// TODO: Remove this with GH-45.
var algs = map[string]algFunc{
Expand Down
46 changes: 13 additions & 33 deletions internal/meta/outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,24 @@ func NewOutcomeFromStrings(strs ...string) *Outcome {
}
}

func (r *Outcome) AnswerClassification() AnswerClassification {
if r.target {
if r.streak < 0 {
return YesWasNo
} else {
return YesWasYes
}
} else {
if r.streak > 0 {
return NoWasYes
} else {
return NoWasNo
}
}
}

func (r *Outcome) PredYesCount() int { return r.newCount(true, r.yesCount) }
func (r *Outcome) PredNoCount() int { return r.newCount(false, r.noCount) }
func (r *Outcome) PredStreak() int {
// Streak Logic
streak := r.streak
switch r.AnswerClassification() {
case YesWasYes:
streak++
case NoWasNo:
streak--
default:
streak = 0
}
return streak
if r.target && r.streak >= 0 {
return r.streak + 1
} else if !r.target && r.streak <= 0 {
return r.streak - 1
} else {
return 0
}
}

func (r *Outcome) Target() bool { return r.target }

func (r *Outcome) PredYesCount() int { return r.newCount(true, r.yesCount) }
func (r *Outcome) PredNoCount() int { return r.newCount(false, r.noCount) }
func (r *Outcome) String() string {
return fmt.Sprintf("%s %s", r.base.String(), r.targetStr())
}

func (r *Outcome) targetStr() string {
if r.target {
return "1"
Expand All @@ -77,10 +61,6 @@ func (r *Outcome) targetStr() string {
}
}

func (r *Outcome) String() string {
return fmt.Sprintf("%s %s", r.base.String(), r.targetStr())
}

func (r *Outcome) newCount(expecting bool, count int) int {
if expecting == r.target {
count++
Expand Down
22 changes: 0 additions & 22 deletions internal/meta/outcome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,3 @@ func TestOutcomeTargetFalse(t *testing.T) {
r := meta.NewOutcomeFromStrings("ff000000000000000000000000000000", "2020-01-01T00:00:00Z", "2020-01-01T00:00:00Z", "2", "2", "1", "0")
assert.False(t, r.Target())
}

func TestOutcomeAnswerClassification(t *testing.T) {
tests := []struct {
expect meta.AnswerClassification
expectStreak int
streak string
answer string
}{
{meta.YesWasYes, 2, "1", "1"},
{meta.YesWasNo, 0, "-1", "1"},
{meta.NoWasYes, 0, "1", "0"},
{meta.NoWasNo, -2, "-1", "0"},
{meta.YesWasYes, 1, "0", "1"},
{meta.NoWasNo, -1, "0", "0"},
}

for _, v := range tests {
r := meta.NewOutcomeFromStrings("", "", "", "2", "2", v.streak, v.answer)
assert.Equal(t, v.expect, r.AnswerClassification())
assert.Equal(t, v.expectStreak, r.PredStreak())
}
}
31 changes: 15 additions & 16 deletions internal/meta/sm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ import (
// Modified SM2 Algorithm
// Returns the duration in nanoseconds for when to review the card next.
func sm2Exec(r Outcome) float64 {
ac := r.AnswerClassification()
period := 0.0
rank := math.Max(1.3, 2.5+.11*float64(r.YesCount())-.29*float64(r.NoCount())+.06*float64(r.Streak()))

// Next Day Logic
if ac == YesWasYes {
if r.Streak() == 0 {
period += float64(time.Hour * 24)
} else {
period += float64(time.Hour * 24 * 6)
}
if r.Target() {
if r.Streak() < 0 {
period = float64(time.Minute * 5)
} else if r.Streak() == 0 {
period += float64(time.Hour * 24)
} else if r.Streak() > 0 {
period += float64(time.Hour * 24 * 6)
}

if r.Streak() >= 2 {
for i := 2; i <= r.Streak(); i++ {
period *= rank
}
}
} else if ac == YesWasNo {
period = float64(time.Minute * 5)
} else {
if r.Streak() >= 2 {
for i := 2; i <= r.Streak(); i++ {
period *= rank
}
}
} else {
period = float64(time.Minute * 1)
}
}

// Add some noise, so everything doesn't get reviewed at the same time.
return period * (1 + .1*rand.Float64())
Expand Down
5 changes: 0 additions & 5 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ type Outcome = meta.Outcome
func MockOutcome(strs ...string) *Outcome {
return meta.NewOutcomeFromStrings(strs...)
}

const YesWasYes meta.AnswerClassification = meta.YesWasYes
const YesWasNo meta.AnswerClassification = meta.YesWasNo
const NoWasYes meta.AnswerClassification = meta.NoWasYes
const NoWasNo meta.AnswerClassification = meta.NoWasNo
5 changes: 1 addition & 4 deletions plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ import (
)

func TestApi(t *testing.T) {
assert.Equal(t, plugin.YesWasYes, plugin.MockOutcome("", "", "", "2", "2", "1", "1").AnswerClassification())
assert.Equal(t, plugin.YesWasNo, plugin.MockOutcome("", "", "", "2", "2", "-1", "1").AnswerClassification())
assert.Equal(t, plugin.NoWasYes, plugin.MockOutcome("", "", "", "2", "2", "1", "0").AnswerClassification())
assert.Equal(t, plugin.NoWasNo, plugin.MockOutcome("", "", "", "2", "2", "-1", "0").AnswerClassification())
assert.True(t, plugin.MockOutcome("", "", "", "", "", "", "1").Target())
}

0 comments on commit 486d6c4

Please sign in to comment.