43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from pymongo import UpdateOne
|
|
from pydantic import Field
|
|
|
|
from .task import Task
|
|
from utils import *
|
|
from db import GBaseModel
|
|
|
|
|
|
class SummaryFunc(Task):
|
|
"""
|
|
功能分析
|
|
"""
|
|
|
|
class Model(GBaseModel):
|
|
prize: list = Field(None, title='奖励')
|
|
need: list = Field(None, title='消耗')
|
|
ftype: str = Field(..., title='功能')
|
|
data: dict = Field(None, title='功能数据')
|
|
|
|
def cleaning(self, cursor_list):
|
|
for cursor in cursor_list: # type:dict
|
|
for event_coll, ts in cursor.items(): # type:str,dict
|
|
logger.info(f'开始处理{self.game_name} 处理 {event_coll} ...')
|
|
where = {
|
|
'_event_name': 'Func',
|
|
'_event_time': {
|
|
'$gte': ts['cursor_st'],
|
|
'$lt': ts['cursor_et'],
|
|
}
|
|
}
|
|
|
|
projection = self.Model.get_fields()
|
|
bulk_data = []
|
|
for item in self.local_db[event_coll].find(where, projection):
|
|
try:
|
|
model = self.Model(**item)
|
|
data = model.dict()
|
|
bulk_data.append(UpdateOne({'_id': data['_id']}, {'$set': data}, upsert=True))
|
|
except Exception as e:
|
|
logger.error(e)
|
|
self.remote_db[self.task_name].bulk_write(bulk_data, ordered=False)
|
|
self.set_cursor(cursor_st=ts['cursor_st'], cursor_et=ts['cursor_et'])
|