How to use test_long_click method in uiautomator

Best Python code snippet using uiautomator

load_data_cikm.py

Source:load_data_cikm.py Github

copy

Full Screen

1import pandas as pd2import numpy as np3import random4from sklearn.model_selection import train_test_split5from scipy.sparse import csr_matrix6#df1 names=['queryId','sessionId','userId','timeframe','duration','eventdate','searchstring.tokens','categoryId','items','is.test'],7#df2 queryId;timeframe;itemId8######################################9df_click=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/train-clicks.csv',sep=';', engine='python')10df_test_click=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/test-cikm_1.csv',sep=';', engine='python')11click_sum={}12for i in df_click.iterrows():13 if i[1][2] not in click_sum:14 click_sum[i[1][2]]=115 else:16 click_sum[i[1][2]]+=117click_list=[]18for key in click_sum:19 click_list.append((click_sum[key], key))20long_tail = sorted(click_list, reverse=True)21hot=[x[1] for x in long_tail[0:2000]]22long_item=[x[1] for x in long_tail[50000:52000]]23test_long_click={}24test_hot_click={}25hot_i={}26long_i={}27for i in df_test_click.iterrows():28 if i[1][2] in hot:29 if i[1][0] not in test_hot_click:30 test_hot_click[i[1][0]] = [i[1][2]]31 else:32 test_hot_click[i[1][0]].append(i[1][2])33 if i[1][2] in long_item:34 if i[1][0] not in test_long_click:35 test_long_click[i[1][0]] = [i[1][2]]36 else:37 test_long_click[i[1][0]].append(i[1][2])38output = open('test_clicks_cikm_hot.csv', 'w')39for key in test_hot_click:40 output.write(str(key))41 output.write(';')42 for j in test_hot_click[key]:43 output.write(str(j))44 output.write(',')45 output.write('\n')46output.close()47output = open('test_clicks_cikm_long.csv', 'w')48for key in test_long_click:49 output.write(str(key))50 output.write(';')51 for j in test_long_click[key]:52 output.write(str(j))53 output.write(',')54 output.write('\n')55output.close()56######################################57df1 = pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/train-queries.csv',sep=';', engine='python')58df2=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/train_clicks_cikm_1.csv',sep=';',engine='python')59###########################################################60df_test=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/test_clicks_cikm_1.csv',sep=';',engine='python')61df_combine_temp_test=pd.merge(df1,df_test,how='inner',on='queryId')[['queryId','userId','categoryId','items','test_click_items']]62df_clicks_all=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/train_clicks_all.csv',sep=';',engine='python')63df_combine_test=pd.merge(df_combine_temp_test,df2,how='inner',on='queryId')[['queryId','userId','categoryId','items','test_click_items','click_items']]64# filter out rows where Rating < 165df_combine_test = df_combine_test[~(df_combine_test['categoryId']==0)]66df_combine_test=df_combine_test.dropna(axis=0,how='any')67n_qids = df1.queryId.unique()68test_cikm={}69for i in df_combine_test.iterrows():70 test_cikm[i[1][0]]={}71 test_cikm[i[1][0]]['user_id']=int(i[1][1])72 test_cikm[i[1][0]]['cate_id']=i[1][2]73 test=i[1][4].split(',')[0:-1]74 test_cikm[i[1][0]]['test'] = test75 test_cikm[i[1][0]]['neg']=list(set(i[1][3].split(',')[0:-1])-set(i[1][5].split(',')[0:-1]))76# test_clicks={}77# # m=078# for i in df_test.iterrows():79# if i[1][0] not in test_clicks:80# test_clicks[i[1][0]]=[i[1][2]]81# else:82# test_clicks[i[1][0]].append(i[1][2])83#84#85# output = open('test_clicks_cikm_1.csv', 'w')86# for key in test_clicks:87# output.write(str(key))88# output.write(';')89# for j in test_clicks[key]:90# output.write(str(j))91# output.write(',')92# output.write('\n')93# output.close()94###########################################################95# train_data, test_data = train_test_split(df2, test_size=0.2)96# train_data = pd.DataFrame(train_data)97# test_data = pd.DataFrame(test_data)98# train_data[['queryId','timeframe','itemId']].to_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/train-cikm_1.csv',sep=';',index=False)99# test_data[['queryId','timeframe','itemId']].to_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/test-cikm_1.csv',sep=';',index=False)100#101# dfcombine=df.groupby(df['queryId'])102# clicks={}103# # m=0104# for i in df2.iterrows():105# if i[1][0] not in clicks:106# clicks[i[1][0]]=[i[1][2]]107# else:108# clicks[i[1][0]].append(i[1][2])109#110#111# output = open('train_clicks_all.csv', 'w')112# for key in clicks:113# output.write(str(key))114# output.write(';')115# for j in clicks[key]:116# output.write(str(j))117# output.write(',')118# output.write('\n')119# output.close()120df_combine_temp=pd.merge(df1,df2,how='inner',on='queryId')[['queryId','userId','categoryId','items','click_items']]121df_clicks_all=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/train_clicks_all.csv',sep=';',engine='python')122df_combine=pd.merge(df_combine_temp,df_clicks_all,how='inner',on='queryId')[['queryId','userId','categoryId','items','click_items','click_items_all']]123# filter out rows where Rating < 1124df_combine = df_combine[~(df_combine['categoryId']==0)]125df_combine=df_combine.dropna(axis=0,how='any')126# print(df_combine)127# n_users = df_combine.userId.unique().shape[0]128# print(n_users)129cate_item={}130all_items=[]131df3=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/product-categories.csv',sep=';',engine='python')132for i in df3.iterrows():133 all_items.append(i[1][0])134 if i[1][1] not in cate_item:135 cate_item[i[1][1]]=[i[1][0]]136 else:137 cate_item[i[1][1]].append(i[1][0])138for k in cate_item:139 if len(cate_item[k])<10:140 cate_item[k]+=random.sample(all_items,10)141#142#143# output = open('train_cate_item.csv', 'w')144# for key in cate_item:145# output.write(str(key))146# output.write(';')147# for j in cate_item[key]:148# output.write(str(j))149# output.write(',')150# output.write('\n')151# output.close()152df4=pd.read_csv('/ext/czh-190/DeepRec-master/data/dataset-train-diginetica/train_cate_item.csv',sep=';',engine='python')153df_combine_1=pd.merge(df_combine,df4,how='left',on='categoryId')154print(df_combine_1)155m=0156n=0157# output = open('train_cikm_1.csv', 'w')158# output.write('queryId;userId;categoryId;source;label;target')159# output.write('\n')160# for i in df_combine_1.iterrows():161# n+=1162# output.write(str(i[1][0]))163# output.write(';')164# output.write(str(int(i[1][1])))165# output.write(';')166# output.write(str(i[1][2]))167# output.write(';')168# train=i[1][4].split(',')[0:-1]169#170# if len(train)>=10:171# m+=1172# print('filter'+str(len(train)))173# continue174# label=list(np.ones((len(train),)))175# label+=list(np.zeros(10-len(train)))176# neg=[]177# temp=list(set(i[1][3].split(',')[0:-1]) - set(i[1][4].split(',')[0:-1]))178# # print(len(temp))179# if len(temp)<10-len(train):180# neg+=random.sample(cate_item[i[1][2]],10-len(train)-len(temp))181# neg+=list(temp)182# else:183# # print("=====")184# # print(len(temp))185# # print(len(train))186# neg+=random.sample(temp, 10-len(train))187# train+=neg188# if len(train)!=10:189# print("error")190# print(i[1][0])191# break192# for j in train:193# output.write(str(j))194# output.write(',')195# output.write(';')196# for j in label:197# output.write(str(int(j)))198# output.write(',')199# output.write(';')200# target=random.sample(cate_item[i[1][2]],10)201# for j in target:202# output.write(str(j))203# output.write(',')204#205#206# output.write('\n')207# output.close()208n_qids = df_combine_1.queryId.unique()209train_cikm={}210for i in df_combine_1.iterrows():211 n+=1212 train_cikm[i[1][0]]={}213 train_cikm[i[1][0]]['user_id']=int(i[1][1])214 train_cikm[i[1][0]]['cate_id']=i[1][2]215 train=i[1][4].split(',')[0:-1]216 pos=i[1][5].split(',')[0:-1]217 if len(train)>=10:218 m+=1219 print('filter'+str(len(pos)))220 continue221 label=list(np.ones((len(train),)))222 label+=list(np.zeros(10-len(train)))223 train_cikm[i[1][0]]['label']=label224 neg=[]225 temp=list(set(i[1][3].split(',')[0:-1]) - set(i[1][5].split(',')[0:-1]))226 # print(len(temp))227 if len(temp)<10-len(train):228 neg+=random.sample(list(set(cate_item[i[1][2]])-set(i[1][3].split(',')[0:-1])),10-len(train)-len(temp))229 neg+=list(temp)230 else:231 # print("=====")232 # print(len(temp))233 # print(len(train))234 neg+=random.sample(temp, 10-len(train))235 train+=neg236 if len(train)!=10:237 print("error")238 print(i[1][0])239 break240 train_cikm[i[1][0]]['source']=train241 target=random.sample(cate_item[i[1][2]],10)242 train_cikm[i[1][0]]['target']=target243print('success')244print(m)245print(n)246# df = pd.read_csv(path, sep=sep, names=header, engine='python')247#248# n_users = 6040249# n_items = 3952250# train_row_all = []251# train_col_all = []252# train_rating_all = []253# ######################################################254# for line in df.itertuples():255# u = line[1] - 1256# # i_list=line[2].split('|')[0]257# i = int(line[2].split('|')[0]) - 1258# train_row_all.append(u)259# train_col_all.append(i)260# # print(max(train_row))261# # print(max(train_col))262# train_rating_all.append(1)263# train_matrix = csr_matrix((train_rating_all, (train_row_all, train_col_all)), shape=(n_users, n_items))264# train = train_matrix.A265# sum_m = np.sum(train, axis=0)266# cold = np.where(sum_m == 0)267# s = []268# for i, k in enumerate(sum_m):269# s.append((k, i))270# long_tail = sorted(s, reverse=True)271# hot = [x[1] for x in long_tail[0:200]]272# long_item = [x[1] for x in long_tail[200:400]]273# # hot=[x[1] for x in long_tail[0:500]]274# # long_item=[x[1] for x in long_tail[500:1000]]275# ######################################################276# train_data, test_data = train_test_split(df, test_size=test_size)277# train_data = pd.DataFrame(train_data)278# test_data = pd.DataFrame(test_data)279#280# train_row = []281# train_col = []282# train_rating = []283#284# for line in train_data.itertuples():285# u = line[1] - 1286# # i_list=line[2].split('|')[0]287# i = int(line[2].split('|')[0]) - 1288# train_row.append(u)289# train_col.append(i)290# train_rating.append(1)291# train_matrix = csr_matrix((train_rating, (train_row, train_col)), shape=(n_users, n_items))292#293# # all_items = set(np.arange(n_items))294# # neg_items = {}295# # for u in range(n_users):296# # neg_items[u] = list(all_items - set(train_matrix.getrow(u).nonzero()[1]))297#298# test_row = []299# test_col = []300# test_rating = []301# for line in test_data.itertuples():302# test_row.append(line[1] - 1)303# test_col.append(int(line[2].split('|')[0]) - 1)304# test_rating.append(1)305# test_matrix = csr_matrix((test_rating, (test_row, test_col)), shape=(n_users, n_items))306#307# test_dict = {}308# for u in range(n_users):309# test_dict[u] = test_matrix.getrow(u).nonzero()[1]310# ############################################################################################311# test_row_hot = []312# test_col_hot = []313# test_rating_hot = []314# for line in test_data.itertuples():315# if (int(line[2].split('|')[0]) - 1) in hot:316# test_row_hot.append(line[1] - 1)317# test_col_hot.append(int(line[2].split('|')[0]) - 1)318# test_rating_hot.append(1)319# test_matrix_hot = csr_matrix((test_rating_hot, (test_row_hot, test_col_hot)), shape=(n_users, n_items))320#321# test_dict_hot = {}322# for u in range(n_users):323# test_dict_hot[u] = test_matrix_hot.getrow(u).nonzero()[1]324# ############################################################################################325#326# ############################################################################################327# test_row_long = []328# test_col_long = []329# test_rating_long = []330# for line in test_data.itertuples():331# if (int(line[2].split('|')[0]) - 1) in long_item:332# test_row_long.append(line[1] - 1)333# test_col_long.append(int(line[2].split('|')[0]) - 1)334# test_rating_long.append(1)335# test_matrix_long = csr_matrix((test_rating_long, (test_row_long, test_col_long)), shape=(n_users, n_items))336#337# test_dict_long = {}338# for u in range(n_users):339# test_dict_long[u] = test_matrix_long.getrow(u).nonzero()[1]340# ############################################################################################341#342# print("Load data finished. Number of users:", n_users, "Number of items:", n_items)343# return train_matrix.todok(), test_dict, n_users, n_items, test_dict_hot, test_dict_long, hot, long_item344#345#346#...

Full Screen

Full Screen

share2.py

Source:share2.py Github

copy

Full Screen

...86 self.get_screenshot("click_fail")87 sleep(2)88 self.get_screenshot("click")89 #长按90 def test_long_click(self):91 try:92 a = self.driver.find_element_by_id("com.netease.cloudmusic:id/anm")93 b = a.find_element_by_class_name("android.widget.LinearLayout")94 c = b.find_elements_by_class_name("android.widget.FrameLayout")95 d = c[1].find_element_by_class_name("android.widget.TextView")96 actions = TouchAction(self.driver)97 actions.long_press(d)98 actions.perform()99 except:100 self.get_screenshot("long_click_fail")101 sleep(2)102 self.get_screenshot("long_click")103 #back键104 def test_back_key(self):...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run uiautomator automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful