# Path: django_ratings/aggregation.py
# def transfer_data():
#     """
#     transfer data from table Rating to table Agg
#     """
#     logger.info("transfer_data BEGIN")
#     timenow = datetime.now()
#     for t in sorted(TIMES_ALL.keys(), reverse=True):
#         TIME_DELTA = t
#         time_agg = timenow - timedelta(seconds=TIME_DELTA)
#         Rating.objects.move_rate_to_agg(time_agg, TIMES_ALL[t])
#     transfer_agg_to_agg()
#     transfer_agg_to_totalrate()
#     logger.info("transfer_data END")


from django.core.management.base import NoArgsCommand
from django.db import transaction
from django_ratings.aggregation import transfer_data

# Logging must be inicialized

class Command(NoArgsCommand):
    help = 'Aggregate ratings'

    @transaction.commit_on_success
    def handle(self, **options):

# Path: django_ratings/aggregation.py
# def transfer_data():
#     """
#     transfer data from table Rating to table Agg
#     """
#     logger.info("transfer_data BEGIN")
#     timenow = datetime.now()
#     for t in sorted(TIMES_ALL.keys(), reverse=True):
#         TIME_DELTA = t
#         time_agg = timenow - timedelta(seconds=TIME_DELTA)
#         Rating.objects.move_rate_to_agg(time_agg, TIMES_ALL[t])
#     transfer_agg_to_agg()
#     transfer_agg_to_totalrate()
#     logger.info("transfer_data END")


# Path: django_ratings/management/commands/aggregate_ratings.py
from django.core.management.base import NoArgsCommand
from django.db import transaction
from django_ratings.aggregation import transfer_data


# Logging must be inicialized

class Command(NoArgsCommand):
    help = 'Aggregate ratings'

    @transaction.commit_on_success
    def handle(self, **options):

        transfer_data()