Example #1
0
    def make_campaign_table(self):
        campaigns = PromoCampaign._by_link(self.thing._id)

        total_budget = 0
        total_spent = 0
        total_paid_impressions = 0
        total_impressions = 0
        total_clicks = 0

        self.campaign_table = []
        for camp in campaigns:
            if not is_launched_campaign(camp):
                continue

            is_live = camp.is_live_now()
            self.has_early_campaign |= is_early_campaign(camp)
            self.has_live_campaign |= is_live

            history = get_billable_traffic(camp)
            impressions, clicks = 0, 0
            for date, (imp, click) in history:
                impressions += imp
                clicks += click

            start = to_date(camp.start_date).strftime('%Y-%m-%d')
            end = to_date(camp.end_date).strftime('%Y-%m-%d')
            target = camp.target.pretty_name
            location = camp.location_str
            spent = promote.get_spent_amount(camp)
            is_active = self.campaign and self.campaign._id36 == camp._id36
            url = '/traffic/%s/%s' % (self.thing._id36, camp._id36)
            is_total = False
            row = self.make_campaign_table_row(camp._id36, start, end, target,
                                               location, camp.bid, spent,
                                               camp.impressions,
                                               impressions, clicks, is_live,
                                               is_active, url, is_total)
            self.campaign_table.append(row)

            total_budget += camp.bid
            total_spent += spent
            total_paid_impressions += camp.impressions
            total_impressions += impressions
            total_clicks += clicks

        # total row
        start = '---'
        end = '---'
        target = '---'
        location = '---'
        is_live = False
        is_active = not self.campaign
        url = '/traffic/%s' % self.thing._id36
        is_total = True
        row = self.make_campaign_table_row(_('total'), start, end, target,
                                           location, total_budget, total_spent,
                                           total_paid_impressions, total_impressions,
                                           total_clicks, is_live, is_active, url,
                                           is_total)
        self.campaign_table.append(row)
Example #2
0
    def make_campaign_table(self):
        campaigns = PromoCampaign._by_link(self.thing._id)

        total_budget = 0
        total_spent = 0
        total_paid_impressions = 0
        total_impressions = 0
        total_clicks = 0

        self.campaign_table = []
        for camp in campaigns:
            if not is_launched_campaign(camp):
                continue

            is_live = camp.is_live_now()
            self.has_early_campaign |= is_early_campaign(camp)
            self.has_live_campaign |= is_live

            history = get_billable_traffic(camp)
            impressions, clicks = 0, 0
            for date, (imp, click) in history:
                impressions += imp
                clicks += click

            start = to_date(camp.start_date).strftime('%Y-%m-%d')
            end = to_date(camp.end_date).strftime('%Y-%m-%d')
            target = camp.target.pretty_name
            location = camp.location_str
            spent = promote.get_spent_amount(camp)
            is_active = self.campaign and self.campaign._id36 == camp._id36
            url = '/traffic/%s/%s' % (self.thing._id36, camp._id36)
            is_total = False
            row = self.make_campaign_table_row(camp._id36, start, end, target,
                                               location, camp.bid, spent,
                                               camp.impressions, impressions,
                                               clicks, is_live, is_active, url,
                                               is_total)
            self.campaign_table.append(row)

            total_budget += camp.bid
            total_spent += spent
            total_paid_impressions += camp.impressions
            total_impressions += impressions
            total_clicks += clicks

        # total row
        start = '---'
        end = '---'
        target = '---'
        location = '---'
        is_live = False
        is_active = not self.campaign
        url = '/traffic/%s' % self.thing._id36
        is_total = True
        row = self.make_campaign_table_row(_('total'), start, end, target,
                                           location, total_budget, total_spent,
                                           total_paid_impressions,
                                           total_impressions, total_clicks,
                                           is_live, is_active, url, is_total)
        self.campaign_table.append(row)
Example #3
0
    def make_campaign_table(self):
        campaigns = PromoCampaign._by_link(self.thing._id)

        total_budget_dollars = 0.
        total_spent = 0
        total_paid_impressions = 0
        total_impressions = 0
        total_clicks = 0
        all_auction = True

        self.campaign_table = []
        for camp in campaigns:
            if not is_launched_campaign(camp):
                continue

            is_live = camp.is_live_now()
            self.has_early_campaign |= is_early_campaign(camp)
            self.has_live_campaign |= is_live

            history = list(get_billable_traffic(camp))

            if not history:
                impressions, clicks, spent = 0, 0, 0
            elif self.use_adserver_reporting:
                impressions, clicks, spent = map(
                    sum, zip(*[values for date, values in history]))
            else:
                impressions, clicks = map(
                    sum, zip(*[values for date, values in history]))
                spent = promote.get_spent_amount(camp)

            start = to_date(camp.start_date).strftime('%Y-%m-%d')
            end = to_date(camp.end_date).strftime('%Y-%m-%d')
            target = camp.target.pretty_name
            location = camp.location_str
            is_active = self.campaign and self.campaign._id36 == camp._id36
            url = '/traffic/%s/%s' % (self.thing._id36, camp._id36)
            is_total = False
            campaign_budget_dollars = camp.total_budget_dollars
            row = self.make_campaign_table_row(
                camp._id36,
                start=start,
                end=end,
                target=target,
                location=location,
                budget_dollars=campaign_budget_dollars,
                spent=spent,
                paid_impressions=camp.impressions,
                impressions=impressions,
                clicks=clicks,
                is_live=is_live,
                is_active=is_active,
                url=url,
                is_total=is_total,
                is_auction=camp.is_auction)
            self.campaign_table.append(row)

            total_budget_dollars += campaign_budget_dollars
            total_spent += spent
            total_paid_impressions += camp.impressions
            total_impressions += impressions
            total_clicks += clicks

            if not camp.is_auction:
                all_auction = False

        # total row
        start = '---'
        end = '---'
        target = '---'
        location = '---'
        is_live = False
        is_active = not self.campaign
        url = '/traffic/%s' % self.thing._id36
        row = self.make_campaign_table_row(
            _('total'),
            start=start,
            end=end,
            target=target,
            location=location,
            budget_dollars=total_budget_dollars,
            spent=total_spent,
            paid_impressions=total_paid_impressions,
            impressions=total_impressions,
            clicks=total_clicks,
            is_live=is_live,
            is_active=is_active,
            url=url,
            is_total=True,
            is_auction=all_auction)
        self.campaign_table.append(row)
Example #4
0
    def make_campaign_table(self):
        campaigns = PromoCampaign._by_link(self.thing._id)

        total_budget_dollars = 0.
        total_spent = 0
        total_paid_impressions = 0
        total_impressions = 0
        total_clicks = 0
        all_auction = True

        self.campaign_table = []
        for camp in campaigns:
            if not is_launched_campaign(camp):
                continue

            is_live = camp.is_live_now()
            self.has_early_campaign |= is_early_campaign(camp)
            self.has_live_campaign |= is_live

            history = list(get_billable_traffic(camp))

            if not history:
                impressions, clicks, spent = 0, 0, 0
            elif self.use_adserver_reporting:
                impressions, clicks, spent = map(sum, zip(*[values for date, values in history]))
            else:
                impressions, clicks = map(sum, zip(*[values for date, values in history]))
                spent = promote.get_spent_amount(camp)

            start = to_date(camp.start_date).strftime('%Y-%m-%d')
            end = to_date(camp.end_date).strftime('%Y-%m-%d')
            target = camp.target.pretty_name
            location = camp.location_str
            is_active = self.campaign and self.campaign._id36 == camp._id36
            url = '/traffic/%s/%s' % (self.thing._id36, camp._id36)
            is_total = False
            campaign_budget_dollars = camp.total_budget_dollars
            row = self.make_campaign_table_row(camp._id36,
                                               start=start,
                                               end=end,
                                               target=target,
                                               location=location,
                                               budget_dollars=campaign_budget_dollars,
                                               spent=spent,
                                               paid_impressions=camp.impressions,
                                               impressions=impressions,
                                               clicks=clicks,
                                               is_live=is_live,
                                               is_active=is_active,
                                               url=url,
                                               is_total=is_total,
                                               is_auction=camp.is_auction)
            self.campaign_table.append(row)

            total_budget_dollars += campaign_budget_dollars
            total_spent += spent
            total_paid_impressions += camp.impressions
            total_impressions += impressions
            total_clicks += clicks

            if not camp.is_auction:
                all_auction = False

        # total row
        start = '---'
        end = '---'
        target = '---'
        location = '---'
        is_live = False
        is_active = not self.campaign
        url = '/traffic/%s' % self.thing._id36
        row = self.make_campaign_table_row(_('total'),
                                           start=start,
                                           end=end,
                                           target=target,
                                           location=location,
                                           budget_dollars=total_budget_dollars,
                                           spent=total_spent,
                                           paid_impressions=total_paid_impressions,
                                           impressions=total_impressions,
                                           clicks=total_clicks,
                                           is_live=is_live,
                                           is_active=is_active,
                                           url=url,
                                           is_total=True,
                                           is_auction=all_auction)
        self.campaign_table.append(row)
Example #5
0
    def make_campaign_table(self):
        campaigns = PromoCampaign._by_link(self.thing._id)

        total_budget = 0
        total_spent = 0
        total_impressions = 0
        total_clicks = 0

        self.campaign_table = []
        for camp in campaigns:
            if not is_launched_campaign(camp):
                continue

            is_live = camp.is_live_now()
            self.has_early_campaign |= is_early_campaign(camp)
            self.has_live_campaign |= is_live

            history = get_billable_traffic(camp)
            impressions, clicks = 0, 0
            for date, (imp, click) in history:
                impressions += imp
                clicks += click

            start = to_date(camp.start_date).strftime("%Y-%m-%d")
            end = to_date(camp.end_date).strftime("%Y-%m-%d")
            target = camp.sr_name or "frontpage"
            spent = promote.get_spent_amount(camp)
            is_active = self.campaign and self.campaign._id36 == camp._id36
            url = "/traffic/%s/%s" % (self.thing._id36, camp._id36)
            is_total = False
            row = self.make_campaign_table_row(
                camp._id36, start, end, target, camp.bid, spent, impressions, clicks, is_live, is_active, url, is_total
            )
            self.campaign_table.append(row)

            total_budget += camp.bid
            total_spent += spent
            total_impressions += impressions
            total_clicks += clicks

        # total row
        start = "---"
        end = "---"
        target = "---"
        is_live = False
        is_active = not self.campaign
        url = "/traffic/%s" % self.thing._id36
        is_total = True
        row = self.make_campaign_table_row(
            _("total"),
            start,
            end,
            target,
            total_budget,
            total_spent,
            total_impressions,
            total_clicks,
            is_live,
            is_active,
            url,
            is_total,
        )
        self.campaign_table.append(row)