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

Create new methods endpoint #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Implementation of the BRAPI standard for TERRA-REF instance of the BETYdb databa
| /germplasm | cultivars. | |
| /observations | traits | |
| /variables | variables | |
| /methods | methods| |

# Currently implemented endpoints & parameters

Expand Down Expand Up @@ -91,7 +92,12 @@ See [Swagger documentation](http://terraref.org/brapi/v1/ui) for more details
name
observationVariableName
observationVariableDbID
scale
scale
/methods
description
name
observationVariableDbId
observationVariableName

```

Expand Down
3 changes: 2 additions & 1 deletion api/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def search(datatype=None, dataType=None, pageSize=None, page=None):
calls_get_helper('studies/{studyDbId}/germplasm', versions=VERSIONS_1_23),
calls_get_helper('studies/{studyDbId}/layouts', versions=VERSIONS_1_23),
calls_get_helper('trials', versions=VERSIONS_1_23),
calls_get_helper('variables', versions=VERSIONS_1_23)
calls_get_helper('variables', versions=VERSIONS_1_23),
calls_get_helper('methods', versions=VERSIONS_1_23)
]

# filter on datatype
Expand Down
49 changes: 49 additions & 0 deletions api/methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import helper


def search(observationVariableDbId=None, traitClass=None, pageSize=None, page=None):
"""Returns information on methods
Arguments:
observationVariableDbId: specific variable to return information on
traitClass: not implemented
pageSize: the desired size of return pages
page: the number of the page to return (starting at zero)
"""
query = "SELECT id, name, description FROM methods AS m"

params = []

where_clause = " WHERE"

# add a filter on the variable ID
if observationVariableDbId:
query += where_clause + " m.id = %s "
params.append(observationVariableDbId)
where_clause = " AND"

# add a filter on the trait class - not implemented at this time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably get rid of this comment block.

#if traitClass:
# NOTE: this code is invalid for filtering on traitClass, it's just a placeholder
# query += where_clause + " s.id = %s "
# params.append(traitClass)
# where_clause = " AND"

query += " ORDER BY m.id"

# count first
count = helper.query_count(query, params)

# execute query
result = helper.query_result(query, params, pageSize, page)

# wrap result
data = list()
for row in result:
data.append({
"name": row["name"],
"observationVariableName": row["name"],
"observationVariableDbId": str(row["id"]),
"description": row["description"]
})

return helper.create_result({"data": data}, count, pageSize, page)
Loading