Beispiel #1
0
    def get_traffic(cls, thing, start, end):
        """Retrieve traffic by interval for a Promoted Link or PromoCampaign."""
        history = get_promo_traffic(thing, start, end)
        interval = cls.get_interval(thing)
        needs_hour_adjustment = _use_adserver_reporting(thing)
        promote_hour = promote.promo_datetime_now().hour

        computed_history = []
        for date, data in history:
            imps = data[0]
            clicks = data[1]
            spent = None if len(data) == 2 else data[2]
            ctr = _clickthrough_rate(imps, clicks)

            # replace hour to ensure that adserver dates appear correct
            # since we store them without the promotion hour.
            if needs_hour_adjustment:
                date = date.replace(hour=promote_hour)

            date = date.replace(tzinfo=pytz.utc)
            date = date.astimezone(pytz.timezone("EST"))
            datestr = format_datetime(
                date,
                locale=c.locale,
                format=cls.date_format_by_interval.get(interval),
            )
            values = ((imps, format_number(imps)), (clicks, format_number(clicks)), (ctr, format_number(ctr)))
            if spent is not None:
                values = ((spent, format_currency(spent, 'USD', locale=c.locale)),) + values
            computed_history.append((date, datestr, values))
        return computed_history
Beispiel #2
0
    def get_traffic(cls, thing, start, end):
        """Retrieve traffic by interval for a Promoted Link or PromoCampaign."""
        history = get_promo_traffic(thing, start, end)
        interval = cls.get_interval(thing)
        needs_hour_adjustment = _use_adserver_reporting(thing)
        promote_hour = promote.promo_datetime_now().hour

        computed_history = []
        for date, data in history:
            imps = data[0]
            clicks = data[1]
            spent = None if len(data) == 2 else data[2]
            ctr = _clickthrough_rate(imps, clicks)

            # replace hour to ensure that adserver dates appear correct
            # since we store them without the promotion hour.
            if needs_hour_adjustment:
                date = date.replace(hour=promote_hour)

            date = date.replace(tzinfo=pytz.utc)
            date = date.astimezone(pytz.timezone("EST"))
            datestr = format_datetime(
                date,
                locale=c.locale,
                format=cls.date_format_by_interval.get(interval),
            )
            values = ((imps, format_number(imps)), (clicks,
                                                    format_number(clicks)),
                      (ctr, format_number(ctr)))
            if spent is not None:
                values = ((spent, format_currency(
                    spent, 'USD', locale=c.locale)), ) + values
            computed_history.append((date, datestr, values))
        return computed_history
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 __init__(self, meetup, user, topic):
        self.meetup = meetup
        self.username = user.name
        self.link_karma = format_number(max(user.karma("link"), 0))
        self.comment_karma = format_number(max(user.karma("comment"), 0))
        self.registration_date = format_date(user._date, "medium", c.locale)

        self.code = "%02d" % utils.make_secret_code(meetup, user)
        self.url = "%s/or/%s/%s" % (g.shortdomain, user.name, self.code)

        if not topic:
            topic = random.choice(TOPICS.keys())
        starter = TOPICS[topic]
        self.starter = Storage(
            title=starter.title(),
            content=starter(user),
        )

        Templated.__init__(self)
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):

        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 #7
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,
        }