Best Python code snippet using uiautomator
mapper.py
Source:mapper.py
1# coding=utf82import sys3if len(sys.argv) > 1:4 module = sys.argv[1]5 sys.path.append(module)6import time7import log_parser8import datetime9import worker10import utils11import filter12import random13import reducer14import os15WORKER = None16KEYS = []17KVS = {}18WHITE_LIST = {}19MAP_DIC = {0: '22', 1: '23', 2: '24', 3: '25', 4: '26', 5: '27', 6: '273', 7: '274', 8: '275', 9: '276', 10: '277', 11: '160', 12: '161', 13: '162', 14: '163', 15: '164', 16: '165', 17: '166', 18: '167', 19: '168', 20: '169', 21: '214', 22: '215', 23: '1000', 24: '1001', 25: '100', 26: '1003', 27: '1004', 28: '1005', 29: '1006', 30: '1007', 31: '1008', 32: '1009', 33: '108', 34: '109', 35: '281', 36: '282', 37: '283', 38: '284', 39: '285', 40: '286', 41: '287', 42: '170', 43: '171', 44: '172', 45: '173', 46: '174', 47: '175', 48: '176', 49: '1', 50: '178', 51: '179', 52: '224', 53: '225', 54: '1010', 55: '1011', 56: '1012', 57: '1013', 58: '1014', 59: '1015', 60: '1016', 61: '1017', 62: '1018', 63: '1019', 64: '118', 65: '119', 66: '291', 67: '292', 68: '293', 69: '294', 70: '295', 71: '296', 72: '297', 73: '180', 74: '181', 75: '182', 76: '183', 77: '184', 78: '185', 79: '186', 80: '187', 81: '188', 82: '189', 83: '234', 84: '235', 85: '1020', 86: '1021', 87: '1022', 88: '1023', 89: '122', 90: '123', 91: '124', 92: '125', 93: '126', 94: '127', 95: '128', 96: '129', 97: '463', 98: '464', 99: '465', 100: '466', 101: '467', 102: '350', 103: '351', 104: '190', 105: '191', 106: '192', 107: '193', 108: '194', 109: '195', 110: '196', 111: '197', 112: '198', 113: '199', 114: '244', 115: '245', 116: '246', 117: '247', 118: '130', 119: '131', 120: '132', 121: '133', 122: '134', 123: '135', 124: '136', 125: '137', 126: '138', 127: '139', 128: '473', 129: '474', 130: '475', 131: '476', 132: '477', 133: '360', 134: '361', 135: '362', 136: '363', 137: '364', 138: '365', 139: '366', 140: '367', 141: '250', 142: '251', 143: '252', 144: '253', 145: '254', 146: '255', 147: '256', 148: '257', 149: '140', 150: '141', 151: '142', 152: '143', 153: '144', 154: '145', 155: '146', 156: '147', 157: '148', 158: '149', 159: '483', 160: '484', 161: '485', 162: '486', 163: '487', 164: '370', 165: '371', 166: '372', 167: '10', 168: '11', 169: '12', 170: '13', 171: '14', 172: '15', 173: '16', 174: '17', 175: '18', 176: '19', 177: '265', 178: '266', 179: '267', 180: '150', 181: '151', 182: '152', 183: '153', 184: '154', 185: '155', 186: '156', 187: '157', 188: '158', 189: '159', 190: '204', 191: '205', 192: '206', 193: '207', 194: '208', 195: '209', 196: '381', 197: '382', 198: '20', 199: '21'}20SID_DIC = {}21SID_HAS_DIC = {}22def init():23 global WORKER24 global KEYS25 global KVS26 global WHITE_LIST27 global SID_DIC28 global SID_HAS_DIC29 path_pre = ''30 if len(sys.argv) >= 2:31 path_pre += module + '/' 32 if filter.CON_LIST:33 if os.path.exists(path_pre + filter.CON_LIST):34 f = open(path_pre + filter.CON_LIST, 'r+')35 elif os.path.exists(filter.CON_LIST):36 f = open(filter.CON_LIST, 'r+')37 while True:38 l = f.readline()39 if not l:40 break41 if '\t' not in l:42 WHITE_LIST[l.strip().lower()] = 143 else:44 key,value = l.split('\t')45 WHITE_LIST[key.strip().lower()] = int(value.strip())46 f.close()47 KEYS.extend([48 'sid', 'cookie_qid', 'ip', 'pv', 'satisfaction',49 'date', 'time', 'page_stay_time', 'has_page_stay',50 'f', 'tn', 'page_turn', 'query_change',51 'query', 'query_len', 'query_last', 'query_next', 'query_rs', 'rs',52 'first_click_time', 'first_click_type', 'first_click_satisfaction', 'first_click_pos', 'has_first_click',53 'last_click_type', 'last_click_pos', 'last_click_satisfaction',54 'total_click', 'click_pv', 'long_click', 'short_click', 'satisfaction_click',55 'pos1_click', 'pos1_long_click', 'pos1_short_click', 'pos1_satisfaction_click',56 'pos2_click', 'pos2_long_click', 'pos2_short_click', 'pos2_satisfaction_click',57 'pos3_click', 'pos3_long_click', 'pos3_short_click', 'pos3_satisfaction_click',58 'pos4_click', 'pos4_long_click', 'pos4_short_click', 'pos4_satisfaction_click',59 'pos5_click', 'pos5_long_click', 'pos5_short_click', 'pos5_satisfaction_click',60 'pos6_click', 'pos6_long_click', 'pos6_short_click', 'pos6_satisfaction_click',61 'pos7_click', 'pos7_long_click', 'pos7_short_click', 'pos7_satisfaction_click',62 'pos8_click', 'pos8_long_click', 'pos8_short_click', 'pos8_satisfaction_click',63 'pos9_click', 'pos9_long_click', 'pos9_short_click', 'pos9_satisfaction_click',64 'pos10_click', 'pos10_long_click', 'pos10_short_click', 'pos10_satisfaction_click',65 'pos11_click', 'pos11_long_click', 'pos11_short_click', 'pos11_satisfaction_click',66 'pos12_click', 'pos12_long_click', 'pos12_short_click', 'pos12_satisfaction_click',67 'pos13_click', 'pos13_long_click', 'pos13_short_click', 'pos13_satisfaction_click',68 'pos14_click', 'pos14_long_click', 'pos14_short_click', 'pos14_satisfaction_click',69 'pos15_click', 'pos15_long_click', 'pos15_short_click', 'pos15_satisfaction_click',70 'pos16_click', 'pos16_long_click', 'pos16_short_click', 'pos16_satisfaction_click',71 'pos17_click', 'pos17_long_click', 'pos17_short_click', 'pos17_satisfaction_click',72 'pos18_click', 'pos18_long_click', 'pos18_short_click', 'pos18_satisfaction_click',73 'pos19_click', 'pos19_long_click', 'pos19_short_click', 'pos19_satisfaction_click',74 'pos20_click', 'pos20_long_click', 'pos20_short_click', 'pos20_satisfaction_click',75 'as_click', 'al_click', 'alop_click', 'alxr_click', 'pp_click', 'ppim_click',76 'im_click', 'lm_click', 'pl_click', 'plr_click', 'behz_click',77 'tab_click', 'tab_music', 'tab_news', 'tab_zhidao', 'tab_pic',78 'tab_video', 'tab_map', 'tab_wenku', 'tab_more', 'tab_tieba','long_long_click' ])79 KVS.update({80 'sid': '-', 'cookie_qid': '-', 'ip': '-', 'pv': 1, 'satisfaction': 0,81 'date': '-', 'time': '-', 'page_stay_time': 0, 'has_page_stay': 0,82 'f': 'enum', 'tn': '-', 'page_turn': 0, 'query_change': 0,83 'query': '-', 'query_len': 0, 'query_last': '-', 'query_next': '-', 'query_rs': '-', 'rs': 0,84 'first_click_time': 0, 'first_click_type': 'enum', 'first_click_satisfaction': 0, 'first_click_pos': 'enum',85 'has_first_click': 0, 'last_click_type': 'enum', 'last_click_satisfaction': 0, 'last_click_pos': 'enum',86 'total_click': 0, 'click_pv': 0, 'long_click': 0, 'short_click': 0, 'satisfaction_click': 0,87 'pos1_click': 0, 'pos1_long_click': 0, 'pos1_short_click': 0, 'pos1_satisfaction_click': 0,88 'pos2_click': 0, 'pos2_long_click': 0, 'pos2_short_click': 0, 'pos2_satisfaction_click': 0,89 'pos3_click': 0, 'pos3_long_click': 0, 'pos3_short_click': 0, 'pos3_satisfaction_click': 0,90 'pos4_click': 0, 'pos4_long_click': 0, 'pos4_short_click': 0, 'pos4_satisfaction_click': 0,91 'pos5_click': 0, 'pos5_long_click': 0, 'pos5_short_click': 0, 'pos5_satisfaction_click': 0,92 'pos6_click': 0, 'pos6_long_click': 0, 'pos6_short_click': 0, 'pos6_satisfaction_click': 0,93 'pos7_click': 0, 'pos7_long_click': 0, 'pos7_short_click': 0, 'pos7_satisfaction_click': 0,94 'pos8_click': 0, 'pos8_long_click': 0, 'pos8_short_click': 0, 'pos8_satisfaction_click': 0,95 'pos9_click': 0, 'pos9_long_click': 0, 'pos9_short_click': 0, 'pos9_satisfaction_click': 0,96 'pos10_click': 0, 'pos10_long_click': 0, 'pos10_short_click': 0, 'pos10_satisfaction_click': 0,97 'pos11_click': 0, 'pos11_long_click': 0, 'pos11_short_click': 0, 'pos11_satisfaction_click': 0,98 'pos12_click': 0, 'pos12_long_click': 0, 'pos12_short_click': 0, 'pos12_satisfaction_click': 0,99 'pos13_click': 0, 'pos13_long_click': 0, 'pos13_short_click': 0, 'pos13_satisfaction_click': 0,100 'pos14_click': 0, 'pos14_long_click': 0, 'pos14_short_click': 0, 'pos14_satisfaction_click': 0,101 'pos15_click': 0, 'pos15_long_click': 0, 'pos15_short_click': 0, 'pos15_satisfaction_click': 0,102 'pos16_click': 0, 'pos16_long_click': 0, 'pos16_short_click': 0, 'pos16_satisfaction_click': 0,103 'pos17_click': 0, 'pos17_long_click': 0, 'pos17_short_click': 0, 'pos17_satisfaction_click': 0,104 'pos18_click': 0, 'pos18_long_click': 0, 'pos18_short_click': 0, 'pos18_satisfaction_click': 0,105 'pos19_click': 0, 'pos19_long_click': 0, 'pos19_short_click': 0, 'pos19_satisfaction_click': 0,106 'pos20_click': 0, 'pos20_long_click': 0, 'pos20_short_click': 0, 'pos20_satisfaction_click': 0,107 'as_click': 0, 'al_click': 0, 'alop_click': 0, 'alxr_click': 0, 'pp_click': 0, 'ppim_click': 0,108 'im_click': 0, 'lm_click': 0, 'pl_click': 0, 'plr_click': 0, 'behz_click': 0,109 'tab_click': 0, 'tab_music': 0, 'tab_news': 0, 'tab_zhidao': 0, 'tab_pic': 0,110 'tab_video': 0, 'tab_map': 0, 'tab_wenku': 0, 'tab_more': 0, 'tab_tieba': 0,'long_long_click':0,111 })112 for _srcid in filter.SRCID_LIST:113 KEYS.append('src_' + str(_srcid) + '_disp')114 KEYS.append('src_' + str(_srcid) + '_pos')115 KEYS.append('src_' + str(_srcid) + '_pos_na')116 KEYS.append('src_' + str(_srcid) + '_click')117 KEYS.append('src_' + str(_srcid) + '_long_click')118 KEYS.append('src_' + str(_srcid) + '_short_click')119 KEYS.append('src_' + str(_srcid) + '_satisfaction_click')120 KEYS.append('src_' + str(_srcid) + '_behz_click')121 KEYS.append('src_' + str(_srcid) + '_stay')122 KVS.update({'src_' + str(_srcid) + '_disp': 0})123 KVS.update({'src_' + str(_srcid) + '_pos': 'enum'})124 KVS.update({'src_' + str(_srcid) + '_pos_na': 'enum'})125 KVS.update({'src_' + str(_srcid) + '_click': 0})126 KVS.update({'src_' + str(_srcid) + '_long_click': 0})127 KVS.update({'src_' + str(_srcid) + '_short_click': 0})128 KVS.update({'src_' + str(_srcid) + '_satisfaction_click': 0})129 KVS.update({'src_' + str(_srcid) + '_behz_click': 0})130 KVS.update({'src_' + str(_srcid) + '_stay': 0})131 # USER DEFINE132 WORKER = getattr(worker, filter.WORKER)()133 KEYS.extend(WORKER.getColumns())134 KVS.update(WORKER.getDefaults())135 return {'KEYS': KEYS, 'KVS': KVS}136def process(ml):137 if not filter.filter('cookie', ml, WHITE_LIST):138 return True139 cookie = ml.attr('cookie')140 goals = ml.attr('goals')141 all_searches = []142 for _goal in goals:143 all_searches.extend(_goal.attr('searches'))144 all_idx = -1145 for _goal in goals:146 searches = _goal.attr('searches')147 len_searches = len(searches)148 for (_idx, _search) in enumerate(searches):149 all_idx += 1150 if not filter.filter('search', _search, WHITE_LIST):151 #if not filter.filter('search', _search, all_searches):152 continue153 kvs = KVS.copy()154 actions = _search.attr('actions_info')155 real_actions = []156 for _action in actions:157 if _action.attr('fm') not in ['se', 'inlo']:158 real_actions.append(_action)159 date_time_s = _search.attr('date_time')160 date_time_c = actions[0].attr('date_time')161 if date_time_s:162 date_time = date_time_s163 elif date_time_c:164 date_time = date_time_c165 else:166 continue167 c = datetime.datetime.strptime(date_time, '%d/%b/%Y:%H:%M:%S')168 kvs['date'] = c.strftime('%Y-%m-%d')169 kvs['time'] = c.strftime('%H:%M:%S')170 # 计ç®é¦ç¹ãå°¾ç¹ç¸å
³ä¿¡æ¯171 if real_actions:172 session_start_time = utils.gettime(date_time_c)173 first_action = real_actions[0]174 first_click_time = utils.gettime(first_action.attr('date_time')) - session_start_time175 if 0 < first_click_time < 120:176 kvs['first_click_time'] = first_click_time177 kvs['has_first_click'] = 1178 else:179 kvs['first_click_time'] = 0180 fm = first_action.attr('fm')181 kvs['first_click_type'] = fm182 if fm in ['as', 'beha', 'behz'] or (fm.startswith('al') and fm != 'alxr'):183 kvs['first_click_pos'] = first_action.attr('click_pos')184 if first_action.attr('is_satisfied_click') == 1:185 kvs['first_click_satisfaction'] = 1186 last_action = real_actions[-1]187 page_stay_time = utils.gettime(last_action.attr('date_time')) - session_start_time188 if page_stay_time > 0:189 kvs['page_stay_time'] = page_stay_time190 kvs['has_page_stay'] = 1191 fm = last_action.attr('fm')192 kvs['last_click_type'] = fm193 if fm in ['as', 'beha', 'behz'] or (fm.startswith('al') and fm != 'alxr'):194 kvs['last_click_pos'] = last_action.attr('click_pos')195 if last_action.attr('is_satisfied_click') == 1:196 kvs['last_click_satisfaction'] = 1197 query_info = _search.attr('query_info')198 query = query_info.attr('query')199 # 计ç®éç¨ä¿¡æ¯200 kvs['query'] = query201 kvs['query_len'] = len(query.decode('gb18030'))202 kvs['f'] = query_info.attr('f')203 kvs['ip'] = _search.attr('ip')204 kvs['cookie_qid'] = cookie + '_' + _search.attr('qid')205 kvs['tn'] = _search.attr('tn')206 kvs['satisfaction'] = _search.attr('satisfaction')207 # 计ç®åä¸ä¸ªqueryååä¸ä¸ªquery208 if _idx > 0:209 kvs['query_last'] = searches[_idx - 1].attr('query_info.query')210 if _idx + 1 < len_searches:211 kvs['query_next'] = searches[_idx + 1].attr('query_info.query')212 # 计ç®ç¿»é¡µãæ¢queryãrs213 _all_idx = all_idx + 1214 # æ¢queryã翻页æ¯åä¸ä¸ªgoal215 for _se in searches[(_idx + 1):]:216 _all_idx += 1217 page_no = _se.attr('page_no')218 if page_no == 1:219 query_info = _se.attr('query_info')220 new_query = query_info.attr('query')221 f = query_info.attr('f')222 if f in ['3', '8']:223 if kvs['query_len'] <= 7:224 if new_query != query and query in new_query:225 kvs['query_change'] = 1226 else:227 if new_query != query:228 kvs['query_change'] = 1229 elif f == '1':230 kvs['rs'] = 1231 kvs['query_rs'] = new_query232 break233 kvs['page_turn'] += 1234 else:235 # rsæ¯è·¨goalç236 for _se in all_searches[_all_idx:]:237 page_no = _se.attr('page_no')238 if page_no == 1:239 f = _se.attr('query_info.f')240 if f == '1':241 kvs['rs'] = 1242 kvs['query_rs'] = _se.attr('query_info.query')243 break244 tp_dict = utils.splitTp(actions[0].attr('tp'))245 sids = tp_dict.get('rsv_sid','').split('_')246 for _s in filter.SID_LIST:247 if str(_s) in sids:248 kvs['sid'] = _s249 break250 len_real_actions = len(real_actions)251 src_act = {} # ç¹å®å¡ççç¹å»252 # 计ç®ç¹å»ç¸å
³ä¿¡æ¯253 action_info_list = []254 for (_nex_act, _action) in enumerate(real_actions, 1):255 fm = _action.attr('fm')256 if fm == 'tab': # åç¬ç»è®¡tabç¹å»257 kvs['tab_click'] += 1258 tab = _action.attr('tab')259 if tab in ['music', 'news', 'zhidao', 'pic', 'video', 'map', 'wenku', 'more', 'tieba']:260 kvs['tab_' + tab] += 1261 else:262 kvs['total_click'] += 1 # å
æ¬äº¤äº263 is_satisfied_click = _action.attr('is_satisfied_click')264 if is_satisfied_click == 1:265 kvs['satisfaction_click'] += 1 # 满æç¹å»266 t1 = utils.gettime(_action.attr('date_time'))267 _l = ''268 if fm not in ['beha', 'behz']: # é¿ç¹å»ä¸å
æ¬äº¤äº269 if _nex_act != len_real_actions:270 t2 = utils.gettime(real_actions[_nex_act].attr('date_time'))271 dura = t2 - t1 # å½åç¹å»çæ¶é´ä¸åä¸ä¸ªç¨æ·ç¹å»çæ¶é´å·®å¼272 real_dura_time = t2 - t1273 else: # å¦æ为æåä¸æ¬¡ç¹å»274 si = _idx + 1275 dura = 0276 real_dura_time = 0277 if si < len_searches: # goalçéæåä¸ä¸ªsearch278 t2 = searches[si].attr('date_time')279 if t2:280 dura = utils.gettime(t2) - t1281 real_dura_time = utils.gettime(t2) - t1282 elif is_satisfied_click == 1:283 dura = 40284 real_dura_time = 120285 if dura >= 40:286 _l = 'long_click'287 elif dura < 5:288 _l = 'short_click'289 else:290 _l = ''291 if real_dura_time >= 120:292 kvs['long_long_click'] += 1293 click_pos = _action.attr('click_pos')294 action_tuple = (fm, click_pos, _l)295 action_info_list.append(action_tuple)296 if _l:297 kvs[_l] += 1 # é¿ç¹å»/çç¹å»298 if filter.SRCID_LIST: # ç»è®¡å¡çç¸å
³çç¹å»ä¿¡æ¯299 tp = _action.attr('tp')300 tp_dict = utils.splitTp(tp)301 srcid = tp_dict.get('rsv_srcid', '0')302 if int(srcid) in filter.SRCID_LIST:303 kvs['src_' + srcid + '_click'] += 1 # å¡ççç¹å»304 if fm in ['beha', 'behz']:305 kvs['src_' + srcid + '_behz_click'] += 1 # å¡çç交äºç¹å»306 if _l:307 kvs['src_' + srcid + '_' + _l] += 1 # å¡ççé¿ç¹å»/çç¹å»308 if is_satisfied_click == 1:309 kvs['src_' + srcid + '_satisfaction_click'] += 1 # å¡çç满æç¹å»310 if srcid not in src_act:311 src_act[srcid] = []312 src_act[srcid].append(_action) # è®°å½ä¸å¡ççç¹å»313 if fm in ['pp', 'ppim', 'im', 'lm', 'pl', \314 'plr', 'alxr', 'alop', 'as']:315 _k = fm316 elif fm in ['behz', 'beha']:317 _k = 'behz'318 elif fm.startswith('al'):319 _k = 'al'320 else:321 continue322 kvs[_k + '_click'] += 1 # ä¸åç±»åçç¹å»323 # åä½ç½®ç¹å»324 if _k in ['alop', 'as', 'al', 'behz']:325 click_pos = _action.attr('click_pos')326 tp = _action.attr('tp')327 tp_dict = utils.splitTp(tp)328 rsv_tpl = tp_dict.get('rsv_tpl', '-')329 if _k == 'behz' and rsv_tpl.startswith('right_'):330 continue331 if 0 < click_pos < 21:332 kvs['pos' + str(click_pos) + '_click'] += 1333 if _l:334 kvs['pos' + str(click_pos) + '_' + _l] += 1335 if is_satisfied_click == 1:336 kvs['pos' + str(click_pos) + '_satisfaction_click'] += 1337 if filter.SRCID_LIST:338 urls = _search.attr('urls_info')339 for _url in urls: # å¡ççå±ç°ä¿¡æ¯340 srcid = utils.getSrcidFromDisplay(_url)341 if srcid and int(srcid) in filter.SRCID_LIST:342 kvs['src_' + str(srcid) + '_disp'] = 1343 dis_pos = _url.attr('display_pos')344 if dis_pos > 0:345 kvs['src_' + str(srcid) + '_pos'] = dis_pos346 na_pos = _url.attr('natural_pos')347 if na_pos > 0:348 kvs['src_' + str(srcid) + '_pos_na'] = na_pos349 for _src in src_act: # å¡ççåçæ¶é´350 if src_act[_src][-1].attr('satisfaction_click') == 1:351 _d = 200352 elif src_act[_src] == real_actions[-1] and \353 src_act[_src][-1].attr('fm') == 'alop':354 _d = 20355 else:356 f = utils.gettime(src_act[_src][0].attr('date_time'))357 l = utils.gettime(src_act[_src][-1].attr('date_time'))358 _d = l - f359 if _d > 200:360 _d = 200361 kvs['src_' + _src + '_stay'] = _d362 if kvs['total_click'] > 0:363 kvs['click_pv'] = 1364 kvs.update(WORKER.getValues(_search, WHITE_LIST,kvs,action_info_list))365 # è¾åºPV级å«æ°æ® 366 print (MAP_DIC[random.randint(50, 99)] + '\t' + '\t'.join([str(kvs[x]) for x in KEYS])).decode('gb18030').encode('utf8')367 # è¾åºquery级å«æ°æ®368 print (MAP_DIC[hash(kvs['query']) % 48 + 2] + '\t' + kvs['query'] + '\t' + '\t'.join([str(kvs[x]) for x in KEYS])).decode('gb18030').encode('utf8')369 370 # è¿éæ¯å¹²ä»ä¹ï¼371 tmp_date = kvs['date']372 if filter.URL_FLAG == True:373 for i in range(0, 10):374 if WHITE_LIST.get(_search.attr('urls_list')[i].attr('url')):375 tmp_sid = str(kvs['sid']) + '@' + WHITE_LIST[_search.attr('urls_list')[i].attr('url')]376 else:377 tmp_sid = str(kvs['sid'])378 else:379 tmp_sid = str(kvs['sid'])380 381 # æ建SID_DICåSID_HAS_DIC382 if not SID_DIC.get(tmp_sid):383 SID_DIC[tmp_sid] = {}384 SID_DIC[tmp_sid][tmp_date] = {}385 else:386 if not SID_DIC[tmp_sid].get(tmp_date):387 SID_DIC[tmp_sid][tmp_date] = {}388 389 if not SID_HAS_DIC.get(tmp_sid):390 SID_HAS_DIC[tmp_sid] = {}391 SID_HAS_DIC[tmp_sid][tmp_date] = {}392 else:393 if not SID_HAS_DIC[tmp_sid].get(tmp_date):394 SID_HAS_DIC[tmp_sid][tmp_date] = {}395 396 397 for idx, name in enumerate(KEYS):398 if not KVS[name] == '-':399 if KVS[name] == 'enum':400 if not SID_DIC[tmp_sid][tmp_date].get(name):401 SID_DIC[tmp_sid][tmp_date][name] = {}402 if SID_DIC[tmp_sid][tmp_date][name].get(kvs[name]):403 SID_DIC[tmp_sid][tmp_date][name][kvs[name]] += 1404 else:405 SID_DIC[tmp_sid][tmp_date][name][kvs[name]] = 1406 else:407 if SID_DIC[tmp_sid][tmp_date].get(name):408 SID_DIC[tmp_sid][tmp_date][name] += kvs[name]409 else:410 SID_DIC[tmp_sid][tmp_date][name] = kvs[name]411 if SID_HAS_DIC[tmp_sid][tmp_date].get(name):412 if kvs[name] > 0:413 SID_HAS_DIC[tmp_sid][tmp_date][name] += 1414 else:415 if kvs[name] > 0:416 SID_HAS_DIC[tmp_sid][tmp_date][name] = 1417 else:418 SID_HAS_DIC[tmp_sid][tmp_date][name] = 0419def dic_has_attr(_dic, keys, kvs):420 tmp_list = []421 for k in keys:422 if kvs[k] == 'enum' or kvs[k] == '-':423 tmp_list.append('null')424 else:425 tmp_list.append(str(_dic[k]))426 return tmp_list427def dic_attr(_dic, keys, kvs):428 tmp_list = []429 for k in keys:430 if kvs[k] == 'enum':431 tmp_str = ''432 for v in _dic[k]:433 tmp_str = tmp_str + str(v) + ':' + str(_dic[k][v]) + '_'434 tmp_list.append(tmp_str[:-1])435 elif kvs[k] == '-':436 tmp_list.append('null')437 else:438 tmp_list.append(str(_dic[k]))439 return tmp_list440if __name__ == '__main__':441 init()442 ml = log_parser.MergeLog_Protobuf()443 while True:444 try:445 flag = ml.readNext()446 except Exception, e:447 continue448 if flag <= 0:449 break450 process(ml)451 for tmp_sid in SID_DIC:452 for tmp_date in SID_DIC[tmp_sid]:453 print (MAP_DIC[0] + '\t' + str(tmp_sid) + '\t' + str(tmp_date) + '\tadddic\t' + '\t'.join(dic_attr(SID_DIC[tmp_sid][tmp_date], KEYS, KVS))).decode('gb18030').encode('utf8')454 print (MAP_DIC[0] + '\t' + str(tmp_sid) + '\t' + str(tmp_date) + '\thasdic\t' + '\t'.join(dic_has_attr(SID_HAS_DIC[tmp_sid][tmp_date], KEYS, KVS))).decode('gb18030').encode('utf8')455 print (MAP_DIC[1] + '\t' + str(tmp_sid) + '\t' + str(tmp_date) + '\tadddic\t' + '\t'.join(dic_attr(SID_DIC[tmp_sid][tmp_date], KEYS, KVS))).decode('gb18030').encode('utf8')...
button.py
Source:button.py
...52 elif action == "move":53 if not self.local_rect.collidepoint(xy):54 self.click_count += 155 56 def _long_click(self,click_count):57 if self.click_count==click_count:58 # we have been pressed for 1.0 seconds 59 # without a move outside of our box or a button release60 self.on_long_click()61 def on_click(self):62 """function called whenever button is clicked. Can be overriden in sub-classes"""63 if self.callback:64 self.callback()65 66 def on_long_click(self):67 """function called whenever button is long_clicked. Can be overriden in sub-classes"""68 if self.long_click_callback:69 self.pressed=False70 self.update()71 self.long_click_callback()72 def draw_button(self):73 (w, h) = self.size74 two_images = self.label.startswith("image:") and "|" in self.label75 if self.style.button_inverting:76 if self.pressed and not two_images:77 self.fill(self.style.button_color)78 else:79 self.fill(self.style.bg_color)80 pygame.draw.rect(self.surface, self.style.button_color, [0, 0, w, h], 1)...
push_button.py
Source:push_button.py
...39 self.counter=ticks_ms()40 elif self.button.value()== self.state:41 if ticks_diff(ticks_ms(),self.counter)>self.long_click and self.button_down:42 self.button_down=False43 self._long_click()44 elif ticks_diff(ticks_ms(),self.counter)>self.single_click and self.button_down:45 self.button_down=False46 if ticks_diff(ticks_ms(),self.counter_fst_click)>self.double_click:47 48 self.counter_fst_click=ticks_ms()49 self.sng_click_timer.init(period=self.double_click-self.single_click, mode=Timer.ONE_SHOT, callback=self._single_click)50 else:51 self.sng_click_timer.deinit()52 self._double_click()53 54 self.button_up=True55 self.counter=ticks_ms()56 57 def _single_click(self,p):58 print('Single click')59 if not self.single_click_fnc==None:60 self.single_click_fnc()61 62 def _long_click(self):63 print('long click')64 if not self.long_click_fnc==None:65 self.long_click_fnc()66 67 def _double_click(self):68 print('double click')69 if not self.double_click_fnc==None:70 self.double_click_fnc()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!