Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OptimumInterval output is NaN value. #6

Open
my-yy opened this issue Jan 1, 2021 · 0 comments
Open

OptimumInterval output is NaN value. #6

my-yy opened this issue Jan 1, 2021 · 0 comments

Comments

@my-yy
Copy link

my-yy commented Jan 1, 2021

I want to use this project as a js library, but I found the output optimumInterval sometimes can be a NaN value:
When I put three review histories into it:
mark=5,date=now
mark=3,date=now+10days
mark=3,date=now+100days

the final optimumInterval will be a NaN value:

repetition:0,date:2021-01-01,mark:5,optimumInterval:4.0 hour

repetition:1,date:2021-01-11,mark:3,optimumInterval:59.2 days

repetition:2,date:2021-04-11,mark:3,optimumInterval:NaN days

code to reproduce this issue:


const sm_util = require("./sm.js")
const sm = new sm_util.SM()
const ONE_DAY = 24 * 3600 * 1000

function mytest() {
    const now = new Date().getTime()

    const item = sm.addItem("")

    answer_core(5, item, new Date(now))

    answer_core(3, item, new Date(now + ONE_DAY * 10))

    answer_core(3, item, new Date(now + ONE_DAY * 100))
}

function answer_core(mark, item, date) {
    sm.answer(mark, item, date)
    const data = item.data()
    const optimumInterval = format_interval(data["optimumInterval"])
    const repetition = data["repetition"]
    console.log(`repetition:${repetition},date:${formatDate(date)},mark:${mark},optimumInterval:${optimumInterval}`)
}

function format_interval(optimumInterval) {
    let days = optimumInterval / 24 / 3600 / 1000
    if (days < 1.0) {
        days = (optimumInterval / 1000 / 3600).toFixed(1) + " hour"
    } else {
        days = days.toFixed(1) + " days"
    }
    return days
}

function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2)
        month = '0' + month;
    if (day.length < 2)
        day = '0' + day;

    return [year, month, day].join('-');
}

mytest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant