OZtree icon indicating copy to clipboard operation
OZtree copied to clipboard

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

Open fwimp opened this issue 1 year ago • 4 comments

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},...}

fwimp avatar Sep 02 '24 15:09 fwimp

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.

lentinj avatar Sep 02 '24 15:09 lentinj

Thanks. Well spotted. Should be an easy fix.

hyanwong avatar Sep 02 '24 17:09 hyanwong

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

fwimp avatar Sep 02 '24 22:09 fwimp

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.

fwimp avatar Sep 03 '24 12:09 fwimp