Beispiel #1
0
 def get_raw_od_imp(now, minute_duration=5, skip_duration=5):
     start_time = now - datetime.timedelta(minutes=minute_duration)
     end_time = now - datetime.timedelta(minutes=skip_duration)
     return list(MongoDbUtils.get_user_activity_collection().aggregate(
         [{'$match': {'time': {'$gt': start_time, '$lt': end_time}}},
          {'$group': {'imp': {'$sum': '$count'}, '_id': {'time': '$time', 'order_item_id': '$orderItemId'}}}],
         allowDiskUse=True
     ))
Beispiel #2
0
    def update_dict():
        comb_dict = Dict()
        time = datetime.datetime.now()
        raw_log = Dict.get_raw_info(time.date())
        for log in raw_log:
            if log[comb_dict.param_index['order_item_id']] not in comb_dict.dict_od_info:
                comb_dict.add_od(log)
            else:
                comb_dict.append_od(log)

        for value in comb_dict.dict_od_info.values():
            comb_dict.list_od_info.append(value)

        for info in comb_dict.list_od_info:
            MongoDbUtils.get_dict_collection().replace_one({"order_item_id": info['order_item_id']}, info, True)

        MongoDbUtils.get_dict_collection().delete_many(
            {"end_date": time.replace(hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(1)}
        )

        size = MongoDbUtils.get_dict_collection().count()
        LogUtils.info("Finish the order item dict synchronization successfully, dict size = %s" % size)
Beispiel #3
0
 def update_ods():
     order_items = OrderItems()
     all_order_item_list = list(MongoDbUtils.get_dict_collection().find())
     combs = Comb.comb
     for comb in combs:
         order_item_dict = dict()
         order_item_dict[OrderItemList.name] = comb[CombFields.name]
         order_item_dict[OrderItemList.alias] = comb[CombFields.alias]
         if len(comb.get(CombFields.condition, [])) == 0:
             order_item_list = []
             for order_item in all_order_item_list:
                 order_item_list.append(order_item)
             order_item_dict[OrderItemList.order_item] = order_item_list
         elif len(comb.get(CombFields.condition, [])) == 1:
             order_item_dict[OrderItemList.order_item] = order_items.filter_one_condition(
                 all_order_item_list, comb.get(CombFields.condition)[0]
             )
         else:
             order_item_dict[OrderItemList.order_item] = order_items.filter_multiple_conditions(
                 all_order_item_list, comb.get(CombFields.condition)
             )
         LogUtils.info("Finish generating the order item list %s, the size = %d" % (comb.get('alias'), len(order_item_dict[OrderItemList.order_item])))
         OrderItems.ods[comb[CombFields.alias]] = order_item_dict
Beispiel #4
0
 def init():
     Comb.comb = list(MongoDbUtils.get_comb_collection().find())
Beispiel #5
0
 def get(self):
     Comb.comb = list(MongoDbUtils.get_comb_collection().find())
     return json.dumps(Comb.comb, default=json_util.default)