當前位置: 首頁>>代碼示例>>Python>>正文


Python PromoMetrics.get方法代碼示例

本文整理匯總了Python中r2.models.promo_metrics.PromoMetrics.get方法的典型用法代碼示例。如果您正苦於以下問題:Python PromoMetrics.get方法的具體用法?Python PromoMetrics.get怎麽用?Python PromoMetrics.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在r2.models.promo_metrics.PromoMetrics的用法示例。


在下文中一共展示了PromoMetrics.get方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_predicted_pageviews

# 需要導入模塊: from r2.models.promo_metrics import PromoMetrics [as 別名]
# 或者: from r2.models.promo_metrics.PromoMetrics import get [as 別名]
def get_predicted_pageviews(srs, start, end):
    srs, is_single = tup(srs, ret_is_single=True)
    sr_names = [sr.name for sr in srs]

    # default subreddits require a different inventory factor
    content_langs = [g.site_lang]
    default_srids = Subreddit.top_lang_srs(content_langs,
                                           limit=g.num_default_reddits,
                                           filter_allow_top=True, over18=False,
                                           ids=True)

    # prediction does not vary by date
    daily_inventory = PromoMetrics.get(MIN_DAILY_CASS_KEY, sr_names=sr_names)
    dates = get_date_range(start, end)
    ret = {}
    for sr in srs:
        if not isinstance(sr, FakeSubreddit) and sr._id in default_srids:
            factor = DEFAULT_INVENTORY_FACTOR
        else:
            factor = INVENTORY_FACTOR
        sr_daily_inventory = daily_inventory.get(sr.name, 0) * factor
        sr_daily_inventory = int(sr_daily_inventory)
        ret[sr.name] = dict.fromkeys(dates, sr_daily_inventory)

    if is_single:
        return ret[srs[0].name]
    else:
        return ret
開發者ID:SDGXDX,項目名稱:reddit,代碼行數:30,代碼來源:inventory.py

示例2: get_predicted_by_date

# 需要導入模塊: from r2.models.promo_metrics import PromoMetrics [as 別名]
# 或者: from r2.models.promo_metrics.PromoMetrics import get [as 別名]
def get_predicted_by_date(sr_name, start, stop=None):
    """Return dict mapping datetime objects to predicted pageviews."""
    # lowest pageviews any day the last 2 weeks
    min_daily = PromoMetrics.get(MIN_DAILY_CASS_KEY, sr_name).get(sr_name, 0)
    # expand out to the requested range of dates
    ndays = (stop - start).days if stop else 1  # default is one day
    predicted = OrderedDict()
    for i in range(ndays):
        date = start + timedelta(i)
        predicted[date] = min_daily
    return predicted
開發者ID:Anenome,項目名稱:reddit,代碼行數:13,代碼來源:inventory.py

示例3: get_predicted_by_date

# 需要導入模塊: from r2.models.promo_metrics import PromoMetrics [as 別名]
# 或者: from r2.models.promo_metrics.PromoMetrics import get [as 別名]
def get_predicted_by_date(sr_name, start, stop=None):
    """
    For now, use lowest pageviews in the subreddit any day the last two weeks
    as a simple heuristic.
    """
    # lowest pageviews any day the last 2 weeks
    min_daily = PromoMetrics.get(CassKeys.MIN_DAILY, sr_name).get(sr_name, 0)
    # expand out to the requested range of dates
    ndays = (stop - start).days if stop else 1  # default is one day
    predicted = OrderedDict()
    for i in range(ndays):
        date = start + timedelta(i)
        predicted[date] = min_daily
    return predicted
開發者ID:redcn,項目名稱:reddit,代碼行數:16,代碼來源:inventory.py

示例4: get_predicted_pageviews

# 需要導入模塊: from r2.models.promo_metrics import PromoMetrics [as 別名]
# 或者: from r2.models.promo_metrics.PromoMetrics import get [as 別名]
def get_predicted_pageviews(srs, start, end):
    srs, is_single = tup(srs, ret_is_single=True)
    sr_names = [sr.name for sr in srs]

    # prediction does not vary by date
    daily_inventory = PromoMetrics.get(MIN_DAILY_CASS_KEY, sr_names=sr_names)
    dates = get_date_range(start, end)
    ret = {}
    for sr in srs:
        sr_daily_inventory = daily_inventory.get(sr.name, 0) * INVENTORY_FACTOR
        sr_daily_inventory = int(sr_daily_inventory)
        ret[sr.name] = dict.fromkeys(dates, sr_daily_inventory)

    if is_single:
        return ret[srs[0].name]
    else:
        return ret
開發者ID:AD42,項目名稱:reddit,代碼行數:19,代碼來源:inventory.py

示例5: get_predicted_pageviews

# 需要導入模塊: from r2.models.promo_metrics import PromoMetrics [as 別名]
# 或者: from r2.models.promo_metrics.PromoMetrics import get [as 別名]
def get_predicted_pageviews(srs, location=None):
    """
    Return predicted number of pageviews for sponsored headlines.

    Predicted geotargeted impressions are estimated as:

    geotargeted impressions = (predicted untargeted impressions) *
                                 (fp impressions for location / fp impressions)

    """

    srs, is_single = tup(srs, ret_is_single=True)
    sr_names = [sr.name for sr in srs]

    # default subreddits require a different inventory factor
    default_srids = LocalizedDefaultSubreddits.get_global_defaults()

    if location:
        no_location = Location(None)
        r = LocationPromoMetrics.get(DefaultSR, [no_location, location])
        location_pageviews = r[(DefaultSR, location)]
        all_pageviews = r[(DefaultSR, no_location)]
        if all_pageviews:
            location_factor = float(location_pageviews) / float(all_pageviews)
        else:
            location_factor = 0.
    else:
        location_factor = 1.0

    # prediction does not vary by date
    daily_inventory = PromoMetrics.get(MIN_DAILY_CASS_KEY, sr_names=sr_names)
    ret = {}
    for sr in srs:
        if not isinstance(sr, FakeSubreddit) and sr._id in default_srids:
            default_factor = DEFAULT_INVENTORY_FACTOR
        else:
            default_factor = INVENTORY_FACTOR
        base_pageviews = daily_inventory.get(sr.name, 0)
        ret[sr.name] = int(base_pageviews * default_factor * location_factor)

    if is_single:
        return ret[srs[0].name]
    else:
        return ret
開發者ID:AHAMED750,項目名稱:reddit,代碼行數:46,代碼來源:inventory.py

示例6: get_predicted_pageviews

# 需要導入模塊: from r2.models.promo_metrics import PromoMetrics [as 別名]
# 或者: from r2.models.promo_metrics.PromoMetrics import get [as 別名]
def get_predicted_pageviews(srs):
    srs, is_single = tup(srs, ret_is_single=True)
    sr_names = [sr.name for sr in srs]

    # default subreddits require a different inventory factor
    default_srids = LocalizedDefaultSubreddits.get_global_defaults()

    # prediction does not vary by date
    daily_inventory = PromoMetrics.get(MIN_DAILY_CASS_KEY, sr_names=sr_names)
    ret = {}
    for sr in srs:
        if not isinstance(sr, FakeSubreddit) and sr._id in default_srids:
            factor = DEFAULT_INVENTORY_FACTOR
        else:
            factor = INVENTORY_FACTOR
        ret[sr.name] = int(daily_inventory.get(sr.name, 0) * factor)

    if is_single:
        return ret[srs[0].name]
    else:
        return ret
開發者ID:2bj,項目名稱:reddit,代碼行數:23,代碼來源:inventory.py

示例7: get_available_pageviews

# 需要導入模塊: from r2.models.promo_metrics import PromoMetrics [as 別名]
# 或者: from r2.models.promo_metrics.PromoMetrics import get [as 別名]
def get_available_pageviews(srs, start, end, datestr=False,
                            ignore=None):
    srs, is_single = tup(srs, ret_is_single=True)
    sr_names = [sr.name for sr in srs]
    daily_inventory = PromoMetrics.get(MIN_DAILY_CASS_KEY, sr_names=sr_names)
    sold_by_sr_by_date = get_sold_pageviews(srs, start, end, ignore)

    datekey = lambda dt: dt.strftime('%m/%d/%Y') if datestr else dt

    ret = {}
    for sr in srs:
        sold_by_date = sold_by_sr_by_date[sr.name]
        sr_ad_inventory = int(daily_inventory.get(sr.name, 0) * 1.00)
        ret[sr.name] = {
            datekey(date): max(0, sr_ad_inventory - sold)
            for date, sold in sold_by_date.iteritems()
        }

    if is_single:
        return ret[srs[0].name]
    else:
        return ret
開發者ID:Alex-Quinn,項目名稱:reddit,代碼行數:24,代碼來源:inventory.py


注:本文中的r2.models.promo_metrics.PromoMetrics.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。