Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
ViaResto-website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Aymeric Chaumont
ViaResto-website
Merge requests
!23
Extract stats
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Extract stats
extract-stats
into
main
Overview
0
Commits
12
Pipelines
12
Changes
13
Merged
Aymeric Chaumont
requested to merge
extract-stats
into
main
2 years ago
Overview
0
Commits
12
Pipelines
12
Changes
13
Expand
0
0
Merge request reports
Compare
main
version 5
d7e4e6da
2 years ago
version 4
8d6530ad
2 years ago
version 3
06ad256d
2 years ago
version 2
1d52a686
2 years ago
version 1
6ab98903
2 years ago
main (base)
and
latest version
latest version
5a680ddc
12 commits,
2 years ago
version 5
d7e4e6da
11 commits,
2 years ago
version 4
8d6530ad
10 commits,
2 years ago
version 3
06ad256d
9 commits,
2 years ago
version 2
1d52a686
7 commits,
2 years ago
version 1
6ab98903
6 commits,
2 years ago
13 files
+
1162
−
448
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
13
Search (e.g. *.vue) (Ctrl+P)
backend/db/crud.py
+
49
−
1
Options
"""
Module to interact with the database
"""
from
datetime
import
date
,
datetime
,
time
,
timedelta
from
numpy
import
average
from
sqlalchemy.orm
import
Session
from
sqlalchemy.sql
import
func
from
db
import
models
,
schemas
@@ -22,5 +26,49 @@ def create_record(new_record: schemas.RecordBase, db: Session):
def
get_waiting_time
(
place
:
str
,
db
:
Session
):
"""
Get the last estimated waiting time for the given place
"""
db_record
=
db
.
query
(
models
.
Records
).
filter
(
models
.
Records
.
place
==
place
).
order_by
(
models
.
Records
.
date
.
desc
()).
one
()
db_record
=
db
.
query
(
models
.
Records
).
filter
(
models
.
Records
.
place
==
place
).
order_by
(
models
.
Records
.
date
.
desc
()).
first
()
return
db_record
.
waiting_time
def
get_stats
(
place
:
str
,
weekday
:
int
,
min_time_hour
:
int
,
min_time_mn
:
int
,
max_time_hour
:
int
,
max_time_mn
:
int
,
interval
:
timedelta
,
db
:
Session
):
"""
Get the average waiting time for each interval between two time steps
"""
def
shift_time
(
t
:
time
,
delta
:
timedelta
):
return
(
datetime
.
combine
(
date
(
1
,
1
,
1
),
t
)
+
delta
).
time
()
def
avg_time_query
(
start_time
,
end_time
):
records
=
db
.
query
(
(
func
.
round
(
func
.
avg
(
3600
*
func
.
extract
(
'
HOUR
'
,
models
.
Records
.
waiting_time
)
+
60
*
func
.
extract
(
'
MINUTE
'
,
models
.
Records
.
waiting_time
)
+
func
.
extract
(
'
SECOND
'
,
models
.
Records
.
waiting_time
))
))
/
60
).
filter
(
models
.
Records
.
place
==
place
,
func
.
weekday
(
models
.
Records
.
date
)
==
weekday
,
(
func
.
extract
(
'
HOUR
'
,
models
.
Records
.
date
)
>
start_time
.
hour
)
|
((
func
.
extract
(
'
HOUR
'
,
models
.
Records
.
date
)
==
start_time
.
hour
)
&
(
func
.
extract
(
'
MINUTE
'
,
models
.
Records
.
date
)
>=
start_time
.
minute
)),
(
func
.
extract
(
'
HOUR
'
,
models
.
Records
.
date
)
<
end_time
.
hour
)
|
((
func
.
extract
(
'
HOUR
'
,
models
.
Records
.
date
)
==
end_time
.
hour
)
&
(
func
.
extract
(
'
MINUTE
'
,
models
.
Records
.
date
)
<
end_time
.
minute
)),
).
one
()
if
records
[
0
]:
return
int
(
records
[
0
])
return
None
def
add_slot
(
slots_list
,
start_time
,
end_time
):
average_waiting_time
=
avg_time_query
(
start_time
,
end_time
)
if
average_waiting_time
:
name
=
f
'
{
start_time
.
hour
:
02
}
h
{
start_time
.
minute
:
02
}
'
slots_list
.
append
({
'
name
'
:
name
,
'
time
'
:
average_waiting_time
})
min_time
,
max_time
=
time
(
min_time_hour
,
min_time_mn
),
time
(
max_time_hour
,
max_time_mn
)
stats
=
[]
start_time
,
end_time
=
min_time
,
shift_time
(
min_time
,
interval
)
while
start_time
<
max_time
:
add_slot
(
stats
,
start_time
,
end_time
)
start_time
,
end_time
=
end_time
,
shift_time
(
end_time
,
interval
)
return
stats
Loading