anvio icon indicating copy to clipboard operation
anvio copied to clipboard

[BUG] Search with operators in the interactive interface

Open FlorianTrigodet opened this issue 1 year ago • 5 comments

Short description of the problem

In the interactive interface, we can search for items matching an operator formula. And it does not work with large numbers somewhat.

anvi'o version

anvi'o v8

Detailed description of the issue

With this table: toto.txt

anvi-interactive --manual -d toto.txt -p PROFILE.db

The search works when I search for values > 70,000: Screenshot 2023-10-23 at 15 45 22

But it fails when I search for values > 2,000,000, it reports too many things including values not matching my condition?: Screenshot 2023-10-23 at 15 45 36

No idea what is happing here 🤷

FlorianTrigodet avatar Oct 23 '23 13:10 FlorianTrigodet

lol. weird indeed.

@metehaansever, can you please take a look at this?

meren avatar Oct 23 '23 15:10 meren

@FlorianTrigodet @metehaansever I was looking into this but couldn't reproduce it, has it been fixed and/or can you reproduce it?

Ge0rges avatar Mar 25 '24 20:03 Ge0rges

I will say that generally though something like this would be cleaner/safer than eval():

function evaluateCondition(cellValue, searchValue, operator, operatorText) {
    switch (operator) {
        case '0': // "=="
            return cellValue.toString() === searchValue;
        case '1': // "!="
            return cellValue.toString() !== searchValue;
        case '2': // ">"
            return parseFloat(cellValue) > parseFloat(searchValue);
        case '3': // "<"
            return parseFloat(cellValue) < parseFloat(searchValue);
        case '4': // ">="
            return parseFloat(cellValue) >= parseFloat(searchValue);
        case '5': // "<="
            return parseFloat(cellValue) <= parseFloat(searchValue);
        case '6': // "contains"
            return cellValue.toString().toLowerCase().includes(searchValue.toLowerCase());
        default:
            return; // or throw an error
    }
}

Ge0rges avatar Mar 25 '24 20:03 Ge0rges

Absolutely -- No eval's should ever come close to anywhere near user-provided data.

meren avatar Mar 26 '24 08:03 meren

I realized that using the Eval function posed significant problems, so I replaced it with Function(). However, this didn't resolve the issue. I believe we should reconsider the entire structure from the ground up.

metehaansever avatar Mar 26 '24 08:03 metehaansever