From 17b52f943be8649c7afbe5bbd0a67178daafdf71 Mon Sep 17 00:00:00 2001 From: pengtao Date: Mon, 12 Aug 2019 16:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=81=93=E5=85=B7=20?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=9B=BE=E7=9A=84=E6=95=B0=E6=8D=AE=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.py | 2 +- mytask/tasks_base.py | 16 ++++++++- mytask/tga.py | 85 ++++++++++++++++++++++++++++++++++++++++++++ ops/scripts.py | 20 +++++++++++ 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 ops/scripts.py diff --git a/config/config.py b/config/config.py index fdadeab..28490e6 100644 --- a/config/config.py +++ b/config/config.py @@ -14,4 +14,4 @@ if not is_debug: (1016, 6001, 'shop_1016'), (1016, 6001, 'shop_new_1016'), (1016, 6001, 'tap_1016'), (1016, 6001, 'tap_new_1016'), (2001, 6001, 'tap_2001'), (2001, 6001, 'tap_new_2001')) else: - event_list = ((1001, 6001, 'vistis_page'), (1001, 6001, 'ad_info')) + event_list = ((1001, 6001, 'items_produce'), (1001, 6001, 'items_consum'),(1001, 6001, 'share_map')) diff --git a/mytask/tasks_base.py b/mytask/tasks_base.py index e9542da..266052b 100644 --- a/mytask/tasks_base.py +++ b/mytask/tasks_base.py @@ -44,4 +44,18 @@ def run_event_vistis_page(kwargs): def run_event_ad_info(kwargs): mytga = TGA_event(**kwargs) - mytga.event_ad_info() \ No newline at end of file + mytga.event_ad_info() + + +def run_event_items_produce(kwargs): + mytga = TGA_event(**kwargs) + mytga.event_items_produce() + + +def run_event_items_consum(kwargs): + mytga = TGA_event(**kwargs) + mytga.event_items_consum() + +def run_event_share_map(kwargs): + mytga = TGA_event(**kwargs) + mytga.event_share_map() diff --git a/mytask/tga.py b/mytask/tga.py index 6e8e4e0..8f887d3 100644 --- a/mytask/tga.py +++ b/mytask/tga.py @@ -5,6 +5,8 @@ import logging import requests import json from config.config import is_debug, adv_id_state, ad_type +from ops.scripts import get_activity_ids + define_logger("/data/logs/reports.log") log = logging.getLogger(__name__) @@ -268,3 +270,86 @@ class GetFromTga: self.write_tga_files(temp) except Exception: print(f"write {line} 2 tga!", exc_info=True) + + + def event_items_produce(self): + sql = f"""SELECT + sum(item_cnt) as item_num, + item_id, + reason , + reason_param + FROM + v_event_19 + where + gameid='{self.gameid}' + and "channel"='{self.channelid}' + and "$part_event"='event_11_8' + and "$part_date"='{self.date}' + group by + item_id, + reason, + reason_param """ + out = self.tga.get_data(sql) + if out: + for line in out: + try: + temp = {} + temp['nums'], temp['item_id'], temp['reason'], temp['reason_param'] = line + self.write_tga_files(temp) + except Exception: + print(f"write {line} 2 tga failed!", exc_info=True) + + def event_items_consum(self): + sql = f"""SELECT + sum(item_cnt) as item_num, + item_id, + reason , + reason_param + FROM + v_event_{self.suffix} + where + gameid='{self.gameid}' + and "channel"='{self.channelid}' + and "$part_event"='event_11_9' + and "$part_date"='{self.date}' + group by + item_id, + reason, + reason_param """ + out = self.tga.get_data(sql) + if out: + for line in out: + try: + temp = {} + temp['nums'], temp['item_id'], temp['reason'], temp['reason_param'] = line + self.write_tga_files(temp) + except Exception: + print(f"write {line} 2 tga failed!", exc_info=True) + + def event_share_map(self): + activity_ids = get_activity_ids() + + sql = f"""SELECT + count(1) AS num , + count(DISTINCT "#account_id") AS u_num, + activity_id_str + FROM + v_event_19 + WHERE + gameid='1001' + AND "$part_event"='event_11_10' + AND "$part_date"='2019-08-07' + GROUP BY + activity_id_str""" + + out = self.tga.get_data(sql) + if out: + for line in out: + temp = {} + if line: + try: + temp['num'], temp['u_num'], temp['activity_id_str'] = line + temp['activity_id'] = activity_ids.get(temp['activity_id_str']) + self.write_tga_files(temp) + except Exception: + print(f"write {line} 2 tga failed!", exc_info=True) diff --git a/ops/scripts.py b/ops/scripts.py new file mode 100644 index 0000000..3829c9f --- /dev/null +++ b/ops/scripts.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +import pymongo + + +def get_activity_ids(): + # get data from mongodb + # mongodb://10.10.5.6:27017/garfield-production/system_dics + # {type: 'share_cfg', deleted: false} + myclient = pymongo.MongoClient("mongodb://10.10.5.6:27017/") + mydb = myclient["garfield-production"] + mycol = mydb["system_dics"] + myquery = {type: 'share_cfg', 'deleted': False} + out_area = {'key': 1, 'value': 1, '_id': 0} + all = [] + for x in mycol.find(myquery, out_area): + temp = {} + a, b = x + temp[a] = b + all.append(temp) + return all