当前位置: 首页>>代码示例>>Python>>正文


Python Stats.increment方法代码示例

本文整理汇总了Python中stats.Stats.increment方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.increment方法的具体用法?Python Stats.increment怎么用?Python Stats.increment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stats.Stats的用法示例。


在下文中一共展示了Stats.increment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: checkArguments

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import increment [as 别名]
    print "Usage:"
    print "python test_yahoo_categories.py URLS [OPTIONS]";
    print ""
    print "Load urls and record Yahoo's categorization of them."
    print "[OPTIONS] is used to pass configuration parameters to PhantomJS"
    sys.exit(0);
    
checkArguments();
stats = Stats();
adExtractor = AdExtractor();

f = open(sys.argv[1]);
urls = f.readlines();
f.close();

categories = [];

for i in range(len(urls)):
  urls[i] = urls[i].replace('\n','');
  result = adExtractor.queryYahoo(urls[i]);
  try:
    for i in range(len(result['category'])):
      cat = result['category'][i]['category'];
      if not cat in categories:
        categories.append(cat);
  except:
    stats.increment('Category detection failed', 1);
    
categories.sort();
for i in range(len(categories)):
  print categories[i];
开发者ID:SoveraNia,项目名称:targeted_ads,代码行数:33,代码来源:test_yahoo_categories.py

示例2: expanduser

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import increment [as 别名]
class AdExtractor:
  # Ad category db
  ad_db_filename = expanduser('~') + '/Lab_TargetedAds/src/resources/ad_db.json';
  ad_db = {};
  
  # Redirection DB
  redirection_db_filename = expanduser('~') + '/Lab_TargetedAds/src/resources/redirection_db.json'
  redirection_db = {};
  
  ad_providers_filename = expanduser('~') + '/Lab_TargetedAds/src/resources/ad_providers.json'
  ad_providers = [];
  
  category_mapping_alexa_filename = expanduser('~') + '/Lab_TargetedAds/src/resources/category_mapping_alexa.json'
  category_mapping_alexa = {};
  
  category_mapping_yahoo_filename = expanduser('~') + '/Lab_TargetedAds/src/resources/category_mapping_yahoo.json'
  category_mapping_yahoo = {};
  
  category_mapping_alchemy_filename = expanduser('~') + '/Lab_TargetedAds/src/resources/category_mapping_alchemy.json'
  category_mapping_alchemy = {};
  
  category_mapping_bluecoat_filename = expanduser('~') + '/Lab_TargetedAds/src/resources/category_mapping_bluecoat.json'
  category_mapping_bluecoat = {};
  
  def __init__(self):
    f = open(self.ad_db_filename);
    self.ad_db = json.load(f);
    f.close();
    f = open(self.redirection_db_filename);
    self.redirection_db = json.load(f);
    f.close();
    f = open(self.ad_providers_filename);
    self.ad_providers = json.load(f);
    f.close();
    
    f = open(self.category_mapping_alexa_filename);
    self.category_mapping_alexa = json.load(f);
    f.close();
    f = open(self.category_mapping_yahoo_filename);
    self.category_mapping_yahoo = json.load(f);
    f.close();
    f = open(self.category_mapping_alchemy_filename);
    self.category_mapping_alchemy = json.load(f);
    f.close();
    f = open(self.category_mapping_bluecoat_filename);
    self.category_mapping_bluecoat = json.load(f);
    f.close();
    
    self.stats = Stats('Ad Extracting Statistics');
  
  def isAdProvider(self, url):
    host = url.split('?')[0];
    for i in range(len(self.ad_providers)):
      try: # In case of encode error
        if self.ad_providers[i] in host:
          return True;
      except:
        continue;
    return False;
  
  def getAdProviders(self, url):
    ret = [];
    for i in range(len(self.ad_providers)):
      try: # In case of encode error
        if self.ad_providers[i] in url and not self.ad_providers[i] in ret:
          ret.append(self.ad_providers[i]);
      except:
        continue;
    return ret;
  
  def getLandingUrl(self, url):
    if self.isAdProvider(url):
      result = self.detectRedirection(url);
      if result != "NONE":
        return result.lower();
      else:
        return "NONE"
    else:
      return url.lower();
    
  def getLandingDomain(self, url):
    return url2Domain(self.getLandingUrl(url));
  
  def detectRedirection(self, url):
    # return "NONE"; # If we don't want to detect redirection
    if url[:4] != "http":
      return 'NONE' # TODO: Handle flashvars, may need decoding.
    
    if url in self.redirection_db:
      self.stats.increment('Redirection DB hit', 1);
      return self.redirection_db[url];
    self.stats.increment('Redirection DB miss', 1);
    
    command = "~/Lab_TargetedAds/phantomjs/phantomjs--linux-x86_64/bin/phantomjs ~/Lab_TargetedAds/src/bin/detect_redirection.js '";
    command += url + "'";
    results = runCommand(command);
    self.stats.increment('Ad link clicked', 1);
    for i in range(len(results)):
      results[i] = results[i].split('\t');
      if len(results[i]) >= 3 and results[i][0] == '<MSG><RESULT>' and results[i][1] == "Destination":
#.........这里部分代码省略.........
开发者ID:SoveraNia,项目名称:targeted_ads,代码行数:103,代码来源:ad_extract.py


注:本文中的stats.Stats.increment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。