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

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

Open
fwimp opened this issue Sep 2, 2024 · 4 comments

Comments

@fwimp
Copy link

fwimp commented Sep 2, 2024

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
Copy link
Collaborator

lentinj commented Sep 2, 2024

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
Copy link
Member

hyanwong commented Sep 2, 2024

Thanks. Well spotted. Should be an easy fix.

@fwimp
Copy link
Author

fwimp commented Sep 2, 2024

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

@fwimp
Copy link
Author

fwimp commented Sep 3, 2024

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):

ret = dict(
header = {k:i for i,k in enumerate(colnames)},
max_taxa_in = max_otts,
max_taxa_out = max_n,
tot_spp = db.executesql("SELECT leaf_rgt FROM ordered_nodes WHERE id = 1;")[0][0]
)

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.

else:
#this turns out to be a little more complicated in SQL terms, because for speed we probably want to sort
#ordered_nodes and ordered_leaves separately then UNION them together. This is easier to do in vanilla SQL
if queryvar_is_true("names"):
extracol = ", name"
ret['header']={k:i for i,k in enumerate(["ott","popularity","popularity_rank","name"])}
else:
extracol = ""
ret['header']={k:i for i,k in enumerate(["ott","popularity","popularity_rank"])}

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.

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

3 participants