Esempio n. 1
0
    def post(self):
        from collections import defaultdict
        payload_string = self.request.get('payload')
        counter_targets = Payload.deserialize(payload_string)
        today = time_util.today()

        product_targets = defaultdict(int)
        user_targets = defaultdict(int)

        for payload in counter_targets:
            daily_product_key = ProductCounter.build_key_name(
                payload.url, DAILY, today)
            weekly_product_key = ProductCounter.build_key_name(
                payload.url, WEEKLY, today)
            monthly_product_key = ProductCounter.build_key_name(
                payload.url, MONTHLY, today)
            user_key = UserCounter.build_key_name(payload.user_id, DAILY,
                                                  today)
            product_targets[daily_product_key] += 1
            product_targets[weekly_product_key] += 1
            product_targets[monthly_product_key] += 1
            user_targets[user_key] += 1

        product_counters = ProductCounter.get_by_key_name(
            product_targets.keys(),
            _storage=[MEMCACHE, DATASTORE],
            _result_type=NAME_DICT)
        user_counters = UserCounter.get_by_key_name(user_targets.keys(),
                                                    _result_type=NAME_DICT)

        for key_name, delta in product_targets.iteritems():
            try:
                product_counters[key_name].count += delta
            except AttributeError:  #Value is None in dict
                frequency = ProductCounter.frequency_from_key_name(key_name)
                product_counters[key_name] = ProductCounter.new(
                    key_name,
                    frequency,
                    today,
                    count=delta,
                    _build_key_name=False)

        for key_name, delta in user_targets.iteritems():
            try:
                user_counters[key_name].count += delta
            except AttributeError:  #Value is None in dict
                user_counters[key_name] = UserCounter.new(
                    key_name, DAILY, today, count=delta, _build_key_name=False)

        ProductCounter.filtered_update(product_counters.values())
        UserCounter.filtered_update(user_counters.values())
Esempio n. 2
0
  def post(self):
    from collections import defaultdict
    payload_string = self.request.get('payload')
    counter_targets = Payload.deserialize(payload_string)
    today = time_util.today()
    
    product_targets = defaultdict(int)
    user_targets = defaultdict(int)
    
    for payload in counter_targets:
      daily_product_key = ProductCounter.build_key_name(payload.url, DAILY, today)
      weekly_product_key = ProductCounter.build_key_name(payload.url, WEEKLY, today)
      monthly_product_key = ProductCounter.build_key_name(payload.url, MONTHLY, today)
      user_key = UserCounter.build_key_name(payload.user_id, DAILY, today)
      product_targets[daily_product_key] += 1
      product_targets[weekly_product_key] += 1
      product_targets[monthly_product_key] += 1
      user_targets[user_key] += 1
        
    product_counters = ProductCounter.get_by_key_name(product_targets.keys(),
                                                      _storage = [MEMCACHE,DATASTORE],
                                                      _result_type=NAME_DICT)
    user_counters = UserCounter.get_by_key_name(user_targets.keys(),
                                                _result_type=NAME_DICT)
        
    for key_name,delta in product_targets.iteritems():
      try:
        product_counters[key_name].count += delta
      except AttributeError: #Value is None in dict
        frequency = ProductCounter.frequency_from_key_name(key_name)
        product_counters[key_name] = ProductCounter.new(key_name, frequency, today,
                                                   count=delta,_build_key_name = False)

    for key_name,delta in user_targets.iteritems():  
      try:
        user_counters[key_name].count += delta
      except AttributeError: #Value is None in dict
        user_counters[key_name] = UserCounter.new(key_name, DAILY, today,
                                             count=delta,_build_key_name = False)
                
    ProductCounter.filtered_update(product_counters.values())
    UserCounter.filtered_update(user_counters.values())
Esempio n. 3
0
 def get(self):
   date = yesterday()
   enqueue_renderer_update(WEEKLY,date)
   enqueue_renderer_update(MONTHLY,date)
   enqueue_cleanup(UserCounter.kind(), DAILY, date)
   enqueue_cleanup(ProductCounter.kind(), DAILY, date)
   enqueue_cleanup(ProductRenderer.kind(), DAILY, date)
   enqueue_cleanup(ProductRenderer.kind(), WEEKLY, date,countdown = 3600)
   enqueue_cleanup(ProductRenderer.kind(), MONTHLY, date,countdown = 3600)
   
   #Delete banlist so it is refreshed with latest banned entities
   banlist = Banlist.retrieve()
   banlist.delete()