OneZoom / OZtree

OneZoom Tree of Life Explorer
Other
91 stars 20 forks source link

`header` return value from `popularity/list` API endpoint does not include a name for raw popularity data. #875

Open fwimp opened 2 months ago

fwimp commented 2 months ago

If you hit the popularity endpoint, it does not return a header value for popularity_raw even when you request it by specifying include_raw.

For example

https://www.onezoom.org/popularity/list?otts=247341,563159,269666,504327,668392&key=0&expand_taxa=0&spread_taxa_evenly=0&taxon_names=0&include_raw=1

returns

{"header":{"ott":0,"popularity":1,"popularity_rank":2},...}

When it should return

{"header":{"ott":0,"popularity":1,"popularity_rank":2, "raw_popularity":3},...}
lentinj commented 2 months ago

It works with expand_taxa=1, e.g: https://www.onezoom.org/popularity/list?otts=247341,563159,269666,504327,668392&key=0&expand_taxa=1&spread_taxa_evenly=0&taxon_names=0&include_raw=1

Not sure if this is helps you out, but at least helps pinpoint where the bug is.

hyanwong commented 2 months ago

Thanks. Well spotted. Should be an easy fix.

fwimp commented 2 months ago

Updated the initial example to have an example consistent with what is returned when expand_taxa=1

fwimp commented 2 months ago

Looks like the issue here is from a hardcoded list of column names in the popularity controller

If queryvar_is_true("expand_taxa") is set to True then the default header column constructed beforehand is used (as there is nothing that resets it in the ret dictionary): https://github.com/OneZoom/OZtree/blob/118bfba9b122d812386e438fb6d6b29cb51aed7e/controllers/popularity.py#L192-L197

However if queryvar_is_true("expand_taxa") is set to False, that branch resets the header entry of ret using a hardcoded list, which does not account for the possibility that include_raw is True.

https://github.com/OneZoom/OZtree/blob/118bfba9b122d812386e438fb6d6b29cb51aed7e/controllers/popularity.py#L262-L270

I thiiiink that lines 265-270 can just be deleted as they also have an unused variable that looks like it was there from some old code.