Skip to content

Commit

Permalink
Added project to db.Dataset.filter function and added a listobj funct…
Browse files Browse the repository at this point in the history
…ion to dataset api
  • Loading branch information
Philipp Kraft committed Jul 8, 2024
1 parent 36c17e7 commit 2eea41f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions odmf/db/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def path(self):
@classmethod
def filter(
cls, session,
project: Optional[int]=None,
valuetype: Optional[int]=None,
user: Optional[str]=None,
site: Optional[int]=None,
Expand Down
2 changes: 1 addition & 1 deletion odmf/plot/summary_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def summarize_item(
:param type: timeseries or transformed_timeseries
:return: A dict with name, value, unit, aggregation and n (number of measurements)
"""
ds_filter = db.Dataset.filter(session, valuetype, user, site, date, instrument, type, level)
ds_filter = db.Dataset.filter(session, None, valuetype, user, site, date, instrument, type, level)
if not ds_filter.count():
return dict(name='No data', value = np.NaN, unit='', aggregation=aggregate, n=0, start = pd.NaT, end=pd.NaT)
else:
Expand Down
28 changes: 27 additions & 1 deletion odmf/webpage/api/dataset_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def values_parquet(self, dsid, start=None, end=None):
@web.method.get
def list(
self,
project: typing.Optional[int] = None,
valuetype: typing.Optional[int] = None,
user: typing.Optional[str] = None,
site: typing.Optional[int] = None,
Expand All @@ -141,11 +142,36 @@ def list(
"""
web.mime.json.set()
with db.session_scope() as session:
datasets = db.Dataset.filter(session, valuetype, user, site, date, instrument, type, level)
datasets = db.Dataset.filter(session, project, valuetype, user, site, date, instrument, type, level)
return web.json_out([
ds.id
for ds in datasets
])
@expose_for()
@web.method.get
def listobj(
self,
project: typing.Optional[int] = None,
valuetype: typing.Optional[int] = None,
user: typing.Optional[str] = None,
site: typing.Optional[int] = None,
date: typing.Optional[datetime.datetime] = None,
instrument: typing.Optional[int] = None,
type: typing.Optional[str] = None,
level: typing.Optional[float] = None
):
"""
Returns a JSON list of all available dataset objects
"""
web.mime.json.set()
ds: db.Dataset
with db.session_scope() as session:
datasets = db.Dataset.filter(session, project, valuetype, user, site, date, instrument, type, level)
return web.json_out([
ds.__jdict__()
for ds in datasets
])


@expose_for(Level.editor)
@web.method.post_or_put
Expand Down

0 comments on commit 2eea41f

Please sign in to comment.