Esempio n. 1
0
def portal_day_started(sender, **kwargs): # pylint: disable=W0613
    accounts_query = AccountPrototype.live_query().filter(active_end_at__gt=datetime.datetime.now(),
                                                          ban_game_end_at__lt=datetime.datetime.now(),
                                                          ban_forum_end_at__lt=datetime.datetime.now(),
                                                          premium_end_at__lt=datetime.datetime.now())

    accounts_number = accounts_query.count()
    if accounts_number < 1:
        return

    account_model = accounts_query[random.randint(0, accounts_number-1)]

    account = AccountPrototype(model=account_model)

    settings[portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY] = str(account.id)

    environment.workers.accounts_manager.cmd_run_account_method(account_id=account.id,
                                                                method_name=AccountPrototype.prolong_premium.__name__,
                                                                data={'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY})

    message = u'''
Поздравляем!

Ваш герой выбран героем дня и Вы получаете %(days)d дней подписки!
''' % {'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY}

    MessagePrototype.create(get_system_user(), account, message)
Esempio n. 2
0
def portal_day_started(sender, **kwargs):  # pylint: disable=W0613
    accounts_query = AccountPrototype.live_query().filter(
        active_end_at__gt=datetime.datetime.now(),
        ban_game_end_at__lt=datetime.datetime.now(),
        ban_forum_end_at__lt=datetime.datetime.now(),
        premium_end_at__lt=datetime.datetime.now())

    accounts_number = accounts_query.count()
    if accounts_number < 1:
        return

    account_model = accounts_query[random.randint(0, accounts_number - 1)]

    account = AccountPrototype(model=account_model)

    settings[portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY] = str(account.id)

    environment.workers.accounts_manager.cmd_run_account_method(
        account_id=account.id,
        method_name=AccountPrototype.prolong_premium.__name__,
        data={'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY})

    message = '''
Поздравляем!

Ваш герой выбран героем дня и Вы получаете %(days)d дней подписки!
''' % {
        'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY
    }

    MessagePrototype.create(get_system_user(), account, message)
Esempio n. 3
0
def get_referers_statistics():

    raw_statistics = AccountPrototype.live_query().values(
        'referer_domain').order_by().annotate(models.Count('referer_domain'))

    statistics = {}

    for s in raw_statistics:
        domain = s['referer_domain']

        count = s['referer_domain__count']

        query = AccountPrototype.live_query().filter(referer_domain=domain)

        if domain is None:
            count = query.count()

        target_domain = domain

        if target_domain and target_domain.endswith(
                'livejournal.com'
        ):  # hide all domains username.livejournal.com (to hide there payment info)
            target_domain = 'livejournal.com'

        st = RefererStatistics(
            domain=target_domain,
            count=count,
            active_accounts=query.filter(
                active_end_at__gt=datetime.datetime.now()).count(),
            premium_accounts=query.filter(
                premium_end_at__gt=datetime.datetime.now()).count(),
            active_and_premium=query.filter(
                active_end_at__gt=datetime.datetime.now(),
                premium_end_at__gt=datetime.datetime.now()).count(),
            premium_currency=BankAccountPrototype._money_received(
                from_type=BANK_ENTITY_TYPE.XSOLLA,
                accounts_ids=query.values_list('id', flat=True)))

        if st.domain in statistics:
            statistics[st.domain] = statistics[st.domain] + st
        else:
            statistics[st.domain] = st

    statistics = sorted(statistics.values(), key=lambda s: -s.count)

    return statistics
Esempio n. 4
0
def get_referers_statistics():

    raw_statistics = (
        AccountPrototype.live_query().values("referer_domain").order_by().annotate(models.Count("referer_domain"))
    )

    statistics = {}

    for s in raw_statistics:
        domain = s["referer_domain"]

        count = s["referer_domain__count"]

        query = AccountPrototype.live_query().filter(referer_domain=domain)

        if domain is None:
            count = query.count()

        target_domain = domain

        if target_domain and target_domain.endswith(
            "livejournal.com"
        ):  # hide all domains username.livejournal.com (to hide there payment info)
            target_domain = "livejournal.com"

        st = RefererStatistics(
            domain=target_domain,
            count=count,
            active_accounts=query.filter(active_end_at__gt=datetime.datetime.now()).count(),
            premium_accounts=query.filter(premium_end_at__gt=datetime.datetime.now()).count(),
            active_and_premium=query.filter(
                active_end_at__gt=datetime.datetime.now(), premium_end_at__gt=datetime.datetime.now()
            ).count(),
            premium_currency=BankAccountPrototype._money_received(
                from_type=BANK_ENTITY_TYPE.XSOLLA, accounts_ids=query.values_list("id", flat=True)
            ),
        )

        if st.domain in statistics:
            statistics[st.domain] = statistics[st.domain] + st
        else:
            statistics[st.domain] = st

    statistics = sorted(list(statistics.values()), key=lambda s: -s.count)

    return statistics
Esempio n. 5
0
    def index(self):

        registration_attemps_number = AccountPrototype._model_class.objects.all().aggregate(models.Max('id'))['id__max']
        accounts_total = AccountPrototype._model_class.objects.all().count()
        accounts_bots = AccountPrototype._model_class.objects.filter(is_bot=True).count()
        accounts_registered = AccountPrototype.live_query().count()
        accounts_active = AccountPrototype.live_query().filter(active_end_at__gt=datetime.datetime.now()).count()
        accounts_premium = AccountPrototype.live_query().filter(premium_end_at__gt=datetime.datetime.now()).count()
        accounts_active_and_premium = AccountPrototype.live_query().filter(active_end_at__gt=datetime.datetime.now(),
                                                                           premium_end_at__gt=datetime.datetime.now()).count()

        accounts_referrals = AccountPrototype.live_query().exclude(referral_of=None).count()
        accounts_referrals_and_premium = AccountPrototype.live_query().exclude(referral_of=None).filter(premium_end_at__gt=datetime.datetime.now()).count()
        accounts_referrals_and_active = AccountPrototype.live_query().exclude(referral_of=None).filter(active_end_at__gt=datetime.datetime.now(),
                                                                                                       premium_end_at__gt=datetime.datetime.now()).count()

        gold = {}
        gold_total_spent = 0
        gold_total_received = 0
        real_gold_total_spent = 0
        real_gold_total_received = 0

        for record in BANK_ENTITY_TYPE.records:
            spent = -BankAccountPrototype._money_spent(from_type=record)
            received = BankAccountPrototype._money_received(from_type=record)
            gold[record.text] = {'spent': spent, 'received': received}

            gold_total_spent += spent
            gold_total_received += received

            if record.is_real:
                real_gold_total_spent += spent
                real_gold_total_received += received

        gold_in_game = gold_total_received - gold_total_spent
        real_gold_in_game = real_gold_total_received - real_gold_total_spent

        return self.template('developers_info/index.html',
                             {'registration_attemps_number': registration_attemps_number,
                              'accounts_total': accounts_total,
                              'accounts_bots': accounts_bots,
                              'accounts_registered': accounts_registered,
                              'accounts_active': accounts_active,
                              'accounts_premium': accounts_premium,
                              'accounts_active_and_premium': accounts_active_and_premium,
                              'accounts_referrals': accounts_referrals,
                              'accounts_referrals_and_premium': accounts_referrals_and_premium,
                              'accounts_referrals_and_active': accounts_referrals_and_active,
                              'gold': gold,
                              'gold_total_spent': gold_total_spent,
                              'gold_total_received': gold_total_received,
                              'gold_in_game': gold_in_game,
                              'real_gold_in_game': real_gold_in_game,
                              'referers_statistics': get_referers_statistics(),
                              'invoice_statistics': get_invoice_statistics(),
                              'invoice_count': InvoiceQuery.count(),
                              'repeatable_payments_statistics': get_repeatable_payments_statistics(),
                              'PAYMENT_GROUPS': PAYMENT_GROUPS,
                              'PREMIUM_DAYS_FOR_HERO_OF_THE_DAY': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY,
                              'page_type': 'index'})
Esempio n. 6
0
def recalculate_accounts_might():

    for account_model in AccountPrototype.live_query():
        account = AccountPrototype(model=account_model)

        new_might = calculate_might(account)

        if account.might != new_might:
            account.set_might(new_might)
            account.cmd_update_hero()

    recalculate_folclor_rating()
Esempio n. 7
0
def recalculate_accounts_might():

    for account_model in AccountPrototype.live_query():
        account = AccountPrototype(model=account_model)

        new_might = calculate_might(account)

        if account.might != new_might:
            account.set_might(new_might)
            account.cmd_update_hero()

    recalculate_folclor_rating()
Esempio n. 8
0
def portal_day_started(sender, **kwargs):
    accounts_query = AccountPrototype.live_query().filter(
        active_end_at__gt=datetime.datetime.now(),
        ban_game_end_at__lt=datetime.datetime.now(),
        ban_forum_end_at__lt=datetime.datetime.now(),
        premium_end_at__lt=datetime.datetime.now())

    accounts_number = accounts_query.count()
    if accounts_number < 1:
        return

    account = None

    for i in range(1000):
        account_model = accounts_query[random.randint(0, accounts_number - 1)]
        account = AccountPrototype(model=account_model)

        # explicity check for premium, since infinit subscribers does not filtered by previouse query
        if not account.is_premium:
            break
    else:
        return  # if not premium account does not found

    settings[portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY] = str(account.id)

    environment.workers.accounts_manager.cmd_run_account_method(
        account_id=account.id,
        method_name=AccountPrototype.prolong_premium.__name__,
        data={'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY})

    message = '''
Поздравляем!

Ваш герой выбран героем дня и Вы получаете %(days)d дней подписки!
''' % {
        'days': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY
    }

    pm_tt_api.send_message(sender_id=accounts_logic.get_system_user_id(),
                           recipients_ids=[account.id],
                           body=message,
                           async=True)
Esempio n. 9
0
    def index(self):

        registration_attemps_number = AccountPrototype._model_class.objects.all(
        ).aggregate(models.Max('id'))['id__max']
        accounts_total = AccountPrototype._model_class.objects.all().count()
        accounts_bots = AccountPrototype._model_class.objects.filter(
            is_bot=True).count()
        accounts_registered = AccountPrototype.live_query().count()
        accounts_active = AccountPrototype.live_query().filter(
            active_end_at__gt=datetime.datetime.now()).count()
        accounts_premium = AccountPrototype.live_query().filter(
            premium_end_at__gt=datetime.datetime.now()).count()
        accounts_active_and_premium = AccountPrototype.live_query().filter(
            active_end_at__gt=datetime.datetime.now(),
            premium_end_at__gt=datetime.datetime.now()).count()

        accounts_referrals = AccountPrototype.live_query().exclude(
            referral_of=None).count()
        accounts_referrals_and_premium = AccountPrototype.live_query().exclude(
            referral_of=None).filter(
                premium_end_at__gt=datetime.datetime.now()).count()
        accounts_referrals_and_active = AccountPrototype.live_query().exclude(
            referral_of=None).filter(
                active_end_at__gt=datetime.datetime.now(),
                premium_end_at__gt=datetime.datetime.now()).count()

        gold = {}
        gold_total_spent = 0
        gold_total_received = 0
        real_gold_total_spent = 0
        real_gold_total_received = 0

        for record in BANK_ENTITY_TYPE.records:
            spent = -BankAccountPrototype._money_spent(from_type=record)
            received = BankAccountPrototype._money_received(from_type=record)
            gold[record.text] = {'spent': spent, 'received': received}

            gold_total_spent += spent
            gold_total_received += received

            if record.is_real:
                real_gold_total_spent += spent
                real_gold_total_received += received

        gold_in_game = gold_total_received - gold_total_spent
        real_gold_in_game = real_gold_total_received - real_gold_total_spent

        return self.template(
            'developers_info/index.html', {
                'registration_attemps_number':
                registration_attemps_number,
                'accounts_total':
                accounts_total,
                'accounts_bots':
                accounts_bots,
                'accounts_registered':
                accounts_registered,
                'accounts_active':
                accounts_active,
                'accounts_premium':
                accounts_premium,
                'accounts_active_and_premium':
                accounts_active_and_premium,
                'accounts_referrals':
                accounts_referrals,
                'accounts_referrals_and_premium':
                accounts_referrals_and_premium,
                'accounts_referrals_and_active':
                accounts_referrals_and_active,
                'gold':
                gold,
                'gold_total_spent':
                gold_total_spent,
                'gold_total_received':
                gold_total_received,
                'gold_in_game':
                gold_in_game,
                'real_gold_in_game':
                real_gold_in_game,
                'referers_statistics':
                get_referers_statistics(),
                'invoice_statistics':
                get_invoice_statistics(),
                'invoice_count':
                InvoiceQuery.count(),
                'repeatable_payments_statistics':
                get_repeatable_payments_statistics(),
                'PAYMENT_GROUPS':
                PAYMENT_GROUPS,
                'PREMIUM_DAYS_FOR_HERO_OF_THE_DAY':
                portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY,
                'page_type':
                'index'
            })
Esempio n. 10
0
    def index(self):

        registration_attemps_number = AccountPrototype._model_class.objects.all().aggregate(models.Max("id"))["id__max"]
        accounts_total = AccountPrototype._model_class.objects.all().count()
        accounts_bots = AccountPrototype._model_class.objects.filter(is_bot=True).count()
        accounts_registered = AccountPrototype.live_query().count()
        accounts_active = AccountPrototype.live_query().filter(active_end_at__gt=datetime.datetime.now()).count()
        accounts_premium = AccountPrototype.live_query().filter(premium_end_at__gt=datetime.datetime.now()).count()
        accounts_active_and_premium = (
            AccountPrototype.live_query()
            .filter(active_end_at__gt=datetime.datetime.now(), premium_end_at__gt=datetime.datetime.now())
            .count()
        )

        accounts_referrals = AccountPrototype.live_query().exclude(referral_of=None).count()
        accounts_referrals_and_premium = (
            AccountPrototype.live_query()
            .exclude(referral_of=None)
            .filter(premium_end_at__gt=datetime.datetime.now())
            .count()
        )
        accounts_referrals_and_active = (
            AccountPrototype.live_query()
            .exclude(referral_of=None)
            .filter(active_end_at__gt=datetime.datetime.now(), premium_end_at__gt=datetime.datetime.now())
            .count()
        )

        gold = {}
        gold_total_spent = 0
        gold_total_received = 0
        real_gold_total_spent = 0
        real_gold_total_received = 0

        for record in BANK_ENTITY_TYPE.records:
            spent = -BankAccountPrototype._money_spent(from_type=record)
            received = BankAccountPrototype._money_received(from_type=record)
            gold[record.text] = {"spent": spent, "received": received}

            gold_total_spent += spent
            gold_total_received += received

            if record.is_real:
                real_gold_total_spent += spent
                real_gold_total_received += received

        gold_in_game = gold_total_received - gold_total_spent
        real_gold_in_game = real_gold_total_received - real_gold_total_spent

        return self.template(
            "developers_info/index.html",
            {
                "registration_attemps_number": registration_attemps_number,
                "accounts_total": accounts_total,
                "accounts_bots": accounts_bots,
                "accounts_registered": accounts_registered,
                "accounts_active": accounts_active,
                "accounts_premium": accounts_premium,
                "accounts_active_and_premium": accounts_active_and_premium,
                "accounts_referrals": accounts_referrals,
                "accounts_referrals_and_premium": accounts_referrals_and_premium,
                "accounts_referrals_and_active": accounts_referrals_and_active,
                "gold": gold,
                "gold_total_spent": gold_total_spent,
                "gold_total_received": gold_total_received,
                "gold_in_game": gold_in_game,
                "real_gold_in_game": real_gold_in_game,
                "referers_statistics": get_referers_statistics(),
                "invoice_statistics": get_invoice_statistics(),
                "invoice_count": InvoiceQuery.count(),
                "repeatable_payments_statistics": get_repeatable_payments_statistics(),
                "PAYMENT_GROUPS": PAYMENT_GROUPS,
                "PREMIUM_DAYS_FOR_HERO_OF_THE_DAY": portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY,
                "page_type": "index",
            },
        )