Пример #1
0
def user_month_totals(user):
    """
    Get monthly statistics about uploaded screenshots and revenue.
    """
    factories = user.factory_set.all()
    if not factories.count():
        return
    all_factories = totals()
    my_factories = totals("WHERE factory_id IN (%s)" %
                          ','.join([str(factory.id) for factory in factories]))
    keys = all_factories.keys()
    keys.sort()
    for year, month in keys:
        all = all_factories.get((year, month), 0)
        my = my_factories.get((year, month), 0)
        revenue = 0
        if 'shotserver04.revenue' in settings.INSTALLED_APPS:
            from shotserver04.revenue import month_revenue
            revenue = month_revenue(year, month)
        yield ('%04d-%02d' % (year, month), all, my,
               '%.3f%%' % (100.0 * my / all), '%.2f' % (revenue * my / all))
Пример #2
0
def user_month_totals(user):
    """
    Get monthly statistics about uploaded screenshots and revenue.
    """
    factories = user.factory_set.all()
    if not factories.count():
        return
    all_factories = totals()
    my_factories = totals("WHERE factory_id IN (%s)" % ','.join(
        [str(factory.id) for factory in factories]))
    keys = all_factories.keys()
    keys.sort()
    for year, month in keys:
        all = all_factories.get((year, month), 0)
        my = my_factories.get((year, month), 0)
        revenue = 0
        if 'shotserver04.revenue' in settings.INSTALLED_APPS:
            from shotserver04.revenue import month_revenue
            revenue = month_revenue(year, month)
        yield ('%04d-%02d' % (year, month), all, my,
               '%.3f%%' % (100.0 * my / all),
               '%.2f' % (revenue * my / all))
Пример #3
0
year = int(sys.argv[1])
month = int(sys.argv[2])

next_year = year
next_month = month + 1
if next_month == 13:
    next_month = 1
    next_year += 1

date = datetime(next_year, next_month, 1, 0, 0, 0)
counts = ScreenshotCount.objects.filter(
    date__gte='%04d-%02d-01' % (year, month),
    date__lt='%04d-%02d-01' % (next_year, next_month),
    )
total_screenshots = sum([c.screenshots for c in counts])
total_revenue = month_revenue(year, month)

for user in User.objects.all():
    screenshots = sum([c.screenshots
                       for c in counts.filter(factory__admin=user)])
    percent = 100.0 * screenshots / total_screenshots
    revenue = total_revenue * screenshots / total_screenshots
    euros = Decimal('%.2f' % revenue)
    if euros < Decimal('0.01'):
        euros = Decimal('0.01')
    balance = latest_balance(user, before=date) + euros
    existing = UserRevenue.objects.filter(
        user=user,
        year=year,
        month=month)
    if not screenshots:
Пример #4
0
year = int(sys.argv[1])
month = int(sys.argv[2])

next_year = year
next_month = month + 1
if next_month == 13:
    next_month = 1
    next_year += 1

date = datetime(next_year, next_month, 1, 0, 0, 0)
counts = ScreenshotCount.objects.filter(
    date__gte='%04d-%02d-01' % (year, month),
    date__lt='%04d-%02d-01' % (next_year, next_month),
)
total_screenshots = sum([c.screenshots for c in counts])
total_revenue = month_revenue(year, month)

for user in User.objects.all():
    screenshots = sum(
        [c.screenshots for c in counts.filter(factory__admin=user)])
    percent = 100.0 * screenshots / total_screenshots
    revenue = total_revenue * screenshots / total_screenshots
    euros = Decimal('%.2f' % revenue)
    if euros < Decimal('0.01'):
        euros = Decimal('0.01')
    balance = latest_balance(user, before=date) + euros
    existing = UserRevenue.objects.filter(user=user, year=year, month=month)
    if not screenshots:
        existing.delete()
        continue
    print screenshots, '%.3f%%' % percent, '%.2f' % euros, user,