failin3 / Oddsmatcher

Tool to help match odds of bookmakers with exchanges
https://www.rickproductions.nl/oddsmatcher/
1 stars 0 forks source link

Frontend: Calculator doesn't start at the optimal point when filling in back stake later #15

Closed failin3 closed 3 years ago

failin3 commented 3 years ago

Especially annoying when using the "go" feature of the oddsmatcher, makes the feature kind of useless.

Not sure where the problem lies but should be fixed quickly.

failin3 commented 3 years ago

The bug is caused by the step size, when the step size is too small, it can't be set exactly at 50, which causes the bug.

failin3 commented 3 years ago

This seems to fix it

if (((slider.value >= 49.5 && slider.value <= 50) || (slider.value <= 50.5 && slider.value >= 50)) && (set_back_stake != back_stake)) {
        set_back_stake = back_stake;
        if (Math.abs((50/slider.step).toFixed(0)*slider.step - 50) <= Math.abs((50/slider.step + 1).toFixed(0)*slider.step - 50)) {
            //Closer to first than second
            console.log("true");
            slider.value = (50/slider.step).toFixed(0)*slider.step;
        } else {
            //Closer to second than first
            console.log("false");
            slider.value = (50/slider.step).toFixed(0)*slider.step+slider.step;
        }

Very ugly and not understandable, but it seems to work, needs some testing still

failin3 commented 3 years ago

This seems to fix it

if (((slider.value >= 49.5 && slider.value <= 50) || (slider.value <= 50.5 && slider.value >= 50)) && (set_back_stake != back_stake)) {
        set_back_stake = back_stake;
        if (Math.abs((50/slider.step).toFixed(0)*slider.step - 50) <= Math.abs((50/slider.step + 1).toFixed(0)*slider.step - 50)) {
            //Closer to first than second
            console.log("true");
            slider.value = (50/slider.step).toFixed(0)*slider.step;
        } else {
            //Closer to second than first
            console.log("false");
            slider.value = (50/slider.step).toFixed(0)*slider.step+slider.step;
        }

Very ugly and not understandable, but it seems to work, needs some testing still

Might have to explain what's happening, when you change the step size, the slider starts from 0 and takes steps to reach 50, this however is not always possible when the step size isn't a round number or divisor of 50. What this code does is check if the back_stake has been changed, then checks if the slider is very close to 50 (because of the step size it cant be exactly 50).

If this is the case, it will check whether floor(50/slider.step) * slider.step or (floor(50/slider.step)+1) * slider.step is closer to 50, then it sets the value of the slider to this value. In other words, it checks which step option is closest to 50, and set that one as the value of the slider.