Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
StorageLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
StorageLeaf
Commits
e8555328
Commit
e8555328
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
allow to specify a date range when fetching all measurements
parent
0e16ae0e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/logic/databaseNew/Crud.py
+7
-2
7 additions, 2 deletions
src/logic/databaseNew/Crud.py
src/routers/MeasurementRouter.py
+10
-4
10 additions, 4 deletions
src/routers/MeasurementRouter.py
with
17 additions
and
6 deletions
src/logic/databaseNew/Crud.py
+
7
−
2
View file @
e8555328
from
datetime
import
datetime
from
datetime
import
datetime
from
sqlalchemy
import
and_
from
sqlalchemy.orm
import
Session
from
sqlalchemy.orm
import
Session
from
logic.databaseNew
import
Models
,
Schemas
from
logic.databaseNew
import
Models
,
Schemas
...
@@ -65,8 +66,12 @@ def delete_sensor(db: Session, sensor: Schemas.Sensor):
...
@@ -65,8 +66,12 @@ def delete_sensor(db: Session, sensor: Schemas.Sensor):
# ===== measurements =====
# ===== measurements =====
def
get_measurements
(
db
:
Session
,
skip
:
int
=
0
,
limit
:
int
=
100
):
def
get_measurements
(
db
:
Session
,
startDateTime
:
str
,
endDateTime
:
str
):
return
db
.
query
(
Models
.
Measurement
).
offset
(
skip
).
limit
(
limit
).
all
()
if
startDateTime
and
endDateTime
:
return
db
.
query
(
Models
.
Measurement
).
filter
(
and_
(
startDateTime
<=
Models
.
Measurement
.
timestamp
,
endDateTime
>=
Models
.
Measurement
.
timestamp
)).
all
()
return
db
.
query
(
Models
.
Measurement
).
all
()
def
get_measurement
(
db
:
Session
,
measurementId
:
int
):
def
get_measurement
(
db
:
Session
,
measurementId
:
int
):
...
...
This diff is collapsed.
Click to expand it.
src/routers/MeasurementRouter.py
+
10
−
4
View file @
e8555328
from
typing
import
List
from
typing
import
List
from
fastapi
import
APIRouter
,
HTTPException
,
Depends
from
fastapi
import
APIRouter
,
HTTPException
,
Depends
,
Query
from
sqlalchemy.orm
import
Session
from
sqlalchemy.orm
import
Session
from
Dependencies
import
get_database
,
check_api_key
from
Dependencies
import
get_database
,
check_api_key
...
@@ -14,9 +14,15 @@ router = APIRouter(
...
@@ -14,9 +14,15 @@ router = APIRouter(
@router.get
(
'
/
'
,
response_model
=
List
[
Schemas
.
Measurement
],
@router.get
(
'
/
'
,
response_model
=
List
[
Schemas
.
Measurement
],
summary
=
'
Gets all measurements
'
)
summary
=
'
Gets all measurements (Number of results can be limited by specifying a date range).
'
)
async
def
read_measurements
(
skip
:
int
=
0
,
limit
:
int
=
100
,
db
:
Session
=
Depends
(
get_database
)):
async
def
read_measurements
(
startDateTime
:
str
=
Query
(
'
2020-01-20 18:15:22
'
,
return
Crud
.
get_measurements
(
db
,
skip
=
skip
,
limit
=
limit
)
description
=
'
The start date and time of the date range
'
'
that should be taken into account.
'
),
endDateTime
:
str
=
Query
(
'
2020-01-20 19:15:22
'
,
description
=
'
The end date and time of the date range
'
'
that should be taken into account.
'
),
db
:
Session
=
Depends
(
get_database
)):
return
Crud
.
get_measurements
(
db
,
startDateTime
=
startDateTime
,
endDateTime
=
endDateTime
)
@router.get
(
'
/{measurementId}
'
,
response_model
=
Schemas
.
Measurement
,
@router.get
(
'
/{measurementId}
'
,
response_model
=
Schemas
.
Measurement
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment