Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
609bc23b
Commit
609bc23b
authored
Jun 07, 2020
by
Maxime Emschwiller
Browse files
feature(backend): Add backfill of connections and feedbacks stats
parent
c8aee250
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/stats_app/management/__init__.py
0 → 100644
View file @
609bc23b
backend/stats_app/management/commands/__init__.py
0 → 100644
View file @
609bc23b
backend/stats_app/management/commands/backfill_stats.py
0 → 100644
View file @
609bc23b
import
logging
from
datetime
import
timedelta
,
datetime
from
django.core.management.base
import
BaseCommand
from
django.utils.timezone
import
make_aware
from
stats_app.compute_stats
import
update_all_stats
logger
=
logging
.
getLogger
(
"Backfill stats"
)
def
backfill_stats_history
(
date_from
:
datetime
,
date_to
:
datetime
):
"""
update all stats in the time range delimited by datetimes in arguments
:param date_from: beginning of the time range
:param date_to: end of the time range
"""
local_date_from
=
date_from
while
local_date_from
.
strftime
(
"%Y-%m-%d"
)
!=
date_to
.
strftime
(
"%Y-%m-%d"
):
logger
.
info
(
local_date_from
)
update_all_stats
(
local_date_from
)
local_date_from
=
local_date_from
+
timedelta
(
days
=
1
)
class
Command
(
BaseCommand
):
help
=
"Backfill REX-DRI stats data"
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
"--date-from"
,
required
=
True
,
type
=
str
,
help
=
"The start date for the backfill (YYYY-MM-DD)."
,
)
parser
.
add_argument
(
"--date-to"
,
required
=
True
,
help
=
"The end date for the backfill (YYYY-MM-DD)"
,
)
def
handle
(
self
,
*
args
,
**
options
):
date_from
=
make_aware
(
datetime
.
strptime
(
options
[
"date_from"
],
"%Y-%m-%d"
))
date_to
=
make_aware
(
datetime
.
strptime
(
options
[
"date_to"
],
"%Y-%m-%d"
))
logger
.
info
(
f
"Backfill from
{
date_from
}
to
{
date_to
}
."
)
backfill_stats_history
(
date_from
,
date_to
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment