Example #1
0
def _generate_level_reports(model, **kwargs):
    content_type = ContentType.objects.get_for_model(model)
    levels = model.objects.values_list('level',
                                       flat=True).distinct().order_by()

    for level in Level.objects.filter(pk__in=levels):
        records = slice_records(model.objects.filter(level=level,
                                                     success=True),
                                minimum_count=2500,
                                report_timespan=timedelta(weeks=2))

        if records.count() > 0:
            report_data = drop_report(records, **kwargs)

            models.LevelReport.objects.create(
                level=level,
                content_type=content_type,
                start_timestamp=records[records.count() - 1].
                timestamp,  # first() and last() do not work on sliced qs
                end_timestamp=records[0].timestamp,
                log_count=records.count(),
                unique_contributors=records.aggregate(
                    Count('wizard_id', distinct=True))['wizard_id__count'],
                report=report_data,
            )
Example #2
0
def generate_shop_refresh_reports():
    records = slice_records(models.ShopRefreshLog.objects.all(),
                            minimum_count=2500,
                            report_timespan=timedelta(weeks=2))
    report = drop_report(records, min_count=0)

    content_type = ContentType.objects.get_for_model(models.ShopRefreshLog)
    if records.count() > 0:
        models.MagicShopRefreshReport.objects.create(
            content_type=content_type,
            # first() and last() do not work on sliced qs
            start_timestamp=records[records.count() - 1].timestamp,
            end_timestamp=records[0].timestamp,
            log_count=records.count(),
            unique_contributors=records.aggregate(
                Count('wizard_id', distinct=True))['wizard_id__count'],
            report=report,
        )
Example #3
0
def _generate_by_grade_reports(model):
    content_type = ContentType.objects.get_for_model(model)
    levels = model.objects.values_list('level',
                                       flat=True).distinct().order_by()

    for level in Level.objects.filter(pk__in=levels):
        all_records = model.objects.none()
        report_data = {'reports': []}

        # Generate a report by grade
        for grade, grade_desc in model.GRADE_CHOICES:
            records = slice_records(model.objects.filter(level=level,
                                                         grade=grade),
                                    minimum_count=2500,
                                    report_timespan=timedelta(weeks=2))

            if records.count() > 0:
                grade_report = drop_report(records)
            else:
                grade_report = None

            report_data['reports'].append({
                'grade': grade_desc,
                'report': grade_report
            })
            all_records |= records

        if all_records.count() > 0:
            # Generate a report with all results for a complete list of all things that drop here
            report_data['summary'] = grade_summary_report(
                all_records, model.GRADE_CHOICES)

            models.LevelReport.objects.create(
                level=level,
                content_type=content_type,
                start_timestamp=all_records.last().timestamp,
                end_timestamp=all_records.first().timestamp,
                log_count=all_records.count(),
                unique_contributors=all_records.aggregate(
                    Count('wizard_id', distinct=True))['wizard_id__count'],
                report=report_data,
            )
Example #4
0
def generate_rune_crafting_reports():
    records = slice_records(models.CraftRuneLog.objects.all(),
                            minimum_count=2500,
                            report_timespan=timedelta(weeks=2))
    content_type = ContentType.objects.get_for_model(models.CraftRuneLog)

    for craft_id, _ in models.CraftRuneLog.CRAFT_CHOICES:
        qs = records.filter(craft_level=craft_id)
        report = get_rune_report(qs, qs.count(), min_count=0)

        if qs.count() > 0:
            models.RuneCraftingReport.objects.create(
                content_type=content_type,
                # first() and last() do not work on sliced qs
                start_timestamp=qs[qs.count() - 1].timestamp,
                end_timestamp=qs[0].timestamp,
                log_count=qs.count(),
                unique_contributors=qs.aggregate(
                    Count('wizard_id', distinct=True))['wizard_id__count'],
                report=report,
                craft_level=craft_id,
            )
Example #5
0
def generate_magic_box_crafting_reports():
    records = slice_records(models.MagicBoxCraft.objects.all(),
                            minimum_count=2500,
                            report_timespan=timedelta(weeks=2))
    content_type = ContentType.objects.get_for_model(models.MagicBoxCraft)

    for box_id, _ in models.MagicBoxCraft.BOX_CHOICES:
        qs = records.filter(box_type=box_id)
        report = drop_report(qs, min_count=0, include_currency=True)

        if qs.count() > 0:
            models.MagicBoxCraftingReport.objects.create(
                content_type=content_type,
                # first() and last() do not work on sliced qs
                start_timestamp=qs[qs.count() - 1].timestamp,
                end_timestamp=qs[0].timestamp,
                log_count=qs.count(),
                unique_contributors=qs.aggregate(
                    Count('wizard_id', distinct=True))['wizard_id__count'],
                report=report,
                box_type=box_id,
            )
Example #6
0
def generate_summon_reports():
    records = slice_records(models.SummonLog.objects.all(),
                            minimum_count=2500,
                            report_timespan=timedelta(weeks=2))
    content_type = ContentType.objects.get_for_model(models.SummonLog)

    items = GameItem.objects.filter(pk__in=set(
        records.values_list('item', flat=True)),
                                    category__isnull=False)
    item_group_pairs = {item: item for item in items}

    # unknown scrolls, hearts
    hearts = GameItem.objects.get(category=GameItem.CATEGORY_CURRENCY,
                                  com2us_id=2)
    us = GameItem.objects.get(category=GameItem.CATEGORY_SUMMON_SCROLL,
                              com2us_id=1)
    # crystals, ms
    crystals = GameItem.objects.get(category=GameItem.CATEGORY_CURRENCY,
                                    com2us_id=1)
    ms = GameItem.objects.get(category=GameItem.CATEGORY_SUMMON_SCROLL,
                              com2us_id=2)
    # ld & pieces
    ld = GameItem.objects.get(category=GameItem.CATEGORY_SUMMON_SCROLL,
                              com2us_id=3)
    ld_pieces = GameItem.objects.get(category=GameItem.CATEGORY_SUMMON_SCROLL,
                                     com2us_id=10)
    # ls & pieces
    ls = GameItem.objects.get(category=GameItem.CATEGORY_SUMMON_SCROLL,
                              com2us_id=7)
    ls_pieces = GameItem.objects.get(category=GameItem.CATEGORY_SUMMON_SCROLL,
                                     com2us_id=9)

    item_group_pairs[hearts] = us
    item_group_pairs[crystals] = ms
    item_group_pairs[ld_pieces] = ld
    item_group_pairs[ls_pieces] = ls

    item_groups = {}
    for item in set(item_group_pairs.values()):
        item_groups[item] = [
            k for k, v in item_group_pairs.items() if v == item
        ]

    for item_g, items in item_groups.items():
        if not items:
            continue
        qs = records.filter(item__in=items)
        report = get_monster_report(qs, qs.count(), min_count=0)

        if qs.count() > 0:
            models.SummonReport.objects.create(
                content_type=content_type,
                # first() and last() do not work on sliced qs
                start_timestamp=qs[qs.count() - 1].timestamp,
                end_timestamp=qs[0].timestamp,
                log_count=qs.count(),
                unique_contributors=qs.aggregate(
                    Count('wizard_id', distinct=True))['wizard_id__count'],
                report=report,
                item=item_g,
            )