Skip to content

Commit

Permalink
add: start and end bounds to counts
Browse files Browse the repository at this point in the history
  • Loading branch information
JonFreer committed Oct 18, 2023
1 parent 4993edb commit a67d88a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api/API/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def read_counts(
time_interval: str,
identity: int,
start_time: int,
end_time:int | None = None,
table: str = "counts_hourly",
) -> List[models.Counts]:
limit, offset = limit_offset
Expand All @@ -212,14 +213,19 @@ def read_counts(
+ table
+ """
WHERE counter = :identity AND timestamp > TIMESTAMPTZ :start_time
AND timestamp <= TIMESTAMPTZ :end_time
GROUP BY 1,2,3
ORDER BY timestamp DESC"""
)

if end_time == None:
end_time = datetime.datetime.now().timestamp()

sql = sql.bindparams(
bindparam("timeInterval", value=time_interval),
bindparam("identity", value=identity),
bindparam("start_time", value=datetime.datetime.fromtimestamp(start_time)),
bindparam("end_time", value=datetime.datetime.fromtimestamp(end_time)),
)

results = db.execute(sql).all()
Expand Down
11 changes: 10 additions & 1 deletion api/API/routers/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def read_counter(
def read_all_counts(
response: Response,
identity: int | None = None,
# start_time: int | None = None,
# end_time: int | None = None,
start_time: Annotated[
int | None, Query(title="Start Time", description="Start timestamp of data. Defaults to zero.")
] = None,
end_time: Annotated[
int | None, Query(title="End Time", description="End timestamp of data. Defaults to current time.")
] = None,
offset: int = 0,
limit: int = 25,
time_interval: str = "1 hour",
Expand All @@ -47,7 +55,8 @@ def read_all_counts(
(limit, offset),
time_interval=time_interval,
identity=identity,
start_time=0,
start_time=start_time,
end_time=end_time
)


Expand Down

0 comments on commit a67d88a

Please sign in to comment.