Beispiel #1
0
 def __init__(self, link):
     self.thing = link
     self.edit_url = promote.promo_edit_url(link)
     self.is_preliminary = False
     campaigns = PromoCampaign._by_link(link._id)
     camps = {}
     fullnames = []
     for campaign in campaigns:
         campaign.imps = 0
         campaign.clicks = 0
         self.is_preliminary |= _is_promo_preliminary(campaign.end_date)
         camps[campaign._fullname] = campaign
         fullnames.append(campaign._fullname)
     click_data = traffic.TargetedClickthroughsByCodename.total_by_codename(
         fullnames)
     for fullname, clicks in click_data:
         camps[fullname].clicks = clicks
     imp_data = traffic.TargetedImpressionsByCodename.total_by_codename(
         fullnames)
     for fullname, imps in imp_data:
         camps[fullname].imps = imps
     self.campaigns = camps.values()
     self.total_clicks = self.total_imps = self.total_spend = 0
     for camp in self.campaigns:
         self.total_clicks += camp.clicks
         self.total_imps += camp.imps
         self.total_spend += camp.bid
         camp.ctr = _clickthrough_rate(camp.imps, camp.clicks)
         camp.cpc = cost_per_click(camp.bid, camp.clicks)
         camp.cpm = cost_per_mille(camp.bid, camp.imps)
     self.total_ctr = _clickthrough_rate(self.total_imps, self.total_clicks)
     self.total_cpc = cost_per_click(self.total_spend, self.total_clicks)
     self.total_cpm = cost_per_mille(self.total_spend, self.total_imps)
     Templated.__init__(self)
Beispiel #2
0
 def __init__(self, link):
     self.thing = link
     self.edit_url = promote.promo_edit_url(link)
     self.is_preliminary = False
     campaigns = PromoCampaign._by_link(link._id)
     camps = {}
     fullnames = []
     for campaign in campaigns:
         campaign.imps = 0
         campaign.clicks = 0
         self.is_preliminary |= _is_promo_preliminary(campaign.end_date)
         camps[campaign._fullname] = campaign
         fullnames.append(campaign._fullname)
     click_data = traffic.TargetedClickthroughsByCodename.total_by_codename(
         fullnames)
     for fullname, clicks in click_data:
         camps[fullname].clicks = clicks
     imp_data = traffic.TargetedImpressionsByCodename.total_by_codename(
         fullnames)
     for fullname, imps in imp_data:
         camps[fullname].imps = imps
     self.campaigns = camps.values()
     self.total_clicks = self.total_imps = self.total_spend = 0
     for camp in self.campaigns:
         self.total_clicks += camp.clicks
         self.total_imps += camp.imps
         self.total_spend += camp.bid
         camp.ctr = _clickthrough_rate(camp.imps, camp.clicks)
         camp.cpc = cost_per_click(camp.bid, camp.clicks)
         camp.cpm = cost_per_mille(camp.bid, camp.imps)
     self.total_ctr = _clickthrough_rate(self.total_imps, self.total_clicks)
     self.total_cpc = cost_per_click(self.total_spend, self.total_clicks)
     self.total_cpm = cost_per_mille(self.total_spend, self.total_imps)
     Templated.__init__(self)
Beispiel #3
0
    def make_campaign_table_row(cls, id, start, end, target, bid, impressions,
                                clicks, is_live, is_active, url, is_total):
        if impressions:
            cpm = format_currency(promote.cost_per_mille(bid, impressions),
                                  'USD',
                                  locale=c.locale)
        else:
            cpm = '---'

        if clicks:
            cpc = format_currency(promote.cost_per_click(bid, clicks),
                                  'USD',
                                  locale=c.locale)
            ctr = format_number(_clickthrough_rate(impressions, clicks))
        else:
            cpc = '---'
            ctr = '---'

        return {
            'id': id,
            'start': start,
            'end': end,
            'target': target,
            'bid': format_currency(bid, 'USD', locale=c.locale),
            'impressions': format_number(impressions),
            'cpm': cpm,
            'clicks': format_number(clicks),
            'cpc': cpc,
            'ctr': ctr,
            'live': is_live,
            'active': is_active,
            'url': url,
            'csv': url + '.csv',
            'total': is_total,
        }
Beispiel #4
0
    def make_campaign_table_row(cls, id, start, end, target, bid, impressions,
                                clicks, is_live, is_active, url, is_total):
        if impressions:
            cpm = format_currency(promote.cost_per_mille(bid, impressions),
                                  'USD', locale=c.locale)
        else:
            cpm = '---'

        if clicks:
            cpc = format_currency(promote.cost_per_click(bid, clicks), 'USD',
                                  locale=c.locale)
            ctr = format_number(_clickthrough_rate(impressions, clicks))
        else:
            cpc = '---'
            ctr = '---'

        return {
            'id': id,
            'start': start,
            'end': end,
            'target': target,
            'bid': format_currency(bid, 'USD', locale=c.locale),
            'impressions': format_number(impressions),
            'cpm': cpm,
            'clicks': format_number(clicks),
            'cpc': cpc,
            'ctr': ctr,
            'live': is_live,
            'active': is_active,
            'url': url,
            'csv': url + '.csv',
            'total': is_total,
        }
Beispiel #5
0
    def make_campaign_table_row(cls, id, start, end, target, location,
                                budget_dollars, spent, paid_impressions,
                                impressions, clicks, is_live, is_active, url,
                                is_total):

        if impressions:
            cpm = format_currency(promote.cost_per_mille(spent, impressions),
                                  'USD',
                                  locale=c.locale)
        else:
            cpm = '---'

        if clicks:
            cpc = format_currency(promote.cost_per_click(spent, clicks),
                                  'USD',
                                  locale=c.locale)
            ctr = format_number(_clickthrough_rate(impressions, clicks))
        else:
            cpc = '---'
            ctr = '---'

        return {
            'id': id,
            'start': start,
            'end': end,
            'target': target,
            'location': location,
            'budget': format_currency(budget_dollars, 'USD', locale=c.locale),
            'spent': format_currency(spent, 'USD', locale=c.locale),
            'impressions_purchased': format_number(paid_impressions),
            'impressions_delivered': format_number(impressions),
            'cpm': cpm,
            'clicks': format_number(clicks),
            'cpc': cpc,
            'ctr': ctr,
            'live': is_live,
            'active': is_active,
            'url': url,
            'csv': url + '.csv',
            'total': is_total,
        }
Beispiel #6
0
    def make_campaign_table_row(cls,
                                id,
                                start,
                                end,
                                target,
                                location,
                                budget_dollars,
                                spent,
                                paid_impressions,
                                impressions,
                                clicks,
                                is_live,
                                is_active,
                                url,
                                is_total,
                                is_auction=False):

        if impressions:
            cpm = format_currency(promote.cost_per_mille(spent, impressions),
                                  'USD',
                                  locale=c.locale)
        else:
            cpm = '---'

        if clicks:
            cpc = format_currency(promote.cost_per_click(spent, clicks),
                                  'USD',
                                  locale=c.locale)
            ctr = format_number(_clickthrough_rate(impressions, clicks))
        else:
            cpc = '---'
            ctr = '---'

        if feature.is_enabled("legacy_ad_reporting"):
            url_query = "?feature=legacy_ad_reporting"
        else:
            url_query = ""

        return {
            'id':
            id,
            'start':
            start,
            'end':
            end,
            'target':
            target,
            'location':
            location,
            'budget':
            format_currency(budget_dollars, 'USD', locale=c.locale),
            'spent':
            format_currency(spent, 'USD', locale=c.locale),
            'impressions_purchased':
            "---" if is_auction else format_number(paid_impressions),
            'impressions_delivered':
            format_number(impressions),
            'cpm':
            cpm,
            'clicks':
            format_number(clicks),
            'cpc':
            cpc,
            'ctr':
            ctr,
            'live':
            is_live,
            'active':
            is_active,
            'url': (url + url_query),
            'csv': (url + '.csv' + url_query),
            'total':
            is_total,
        }