59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
import traceback
|
|
|
|
from pymongo import UpdateOne
|
|
from pydantic import Field
|
|
import pandas as pd
|
|
|
|
from .task import Task
|
|
from utils import *
|
|
from model import GBaseModel, IntStr, MdbObjectId
|
|
|
|
|
|
class SummaryFunnel(Task):
|
|
"""
|
|
功能分析
|
|
"""
|
|
|
|
class Model(GBaseModel):
|
|
id: MdbObjectId = Field(..., title="id", alias='_id')
|
|
cdate: int = Field(..., title='当天0点')
|
|
|
|
def cleaning(self, cursor_list):
|
|
funnel_conf = self.local_db['attr'].find_one({'pname': 'funnel'}, {'data': True})
|
|
if not funnel_conf:
|
|
ddsend_msg(f'{self.game_name} 请设置漏斗配置')
|
|
return
|
|
step_list = list({step['cond']['step'] for step in funnel_conf['data']['steps'] if step['cond']['step']})
|
|
|
|
for cursor in cursor_list: # type:dict
|
|
for source_coll, ts in cursor.items(): # type:str,dict
|
|
if ts['cursor_st'] == ts['cursor_et']:
|
|
continue
|
|
logger.info(f'开始处理{self.game_name} 处理 {source_coll} 游标 {ts}')
|
|
where = {
|
|
'_event_name': 'Guide',
|
|
'step': {'$in': step_list},
|
|
'_ut': {
|
|
'$gte': ts['cursor_st'],
|
|
'$lt': ts['cursor_et'],
|
|
}
|
|
}
|
|
|
|
bulk_data = []
|
|
for item in self.local_db[source_coll].find(where): # 所有字段
|
|
try:
|
|
item['cdate'] = int(pd.Timestamp(item['_event_time'], unit='s', tz=self.timezone) \
|
|
.normalize().timestamp())
|
|
model = self.Model(**item)
|
|
data = model.dict(by_alias=True)
|
|
data.update(item)
|
|
bulk_data.append(UpdateOne({'_id': data['_id']}, {'$set': data}, upsert=True))
|
|
except Exception as e:
|
|
msg = traceback.format_exc()
|
|
ddsend_msg(f'{self.game_name}.{source_coll}字段异常 {msg}')
|
|
logger.error(repr(e))
|
|
if bulk_data:
|
|
self.local_db[self.dest_coll].bulk_write(bulk_data, ordered=False)
|
|
self.remote_db[self.dest_coll].bulk_write(bulk_data, ordered=False)
|
|
self.set_cursor(cursor_st=ts['cursor_st'], cursor_et=ts['cursor_et'])
|