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

OHLC equal open close cases fix #1655

Merged
merged 8 commits into from
Jun 8, 2017
Merged

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented May 8, 2017

supersedes @noway's #1619 with tests and lint fixes.

@noway does the test case look ok to you?

switch(direction) {
case 'increasing':
return function(o, c) { return o <= c; };
fn = function(o, c) {
if(o === c) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't cast to numbers, have we? Looks like this will break if we mix strings and numbers (or use different string representations of the same number, like '2.0' and '2.00'

I guess a point should get dropped if any of o, h, l, c is not numeric?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked all to ensure they're numeric in 597adf9

}
}
return o > c;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of duplication with just a few true <-> false flips... looks like we could keep the perf up without the duplication if we made one function isIncreasing(o, c), which looks at a state var isPrevIncreasing (which would also simplify the logic there as we wouldn't need to deal with null, just initialize it to true), then move the switch logic into creating the wrapper function below:

function increasingFilter(o, c) {
    var isThisIncreasing = isIncreasing(o, c);
    isPrevIncreasing = isThisIncreasing; // why add !! to this?
    cPrev = c;
    return isThisIncreasing;
}

function decreasingFilter(o, c) {
    var isThisIncreasing = isIncreasing(o, c);
    isPrevIncreasing = isThisIncreasing; // why add !! to this?
    cPrev = c;
    return !isThisIncreasing; // the only difference...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson I vaguely remember you mentioning on slack that you had a commit implementing your solution on a branch. If that's not case, I'll try to push something up to get this PR in this week's 1.28.0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplified these filters (even more than ^^) in 9575ab6

@etpinard etpinard added this to the 1.28.0 milestone May 18, 2017
@alexcjohnson
Copy link
Collaborator

hah, the test failure is a real bug that's fixed by 597adf9
old version has a light green bar:
screen shot 2017-06-08 at 4 50 44 pm
new version it's pink:
screen shot 2017-06-08 at 4 50 20 pm
because '99' > '100' while 99 < 100

@etpinard
Copy link
Contributor Author

etpinard commented Jun 8, 2017

hah, the test failure is a real bug that's fixed by 597adf9

Nice 🎉

}

function isDecreasing(o, c) {
return isNumeric(o) && isNumeric(c) && !_isIncreasing(+o, +c);
Copy link
Contributor Author

@etpinard etpinard Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that !_isIncreasing statement is so brilliant ✨

@etpinard
Copy link
Contributor Author

etpinard commented Jun 8, 2017

💃

Thanks very much for taking this one to the finish line 🏎️ 🏁

@alexcjohnson alexcjohnson merged commit 2b831a0 into master Jun 8, 2017
@alexcjohnson alexcjohnson deleted the pr-1619-ohlc-equal-open-close branch June 8, 2017 21:12
@noway
Copy link
Contributor

noway commented Jun 11, 2017

Haven't had a chance to look into it all, but thank you for seeing it all through 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants