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

histogram widget filter is sending wrong bounds #926

Closed
javisantana opened this issue Dec 11, 2015 · 4 comments
Closed

histogram widget filter is sending wrong bounds #926

javisantana opened this issue Dec 11, 2015 · 4 comments

Comments

@javisantana
Copy link
Contributor

When you filter using the last bucket in a histogram bucket the filter sends wrong bounds, for example:

the buckets goes from 400 to 500, you filter it and the filter sent to the tiler is [400, 499.9999] so rows with 500 are kept out.

how to reproduce:

@javierarce
Copy link
Contributor

I'm afraid those values are calculated in the backend. The frontend picks the values from the data model using the lower and upper index.

/cc @rochoa

@rochoa
Copy link
Contributor

rochoa commented Dec 14, 2015

The problem is the zoomed histogram returns with:

{
  "bin_width": 66.8333333333333,
  "bins_count": 6,
  "bins_start": 99,
  ...
}

So ... 66.8333333333333 * 6 + 99 = 499.9999999999998.

More on this:

$ node
> // https://gist.github.com/rochoa/5b57e57c9694741c4887
> // Following code was extracted from almost-equal
undefined
> // (c) 2013 Mikola Lysenko. MIT License
undefined
> // MIT License (MIT)
undefined
> // See https://github.com/scijs/almost-equal/blob/93af191fe4075ee2dea94d29a26c796c26bb9cb6/almost_equal.js
undefined
>
undefined
> var PRECISION_FLOAT_EPSILON = 1.19209290e-7;
undefined
> var PRECISION_DOUBLE_EPSILON = 2.2204460492503131e-16;
undefined
>
undefined
> function almostEqual(a, b, absoluteError, relativeError) {
...     absoluteError = absoluteError || PRECISION_DOUBLE_EPSILON;
...     relativeError = relativeError || PRECISION_DOUBLE_EPSILON;
...
...     var d = Math.abs(a - b);
...     if(d <= absoluteError) {
...         return true;
...     }
...     if(d <= relativeError * Math.min(Math.abs(a), Math.abs(b))) {
...         return true;
...     }
...
...     return a === b;
... }
undefined
> almostEqual(66.8333333333333 * 6 + 99, 500, PRECISION_FLOAT_EPSILON, PRECISION_FLOAT_EPSILON)
true

@rochoa
Copy link
Contributor

rochoa commented Dec 14, 2015

Just by changing the selection to:

Uploading Screen Shot 2015-12-14 at 12.17.40.png…

You get rid of the precision problem because you get:

{
  "bin_width": 52,
  "bins_count": 6,
  "bins_start": 188,
  ...
}

In this case: 52 * 6 + 188 = 500.

We might not have a good solution here if we don't want to change the way the bin width is being calculated.

@nobuti
Copy link
Contributor

nobuti commented Nov 16, 2016

There has been no activity on this issue for several months and that's why we are closing it (automatically). If you think this still needs to be addressed please reopen it. The good news is that we are now working on the next version of CARTO.js, stay tuned.

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

4 participants