Ejemplo n.º 1
0
    def complete_values(self):
        if self.values_completed:
            raise exceptions.ValuesCompletedError()

        for date in days_range(*self._get_interval()):
            self.store_value(date, self.get_value(date))
        self.values_completed = True
Ejemplo n.º 2
0
    def initialize(self):
        super(IncomeTotal, self).initialize()
        query = InvoicePrototype._db_filter(
            ACCEPTED_INVOICE_FILTER,
            self.db_date_gte('created_at'),
            sender_type=ENTITY_TYPE.XSOLLA,
            currency=CURRENCY_TYPE.PREMIUM).values_list(
                'created_at', 'amount')
        invoices = [(created_at.date(), amount)
                    for created_at, amount in query]

        invoices_values = {}
        for created_at, amount in invoices:
            invoices_values[created_at] = invoices_values.get(created_at,
                                                              0) + amount

        income = InvoicePrototype._db_filter(
            ACCEPTED_INVOICE_FILTER,
            self.db_date_lt('created_at'),
            sender_type=ENTITY_TYPE.XSOLLA,
            currency=CURRENCY_TYPE.PREMIUM).aggregate(
                income=models.Sum('amount'))['income']
        if income is None:
            income = 0

        self.incomes = {}

        for date in days_range(*self._get_interval()):
            income += invoices_values.get(date, 0)
            self.incomes[date] = income
Ejemplo n.º 3
0
    def complete_values(self):
        if self.values_completed:
            raise exceptions.ValuesCompletedError()

        for date in days_range(*self._get_interval()):
            self.store_value(date, self.get_value(date))
        self.values_completed = True
Ejemplo n.º 4
0
 def test_days_range__many_days__datetime(self):
     self.assertEqual(
         list(
             days_range(datetime.datetime(666, 6, 6, 6),
                        datetime.datetime(666, 6, 10, 7))), [
                            datetime.date(666, 6, 6),
                            datetime.date(666, 6, 7),
                            datetime.date(666, 6, 8),
                            datetime.date(666, 6, 9)
                        ])
Ejemplo n.º 5
0
    def initialize(self):
        super(ReferralsTotal, self).initialize()
        referrals_dates = AccountPrototype._db_filter(is_fast=False, is_bot=False).exclude(referral_of=None).values_list('created_at', flat=True)
        referrals_count = collections.Counter(date.date() for date in referrals_dates)

        self.counts = {}

        count = 0
        for date in days_range(*self._get_interval()):
            count += referrals_count.get(date, 0)
            self.counts[date] = count
Ejemplo n.º 6
0
    def initialize(self):
        super(ReferralsTotal, self).initialize()
        referrals_dates = AccountPrototype._db_filter(is_fast=False, is_bot=False).exclude(referral_of=None).values_list('created_at', flat=True)
        referrals_count = collections.Counter(date.date() for date in referrals_dates)

        self.counts = {}

        count = 0
        for date in days_range(*self._get_interval()):
            count += referrals_count.get(date, 0)
            self.counts[date] = count
Ejemplo n.º 7
0
    def initialize(self):
        super(VotesTotal, self).initialize()

        query = models.Vote.objects.all()

        count = query.filter(self.db_date_lt('created_at')).count()

        votes_dates = query.filter(self.db_date_gte('created_at')).values_list('created_at', flat=True)
        votes_count = collections.Counter(date.date() for date in votes_dates)

        self.counts = {}
        for date in days_range(*self._get_interval()):
            count += votes_count.get(date, 0)
            self.counts[date] = count
Ejemplo n.º 8
0
    def initialize(self):
        super(AccountsTotal, self).initialize()

        query = AccountPrototype._db_filter(is_fast=False, is_bot=False)

        count = query.filter(self.db_date_lt('created_at')).count()

        registrations_dates = query.filter(self.db_date_gte('created_at')).values_list('created_at', flat=True)
        registrations_count = collections.Counter(date.date() for date in registrations_dates)

        self.counts = {}
        for date in days_range(*self._get_interval()):
            count += registrations_count.get(date, 0)
            self.counts[date] = count
Ejemplo n.º 9
0
    def initialize(self):
        super(AccountsTotal, self).initialize()

        query = AccountPrototype._db_filter(is_fast=False, is_bot=False)

        count = query.filter(self.db_date_lt('created_at')).count()

        registrations_dates = query.filter(self.db_date_gte('created_at')).values_list('created_at', flat=True)
        registrations_count = collections.Counter(date.date() for date in registrations_dates)

        self.counts = {}
        for date in days_range(*self._get_interval()):
            count += registrations_count.get(date, 0)
            self.counts[date] = count
Ejemplo n.º 10
0
    def initialize(self):
        super(IncomeTotal, self).initialize()
        query = InvoicePrototype._db_filter(ACCEPTED_INVOICE_FILTER,
                                            self.db_date_gte('created_at'),
                                            sender_type=ENTITY_TYPE.XSOLLA,
                                            currency=CURRENCY_TYPE.PREMIUM).values_list('created_at', 'amount')
        invoices = [(created_at.date(), amount) for created_at, amount in query]

        invoices_values = {}
        for created_at, amount in invoices:
            invoices_values[created_at] = invoices_values.get(created_at, 0) + amount

        income = InvoicePrototype._db_filter(ACCEPTED_INVOICE_FILTER,
                                             self.db_date_lt('created_at'),
                                             sender_type=ENTITY_TYPE.XSOLLA,
                                             currency=CURRENCY_TYPE.PREMIUM).aggregate(income=models.Sum('amount'))['income']
        if income is None:
            income = 0

        self.incomes = {}

        for date in days_range(*self._get_interval()):
            income += invoices_values.get(date, 0)
            self.incomes[date] = income
Ejemplo n.º 11
0
 def test_days_range__1_day(self):
     self.assertEqual(
         list(days_range(datetime.date(666, 6, 6), datetime.date(666, 6,
                                                                 7))),
         [datetime.date(666, 6, 6)])
Ejemplo n.º 12
0
 def test_days_range__0_days(self):
     self.assertEqual(
         list(days_range(datetime.date(666, 6, 6), datetime.date(666, 6,
                                                                 6))), [])
Ejemplo n.º 13
0
 def test_days_range__many_days__datetime(self):
     self.assertEqual(list(days_range(datetime.datetime(666, 6, 6, 6), datetime.datetime(666, 6, 10, 7))),
                      [datetime.date(666, 6, 6),
                       datetime.date(666, 6, 7),
                       datetime.date(666, 6, 8),
                       datetime.date(666, 6, 9)])
Ejemplo n.º 14
0
 def test_days_range__1_day(self):
     self.assertEqual(list(days_range(datetime.date(666, 6, 6), datetime.date(666, 6, 7))),
                      [datetime.date(666, 6, 6)])
Ejemplo n.º 15
0
 def test_days_range__0_days(self):
     self.assertEqual(list(days_range(datetime.date(666, 6, 6), datetime.date(666, 6, 6))),
                      [])