Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

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): 

raise Exception("Backfill is not permetted anymore, use with caution.") 

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)