Skip to content
Snippets Groups Projects
Commit 26fbbec5 authored by Sabine Schröder's avatar Sabine Schröder
Browse files

Merge branch 'dev' into 'testing'

The citation endpoint returns the actual date and time (and *not* the date and...

See merge request !184
parents a0d3473c bb0ccadc
Branches
Tags
4 merge requests!217profiling tools have been integrated,!199Draft: Resolve "tool for automatic ontology creation from the source code has been built",!185The citation endpoint returns the actual date and time (and *not* the date and...,!184The citation endpoint returns the actual date and time (and *not* the date and...
Pipeline #144054 passed
...@@ -60,8 +60,13 @@ def get_timeseries(db: Session, timeseries_id: int, fields: str = None): ...@@ -60,8 +60,13 @@ def get_timeseries(db: Session, timeseries_id: int, fields: str = None):
pass pass
return db_object return db_object
# https://www.reddit.com/r/flask/comments/ypqk40/default_datetimenow_not_using_current_time/
def get_citation(db: Session, timeseries_id: int, datetime: dt.datetime = dt.datetime.now(dt.timezone.utc)): # dt.datetime.now(dt.timezone.utc) cannot be used as default value, since it will already be
# evaluated at the start of the worker process and **not** when actually accessing the data
# def get_citation(db: Session, timeseries_id: int, datetime: dt.datetime = dt.datetime.now(dt.timezone.utc)):
def get_citation(db: Session, timeseries_id: int, datetime: dt.datetime = None):
if not datetime:
datetime = dt.datetime.now(dt.timezone.utc)
db_object = db.query(models.Timeseries).filter(models.Timeseries.id == timeseries_id).first() db_object = db.query(models.Timeseries).filter(models.Timeseries.id == timeseries_id).first()
# there is a mismatch with additional_metadata # there is a mismatch with additional_metadata
PI = "unknown" PI = "unknown"
...@@ -91,7 +96,7 @@ def get_citation(db: Session, timeseries_id: int, datetime: dt.datetime = dt.dat ...@@ -91,7 +96,7 @@ def get_citation(db: Session, timeseries_id: int, datetime: dt.datetime = dt.dat
station = get_stationmeta_by_id(db, station_id=db_object.station_id).name station = get_stationmeta_by_id(db, station_id=db_object.station_id).name
dataset_version = db_object.provider_version dataset_version = db_object.provider_version
citation = f"{PI}: time series of {var} at {station}, accessed from the TOAR database on {datetime}" citation = f"{PI}: time series of {var} at {station}, accessed from the TOAR database on {datetime}"
if list_of_data_originators: if attribution and list_of_data_originators:
attribution = attribution.format(list_of_data_originators=list_of_data_originators) attribution = attribution.format(list_of_data_originators=list_of_data_originators)
if dataset_version != 'N/A': if dataset_version != 'N/A':
citation += f", original dataset version {dataset_version}" citation += f", original dataset version {dataset_version}"
......
...@@ -54,7 +54,7 @@ def get_timeseries2(timeseries_id: int, db: Session = Depends(get_db)): ...@@ -54,7 +54,7 @@ def get_timeseries2(timeseries_id: int, db: Session = Depends(get_db)):
#build citation text of one timeseries (known its ID) #build citation text of one timeseries (known its ID)
@router.get('/timeseries/citation/{timeseries_id}') @router.get('/timeseries/citation/{timeseries_id}')
def get_citation(timeseries_id: int, datetime: dt.datetime = dt.datetime.now(dt.timezone.utc), db: Session = Depends(get_db)): def get_citation(timeseries_id: int, datetime: dt.datetime = None, db: Session = Depends(get_db)):
citation = crud.get_citation(db, timeseries_id=timeseries_id, datetime=datetime) citation = crud.get_citation(db, timeseries_id=timeseries_id, datetime=datetime)
return citation return citation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment