How to use n_result method in avocado

Best Python code snippet using avocado_python

test.py

Source:test.py Github

copy

Full Screen

1from ast import Not2import re3total_result=[None,(None,7,10,12,17,23,28,34),(None,20,24,29,31,33,34,35),4 (None,2,7,8,11,14,23,31),(None,12,13,22,23,24,28,29),(None,1,3,4,5,16,21,28),5 (None,5,15,19,23,30,34,35),(None,1,3,5,7,27,29,33),(None,2,21,28,29,30,32,36),6 (None,3,4,15,23,27,30,36),(None,1,2,3,6,24,28,30)]7def up_result() :8 """変数total_result(今までの当選数字)を更新する。本数字のみ9 """10 n=len(total_result)11 print("第 {} 回の結果を入力します。中止は'q'".format(n),"\n")12 result=[None]13 for i in range(1,8):14 m=input("第 {} 数字を入力してください".format(i))15 if m == "q":16 break17 result.append(m)18 if len(result) == 8:19 result=tuple(result)20 total_result.append(result)21up_result()22#更新したtotal_resultをファイルに書き込まなきゃ。23#ifループの中で1~37以外を入力したときはエラーを出す(continue?)24#数字を昇順に並べ替える必要あり25class Anal_column:26 """直近n回の第m数字をいろいろ解析する27 """28 def __init__(self,n,m):29 self.n=n*-130 self.m=m31 32 def appear_column(self):33 """出現頻度を調べる"""34 column=[]35 for i in range(self.n,0):36 column.append(total_result[i])37def appear_column(n,m):38 """直近n回の第m数字の出現頻度を調べる39 先頭数字の評価に使う"""40 n=n*(-1)41 column=[]#直近n回の第m数字のリスト42 for i in range(n,0):43 column.append(total_result[i][m])44 print(column)45 appear=[None,[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],46 [8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],47 [15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],48 [22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],49 [29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],50 [36,0],[37,0]]#1~37に出現回数を割り当てるためのリスト51 for val in column:52 appear[val][1] += 153 appear.pop(0)#Noneが混在してるとsortできない54 #無名関数lambdaの引数xはappearの各要素、戻り値:各要素のindex1でソートする55 appear.sort(key=lambda x: x[1],reverse=True)56 print(appear)57appear_column(10,1)58def appear_all(n):59 """直近n回のすべての位置での出現頻度を調べる"""60 n=n*-161 recent_result=total_result[n:]62 print(recent_result)#直近n回の当選番号のリスト63 appear=[None,[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],64 [8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],65 [15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],66 [22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],67 [29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],68 [36,0],[37,0]]#1~37に出現回数を割り当てるためのリスト69 for val in recent_result:70 for i in range(1,8):71 appear[val[i]][1]+=172 appear.pop(0)73 appear.sort(key=lambda x: x[1],reverse=True)74 print(appear)75appear_all(2)76def int_column(n,m):77 """第n回の第m数字の値とその第m数字の列における出現間隔値を調べる78 先頭数字の評価に使う"""79 n_result=total_result[n][m]80 m_column=[]#第m数字のリスト81 for i in range(1,n+1):82 m_column.append(total_result[i][m])83 m_column.reverse()#新しいほうからへ並び替え84 m_column[0]=None#インデックス0は第n回そのものなのでNONEで埋める85 if n_result in m_column:86 int_n=m_column.index(n_result)#数字がなかった時の処理考える87 else :88 int_n=089 print(n_result)90 print(m_column)91 print(int_n)92int_column(7,2)93def int_all(n,m):94 """第n回の第m数字の値とすべての位置での出現間隔値を調べる"""95 n_result=total_result[n][m]96 sub_total_result=total_result[:n]97 sub_reverse_result=reversed(sub_total_result)#新しいほうからへ並び替え98 sub_reverse_result=list(sub_reverse_result)#イデレータをリスト化99 int_n=0100 for i in range(n-1):101 if n_result in sub_reverse_result[i]:102 int_n=i+1103 break104 print(total_result)105 print(n_result)106 print(sub_reverse_result)107 print(int_n)108int_all(9,1)109def next_number(n,m):110 """第n回の当選番号の第m数字から次回にその第m数字の列に111 出た数字を調べる"""112 n_result=total_result[n][m]113 appear=[None,[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],114 [8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],115 [15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],116 [22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],117 [29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],118 [36,0],[37,0]]#1~37に出現回数を割り当てるためのリスト119 for i in range(1,len(total_result)-1):#len()-1:最新の結果は除く(次回はないため)120 if n_result == total_result[i][m]:121 next=total_result[i+1][m]122 appear[next][1]+=1123 appear.pop(0)124 appear.sort(key=lambda x: x[1],reverse=True)125 print(appear)126next_number(10,2)127def present_one_digit(n):128 """直近n回の下一桁数字(0~9)とその位置(第m数字として)を129 調べる"""130 m=n*-1131 recent_result=total_result[m:]132 print(recent_result)#直近n回の当選番号のリスト133 recent_one_digit=[None]134 for j,val in enumerate(recent_result):135 str_line=[]136 for i in range(1,8):137 str_rize=str(val[i])#文字化138 str_rize=str_rize[-1]#下一桁を取り出す(最後のインデックス)139 str_line.append(str_rize)140 recent_one_digit.append(str_line)141 recent_one_digit[j+1].insert(0,None)142 print(recent_one_digit)143 checker=["0","1","2","3","4","5","6","7","8","9"]144 one_digit_posi=[None]145 for j in range(1,n+1):146 sub_posi=[["0"],["1"],["2"],["3"],["4"],["5"],["6"],["7"],["8"],["9"]]147 for i,val in enumerate(recent_one_digit[j]):148 for check in checker:149 if check == val:150 sub_posi[checker.index(check)].append(i)151 one_digit_posi.append(sub_posi)#インデックス0は下一桁数字の値、インデックス1以降は位置(第m数字として)152 print(one_digit_posi)153 return one_digit_posi154present_one_digit(2)155def sort_pre_one_digit(s):156 """関数present_one_digitで得られたリスト(引数)をソート、カット157 リストのようなミュータブルオブジェクトの場合、b=a(参照渡し)とやると158 b或いはaの変更が、a或いはbにも反映されてしまう。159 (文字列、タプルのようなイミュータブルは気にしないでOK)160 なので関数を分ける。関数を分けても関数の戻り値(リスト)を変数に代入(参照渡し)して161 使いまわしたらダメ、影響を受ける。影響を受けないためには一々メモリにロードし別オブジェクトにする162 まとめ163 変数に代入(参照渡し):ミュータブルオブジェクト(要素がイミュータブルでも)は変更が元のオブジェクトに反映164 浅いコピー(スライスとかcopyメソッド):要素がミュータブルなら(リストの要素がリストとか)は影響される165 深いコピー(deepcopyメソッド):大丈夫!166 参考:https://snowtree-injune.com/2018/07/17/post-565/とか167 https://note.nkmk.me/python-copy-deepcopy/168 """169 #↑これ大事。total_resultを加工したリストの変数を作りそれを加工するとtotal_resultが変わってしまう!170 #今まで作った関数チェックの事 171 #total_resultは要素がタプルなのでスライスして作ったオブジェクトは大丈夫!172 #one_digit_posiは要素がリストなのでそこから作ったオブジェクトを加工すると173 #元のオブジェクトも影響を受ける。deepcopyか関数を分ける174 s.pop(0)175 for i in range(len(s)):176 s[i].sort(key=lambda x: len(x),reverse=True)177 for i,val in enumerate(s):178 for j,val2 in enumerate(val):179 if len(val2)==2:180 break181 s[i]=s[i][:j]182 print(s)183sort_pre_one_digit(present_one_digit(6))184def next_one_digit(n):185 """第n回の当選番号の下一桁数字が次回にどの下一桁数字が出たかを186 調べる。"""187 n_result=total_result[n:n+2]188 n_result.insert(0,None)189 print(n_result)#第n回の当選番号のリスト190 n_one_digit=[None]191 for j,val in enumerate(n_result):192 if val == None:193 continue194 str_line=[]195 for i in range(1,8):196 str_rize=str(val[i])#文字化197 str_rize=str_rize[-1]#下一桁を取り出す(最後のインデックス)198 str_line.append(str_rize)199 n_one_digit.append(str_line)200 n_one_digit[j].insert(0,None)201 print(n_one_digit)202 next_list=[]203 for j ,val1 in enumerate(n_one_digit[1]):204 if val1 == None:205 continue206 for i ,val2 in enumerate(n_one_digit[2]):207 if val2 == None:208 continue209 if val1 == val2 :210 t=(val1,n_result[1][j],j,n_result[2][i],i)211 #下一桁数字,n回の数字,n回の位置(第m数字),次回(n+1)の数字,次回(n+1)の位置(第m数字)212 next_list.append(t)213 print(next_list)214next_one_digit(2)215#前回の当選番号の数字からよく出ている下一桁数字を調べる関数を作る216#next_one_digitを複数回繰り返し良く出ている数字を調べる⇒あとで買い目を217#だすアルゴリズムを考える時218#present_one_digit&sortもう少し簡単にならないかやってみる。219#できた!上のpresent_one_digitとsort_pre_one_digitをひとつにまとめた!220def present_one_digit2(n):221 """直近n回の下一桁数字(0~9)とその位置(第m数字として)を222 調べる"""223 m=n*-1224 recent_result=total_result[m:]225 recent_result.insert(0,None)226 print(recent_result)#直近n回の当選番号のリスト227 recent_one_digit=[None]228 for j,val in enumerate(recent_result):229 if val == None:230 continue231 str_line=[]232 for i in range(1,8):233 str_rize=str(val[i])#文字化234 str_rize=str_rize[-1]#下一桁を取り出す(最後のインデックス)235 str_line.append(str_rize)236 recent_one_digit.append(str_line)237 recent_one_digit[j].insert(0,None)238 print(recent_one_digit)239 checker=["0","1","2","3","4","5","6","7","8","9"]240 one_digit_posi=[None]241 for j in range(1,n+1):242 sub_posi=[]243 sub_posi2=[]244 for i,val in enumerate(recent_one_digit[j]):245 if val == None:246 continue247 for h in checker:248 if h == val:249 l=[h,recent_result[j][i],i]#下一桁数字,その数字,位置(第m数字として)250 sub_posi.append(l)251 print(sub_posi)252 #ここにsub_posiのインデックス0を評価して出現回数が2未満は消すコードを入れる253 l2=[x[0] for x in sub_posi]254 print(l2)255 l2=[val2 for val2 in l2 if l2.count(val2)>1]256 print(l2)257 l3=[]258 l2=[x for x in l2 if x not in l3 and not l3.append(x)]259 print(l2)260 for m in l2:261 for val3 in sub_posi:262 if val3[0] == m:263 sub_posi2.append(val3)264 one_digit_posi.append(sub_posi2)265 return one_digit_posi266present_one_digit2(3)267def next_conti_number(n):268 """第n回の当選番号の中から次回も継続して出た数字を調べる269 (引っ張り数字)"""270 n_result=total_result[n:n+2]271 n_result.insert(0,None)272 print(n_result)#第n回の当選番号のリスト273 274 next_list=[]275 for j,val1 in enumerate(n_result[1]):276 if val1 == None:277 continue278 for i,val2 in enumerate(n_result[2]):279 if val2 == None:280 continue281 if val1 == val2 :282 t=(str(val1),n_result[1][j],j,n_result[2][i],i)283 #継続数字,n回の数字,n回の位置(第m数字),次回(n+1)の数字,次回(n+1)の位置(第m数字)284 #上でインデックス1、3はいらないがとりあえずnext_one_digitの戻り値と形を合わせておく285 next_list.append(t)286 print(next_list)287next_conti_number(9)288def present_serial_number(n):289 """第n回の連続数字(x,x2)とその位置(第m,m2数字として)を290 調べる"""291 n_result=total_result[n]292 print(n_result)#第n回の当選番号のリスト293 serial_list=[]294 for i in range(1,7):295 if n_result[i] == n_result[i+1]-1:296 val=[n_result[i],n_result[i+1],i,i+1]#x,x2,m,m2297 serial_list.append(val)298 print(serial_list)299present_serial_number(1)300def next_shift_number(n):301 """第n回の当選番号の本数字から次回に+1の数字(r_shift=後数字)、302 -1の数字(l_shift=前数字)を調べる303 (前数字・後数字)"""304 n_result=total_result[n:n+2]305 n_result.insert(0,None)306 print(n_result)#第n回の当選番号のリスト307 r_shift_list=[]308 l_shift_list=[]309 for j,val1 in enumerate(n_result[1]):310 if val1 == None:311 continue312 for i,val2 in enumerate(n_result[2]):313 if val2 == None:314 continue315 if val1+1 == val2 :316 t=(n_result[1][j],j,n_result[2][i],i)317 #n回の数字,n回の位置(第m数字),次回(n+1)の数字,次回(n+1)の位置(第m数字)318 r_shift_list.append(t)319 if val1-1 == val2:320 u=(n_result[1][j],j,n_result[2][i],i)321 l_shift_list.append(u)322 print(r_shift_list)323 print(l_shift_list)...

Full Screen

Full Screen

api.py

Source:api.py Github

copy

Full Screen

1from application.mongo import Connection2from flask import jsonify3class APIManager(object):4 5 @staticmethod6 def index():7 """8 API Manager Index Page9 :return:10 """11 return jsonify(12 status=200,13 detail="Welcome to Social Manager API",14 services=[{"source": "Twitter", "url": "/api/v1/twitter"}]15 ), 20016class TwitterAPI(object):17 18 @staticmethod19 def index():20 """21 Twitter API Index Page22 :return:23 """24 return jsonify(25 status=200,26 detail="Twitter API Index",27 services=[28 {29 "name": "Listener",30 "url": "/api/v1/twitter/search/{KEYWORD-TO-SEARCH}",31 "util": "/api/v1/twitter/keywords"32 },33 {34 "name": "Tweet Discover",35 "url": "/api/v1/twitter/tweets/{USER-TO-DISCOVER}",36 "util": "/api/v1/twitter/users"37 },38 {39 "name": "Friends Discover",40 "url": "/api/v1/twitter/friends/{USER-TO-DISCOVER}",41 "util": "/api/v1/twitter/users"42 },43 {44 "name": "Follower Discover",45 "url": "/api/v1/twitter/followers/{USER-TO-DISCOVER}",46 "util": "/api/v1/twitter/users"47 }48 ]49 ), 20050 51 @staticmethod52 def get_keywords():53 """54 Return the list of all available keywords55 :return: Json56 """57 return jsonify(status=200,58 keywords=Connection.Instance().db.twitter.find({"source": "listener"}).distinct("keywords")), 20059 60 @staticmethod61 def search(keyword, page=1):62 """63 Get all tweets from a given keyword with pagination support.64 :param keyword: Keyword to search65 :param page: Page Number66 :return:67 """68 try:69 page = int(page) if int(page) > 0 else 170 except:71 page = 172 n_result = 1073 total_result = Connection.Instance().db.twitter.find({"keywords": keyword, "source": "listener"}).count()74 result = list(Connection.Instance().db.twitter.find(75 {76 "keywords": keyword,77 "source": "listener"78 },79 {80 "_id": False,81 "created": False,82 "keywords": False,83 "source": False84 }).skip((page-1)*n_result).limit(n_result))85 86 page_size = len(result)87 88 return jsonify(89 total_result=total_result,90 status=200,91 page_size=page_size,92 page=page,93 result=[data['data'] for data in result],94 next="/api/v1/twitter/search/python/%s" % str(page + 1) if page_size == n_result else None,95 before="/api/v1/twitter/search/python/%s" % str(page - 1) if page > 1 else None96 ), 20097 @staticmethod98 def get_users():99 """100 Return list of users fetched101 :return: Json102 """103 return jsonify(status=200,104 users=Connection.Instance().db.twitter.find({"user": {"$ne": None}}).distinct("user")), 200105 @staticmethod106 def get_tweets(user, page=1):107 """108 Return List of tweets from a specific user109 :param user: User Screen Name110 :param page: Page Number111 :return:112 """113 total_result = Connection.Instance().db.twitter.find({"user": user, "source": "collector"}).count()114 try:115 page = int(page) if int(page) > 0 else 1116 except:117 page = 1118 n_result = 10119 result = list(Connection.Instance().db.twitter.find(120 {121 "source": "collector",122 "user": user123 }124 ).skip((page-1)*n_result).limit(n_result))125 126 page_size = len(result)127 return jsonify(128 total_result=total_result,129 status=200,130 page_size=page_size,131 page=page,132 result=[data['data'] for data in result],133 next="/api/v1/twitter/tweets/%s/%s" % (user, str(page + 1)) if page_size == n_result else None,134 before="/api/v1/twitter/tweets/%s/%s" % (user, str(page - 1)) if page > 1 else None135 ), 200136 @staticmethod137 def get_followers(user, page=1):138 """139 Return List of followers of a specific user140 :param user: User Screen Name141 :param page: Page Number142 :return:143 """144 total_result = Connection.Instance().db.twitter.find({"user": user, "source": "follower"}).count()145 try:146 page = int(page) if int(page) > 0 else 1147 except:148 page = 1149 n_result = 10150 result = list(Connection.Instance().db.twitter.find(151 {152 "source": "follower",153 "user": user154 }155 ).skip((page - 1) * n_result).limit(n_result))156 page_size = len(result)157 return jsonify(158 total_result=total_result,159 status=200,160 page_size=page_size,161 page=page,162 result=[data['data'] for data in result],163 next="/api/v1/twitter/followers/%s/%s" % (user, str(page + 1)) if page_size == n_result else None,164 before="/api/v1/twitter/followers/%s/%s" % (user, str(page - 1)) if page > 1 else None165 ), 200166 @staticmethod167 def get_friends(user, page=1):168 """169 Return List of friends of a specific user170 :param user: User Screen Name171 :param page: Page Number172 :return:173 """174 total_result = Connection.Instance().db.twitter.find({"user": user, "source": "friends"}).count()175 try:176 page = int(page) if int(page) > 0 else 1177 except:178 page = 1179 n_result = 10180 result = list(Connection.Instance().db.twitter.find(181 {182 "source": "friends",183 "user": user184 }185 ).skip((page - 1) * n_result).limit(n_result))186 187 page_size = len(result)188 189 return jsonify(190 total_result=total_result,191 status=200,192 page_size=page_size,193 page=page,194 result=[data['data'] for data in result],195 next="/api/v1/twitter/friends/%s/%s" % (user, str(page + 1)) if page_size == n_result else None,196 before="/api/v1/twitter/friends/%s/%s" % (user, str(page - 1)) if page > 1 else None...

Full Screen

Full Screen

find_addends_recu.py

Source:find_addends_recu.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# from .find_addends_utils import tol2side_x_eq_y3# # from find_addends_utils import tol2side_x_eq_y4from dramkit.find_addends.find_addends_utils import tol2side_x_eq_y5def find_addends_recu(tgt_sum, alts, max_idx, choseds=[], results=[],6 tol_below=0.0, tol_above=0.0, n_result=None,7 keep_order=True):8 '''9 | 递归方法,从给定的列表alts中选取若干个数之和最接近tgt_sum10 | 优点: 可在实数范围内求解,没有正负或整数限制;能够返回所有可行解(理论上)11 | 缺点: 受递归深度限制,alts太长就无法求解;没有可行解的情况下不能返回相对最优解?12 Parameters13 ----------14 tgt_sum : float, int15 目标和16 alts : list17 备选数列表18 max_idx : int19 从索引max_idx处开始从后往前搜索,初始值一般设为alts的最大索引20 choseds : list21 预选中的备选数,初始值默认为空22 results : list23 已存在的所有结果,初始值默认为空24 tol_below : float25 下界误差,若目标和减去当前和小于等于tol_below,则为可行解,默认为0.026 tol_above : tol27 上界误差,若当前和减去目标和小于等于bol_above,则为可行解,默认为0.028 n_result : int, None29 返回的可行解个数限制,当results的长度大于n_result时返回results30 keep_order : bool31 是否保结果中备选数的进入顺序与alts中的顺序一致,默认是32 Returns33 -------34 results : list35 所有可能的解列表36 References37 ----------38 https://blog.csdn.net/mandagod/article/details/7958875339 '''40 if n_result is None:41 if max_idx < 0:42 return results43 else:44 if len(results) > n_result-1 or max_idx < 0:45 return results46 result = [] # 保存一个可行解47 # 满足误差界限意味着找到一个可行解48 if tol2side_x_eq_y(alts[max_idx], tgt_sum, tol_below, tol_above):49 result.append(alts[max_idx])50 if keep_order:51 choseds = choseds[::-1] # 对choseds逆序(保证顺序)52 result += choseds53 choseds = choseds[::-1] # 恢复顺序54 else:55 result += choseds56 results.append(result)57 # 选中max_idx之后继续递归58 choseds.append(alts[max_idx])59 results = find_addends_recu(tgt_sum-alts[max_idx], alts, max_idx-1,60 choseds=choseds, results=results,61 tol_below=tol_below, tol_above=tol_above,62 n_result=n_result, keep_order=keep_order)63 # 不选max_idx继续递归64 del choseds[-1]65 results = find_addends_recu(tgt_sum, alts, max_idx-1, choseds=choseds,66 results=results, tol_below=tol_below,67 tol_above=tol_above, n_result=n_result,68 keep_order=keep_order)69 return results70if __name__ == '__main__':71 import time72 start_time = time.time()73 tgt_sum = 22 + 21 + 4.174 alts = [22, 15, 14, 13, 7, 6.1, 5, 21.5, 100]75 # alts = [100, 99, 98, 98.2, 6, 5, 3, -20, -25]76 # tgt_sum = 78.277 # alts = [200, 107, 100, 99, 98, 6, 5, 3, -1, -20, -25]78 # tgt_sum = 100 + 6 - 2579 # alts = [-900, 901, 800, 600, -400, 402]80 # tgt_sum = 181 # alts = [100, -100, -105, -102, -25, -30, -1]82 # tgt_sum = -2683 alts = [10, 9, 8, 7, 6, 5]84 tgt_sum = 1785 # alts = [10, 9, 8, -7, -6, -5]86 # tgt_sum = 387 # alts = [10, 7, 6, 3]88 # tgt_sum = 1889 # alts = [10, 7, 6, 3]90 # tgt_sum = 1291 max_idx = len(alts) - 192 choseds = []93 results = []94 tol_below = 0.000195 tol_above = 0.000196 n_result = None97 keep_order = True98 results = find_addends_recu(tgt_sum, alts, max_idx, choseds=choseds,99 results=results, tol_below=tol_below,100 tol_above=tol_above, n_result=n_result,101 keep_order=keep_order)102 print('可能的序列:')103 for result in results:104 print(result, end='')105 s = sum(result)106 print('\n和:', s, '\n目标和:', tgt_sum, '\n差:', tgt_sum-s, end='\n\n')...

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 avocado 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