How to use add_relation method in autotest

Best Python code snippet using autotest_python

linking_utils.py

Source:linking_utils.py Github

copy

Full Screen

...63 self.merge_types = merge_types64 self.sc_link = sc_link65 self.cv_link = cv_link66 self.relation_ids = {}67 def add_relation(name):68 self.relation_ids[name] = len(self.relation_ids)69 logging.debug('relation: %s --> %d', name, self.relation_ids[name])70 ##< TODO: add_relation('[UNK]')71 def add_rel_dist(name, max_dist):72 for i in range(-max_dist, max_dist + 1):73 add_relation((name, i))74 add_rel_dist('qq_dist', qq_max_dist)75 add_relation('qc_default')76 # if qc_token_match:77 # add_relation('qc_token_match')78 add_relation('qt_default')79 # if qt_token_match:80 # add_relation('qt_token_match')81 add_relation('cq_default')82 # if cq_token_match:83 # add_relation('cq_token_match')84 add_relation('cc_default')85 if cc_foreign_key:86 add_relation('cc_foreign_key_forward')87 add_relation('cc_foreign_key_backward')88 if cc_table_match:89 add_relation('cc_table_match')90 add_rel_dist('cc_dist', cc_max_dist)91 add_relation('ct_default')92 if ct_foreign_key:93 add_relation('ct_foreign_key')94 if ct_table_match:95 add_relation('ct_primary_key')96 add_relation('ct_table_match')97 add_relation('ct_any_table')98 add_relation('tq_default')99 # if cq_token_match:100 # add_relation('tq_token_match')101 add_relation('tc_default')102 if tc_table_match:103 add_relation('tc_primary_key')104 add_relation('tc_table_match')105 add_relation('tc_any_table')106 if tc_foreign_key:107 add_relation('tc_foreign_key')108 add_relation('tt_default')109 if tt_foreign_key:110 add_relation('tt_foreign_key_forward')111 add_relation('tt_foreign_key_backward')112 add_relation('tt_foreign_key_both')113 add_rel_dist('tt_dist', tt_max_dist)114 # schema linking relations115 # forward_backward116 if sc_link:117 add_relation('qcCEM')118 add_relation('cqCEM')119 add_relation('qtTEM')120 add_relation('tqTEM')121 add_relation('qcCPM')122 add_relation('cqCPM')123 add_relation('qtTPM')124 add_relation('tqTPM')125 if cv_link:126 add_relation("qcNUMBER")127 add_relation("cqNUMBER")128 add_relation("qcTIME")129 add_relation("cqTIME")130 add_relation("qcCELLMATCH")131 add_relation("cqCELLMATCH")132 if merge_types:133 assert not cc_foreign_key134 assert not cc_table_match135 assert not ct_foreign_key136 assert not ct_table_match137 assert not tc_foreign_key138 assert not tc_table_match139 assert not tt_foreign_key140 assert cc_max_dist == qq_max_dist141 assert tt_max_dist == qq_max_dist142 add_relation('xx_default')143 self.relation_ids['qc_default'] = self.relation_ids['xx_default']144 self.relation_ids['qt_default'] = self.relation_ids['xx_default']145 self.relation_ids['cq_default'] = self.relation_ids['xx_default']146 self.relation_ids['cc_default'] = self.relation_ids['xx_default']147 self.relation_ids['ct_default'] = self.relation_ids['xx_default']148 self.relation_ids['tq_default'] = self.relation_ids['xx_default']149 self.relation_ids['tc_default'] = self.relation_ids['xx_default']150 self.relation_ids['tt_default'] = self.relation_ids['xx_default']151 if sc_link:152 self.relation_ids['qcCEM'] = self.relation_ids['xx_default']153 self.relation_ids['qcCPM'] = self.relation_ids['xx_default']154 self.relation_ids['qtTEM'] = self.relation_ids['xx_default']155 self.relation_ids['qtTPM'] = self.relation_ids['xx_default']156 self.relation_ids['cqCEM'] = self.relation_ids['xx_default']...

Full Screen

Full Screen

script.py

Source:script.py Github

copy

Full Screen

...4class Graph:5 def __init__(self) -> None:6 self.vertices: list = []7 self.vert_neigh_dict: Dict[str, List[Tuple[str, int]]] = {}8 def add_relation(self, start: str, end: str, time: int) -> None:9 if start not in self.vertices:10 self.vertices.append(start)11 if end not in self.vertices:12 self.vertices.append(end)13 if start not in self.vert_neigh_dict.keys():14 self.vert_neigh_dict[start] = []15 if end not in self.vert_neigh_dict.keys():16 self.vert_neigh_dict[end] = []17 if ((end, time) in self.vert_neigh_dict[start]) or ((start, time) in self.vert_neigh_dict[end]):18 return19 self.vert_neigh_dict[start].append((end, time))20 self.vert_neigh_dict[end].append((start, time))21 @property22 def vertices_(self) -> list:23 return self.vertices24 def get_neighbours(self, vertex: str) -> list:25 if vertex in self.vertices:26 return [neighbour for neighbour, time in self.vert_neigh_dict[vertex]]27 else:28 raise KeyError(f'{vertex} not present as a vertex in database')29 def _get_adjacency_list(self, vertex: str) -> list:30 return self.vert_neigh_dict[vertex]31 def _h(self, node: str):32 H = {vertex: 1 for vertex in self.vertices}33 return H[node]34 def a_star_algorithm(self, start: str, end: str):35 open_list = set([start])36 closed_list = set([])37 g = {}38 g[start] = 039 parents = {}40 parents[start] = start41 while len(open_list) > 0:42 n = None43 for v in open_list:44 if n == None or g[v] + self._h(v) < g[n] + self._h(n):45 n = v46 if n == None:47 # -> # return string48 # print('Path does not exist!')49 return None50 if n == end:51 reconst_path = []52 while parents[n] != n:53 reconst_path.append(n)54 n = parents[n]55 reconst_path.append(end)56 reconst_path.reverse()57 # print('Path found: {}'.format(reconst_path))58 reconst_path[0] = start59 time_duration = 060 for node in reconst_path:61 if node == end:62 break63 for neighbour, time in self._get_adjacency_list(node):64 if neighbour == reconst_path[reconst_path.index(node) + 1]:65 time_duration += time66 return reconst_path, time_duration67 for (m, weight) in self._get_adjacency_list(n):68 if m not in open_list and m not in closed_list:69 open_list.add(m)70 parents[m] = n71 g[m] = g[n] + weight72 else:73 if g[m] > g[n] + weight:74 g[m] = g[n] + weight75 parents[m] = n76 if m in closed_list:77 closed_list.remove(m)78 open_list.add(m)79 open_list.remove(n)80 closed_list.add(n)81# -> # Change return and remove print statement82 # print('Path does not exist!')83 return None84if __name__ == '__main__':85 graph = Graph()86 # Adding the Western Line87 graph.add_relation('Dahanu Road', 'Vangaon', 13)88 graph.add_relation('Vangaon', 'Boisar', 9)89 graph.add_relation('Boisar', 'Umroli', 6)90 graph.add_relation('Umroli', 'Palghar', 6)91 graph.add_relation('Palghar', 'Kelve Rd.', 15)92 graph.add_relation('Kelve Rd.', 'Saphale', 8)93 graph.add_relation('Saphale', 'Vaitarna', 8)94 graph.add_relation('Vaitarna', 'Virar', 9)95 graph.add_relation('Virar', 'Nallasopara', 6)96 graph.add_relation('Nallasopara', 'Vasai Rd.', 5)97 graph.add_relation('Vasai Rd.', 'Naigaon', 5)98 graph.add_relation('Naigaon', 'Bhayandar', 6)99 graph.add_relation('Bhayandar', 'Mira Road', 5)100 graph.add_relation('Mira Road', 'Dahisar', 5)101 graph.add_relation('Dahisar', 'Borivali', 5)102 graph.add_relation('Borivali', 'Kandivali', 6)103 graph.add_relation('Kandivali', 'Malad', 3)104 graph.add_relation('Malad', 'Goregaon', 5)105 graph.add_relation('Goregaon', 'Ram Mandir', 2)106 graph.add_relation('Ram Mandir', 'Jogeshwari', 3)107 graph.add_relation('Jogeshwari', 'Andheri', 4)108 graph.add_relation('Andheri', 'Vile Parle', 5)109 graph.add_relation('Vile Parle', 'Santacruz', 3)110 graph.add_relation('Santacruz', 'Khar Road', 2)111 graph.add_relation('Khar Road', 'Bandra', 3)112 graph.add_relation('Bandra', 'Mahim', 4)113 graph.add_relation('Mahim', 'Matunga Rd.', 3)114 graph.add_relation('Matunga Rd.', 'Dadar', 2)115 graph.add_relation('Dadar', 'Prabhadevi', 2)116 graph.add_relation('Prabhadevi', 'Lower Parel', 3)117 graph.add_relation('Lower Parel', 'Mahalaxmi', 3)118 graph.add_relation('Mahalaxmi', 'Mumbai Central (MMCT)', 3)119 graph.add_relation('Mumbai Central (MMCT)', 'Grant Rd.', 2)120 graph.add_relation('Grant Rd.', 'Charni Rd.', 3)121 graph.add_relation('Charni Rd.', 'Marine Lines', 2)122 graph.add_relation('Marine Lines', 'Churchgate', 3)123 # Adding the Central Line124 graph.add_relation(125 'Chatrapati Shivaji Maharaj Terminus (CSMT)', 'Masjid', 3)126 graph.add_relation('Masjid', 'Sandhurst Rd.', 2)127 graph.add_relation('Sandhurst Rd.', 'Byculla', 3)128 graph.add_relation('Byculla', 'Chinchpokali', 2)129 graph.add_relation('Chinchpokali', 'Currey Rd.', 2)130 graph.add_relation('Currey Rd.', 'Parel', 3)131 graph.add_relation('Parel', 'Dadar', 3)132 graph.add_relation('Dadar', 'Matunga', 3)133 graph.add_relation('Matunga', 'Sion', 4)134 graph.add_relation('Sion', 'Kurla', 4)135 graph.add_relation('Kurla', 'Vidya Vihar', 3)136 graph.add_relation('Vidya Vihar', 'Ghatkopar', 3)137 graph.add_relation('Ghatkopar', 'Vikhroli', 5)138 graph.add_relation('Vikhroli', 'Kanjur Marg', 3)139 graph.add_relation('Kanjur Marg', 'Bhandup', 3)140 graph.add_relation('Bhandup', 'Nahur', 3)141 graph.add_relation('Nahur', 'Mulund', 3)142 graph.add_relation('Mulund', 'Thane', 4)143 graph.add_relation('Thane', 'Kalwa', 4)144 graph.add_relation('Kalwa', 'Mumbra', 6)145 graph.add_relation('Mumbra', 'Diva', 4)146 graph.add_relation('Diva', 'Kopar', 5)147 graph.add_relation('Kopar', 'Dombivali', 4)148 graph.add_relation('Dombivali', 'Thakurli', 3)149 graph.add_relation('Thakurli', 'Kalyan', 6)150 graph.add_relation('Kalyan', 'Shahad', 5)151 graph.add_relation('Shahad', 'Ambivli', 3)152 graph.add_relation('Ambivli', 'Titwala', 5)153 graph.add_relation('Titwala', 'Khadavali', 6)154 graph.add_relation('Khadavali', 'Vashind', 8)155 graph.add_relation('Vashind', 'Asangaon', 6)156 graph.add_relation('Asangaon', 'Atgaon', 9)157 graph.add_relation('Atgaon', 'Thansit', 7)158 graph.add_relation('Thansit', 'Khardi', 5)159 graph.add_relation('Khardi', 'Umbernali', 6)160 graph.add_relation('Umbernali', 'Kasara', 12)161 graph.add_relation('Kalyan', 'Vitthalvadi', 5)162 graph.add_relation('Vitthalvadi', 'Ulhasnagar', 3)163 graph.add_relation('Ulhasnagar', 'Ambernath', 6)164 graph.add_relation('Ambernath', 'Badlapur', 8)165 graph.add_relation('Badlapur', 'Vangani', 9)166 graph.add_relation('Vangani', 'Shelu', 4)167 graph.add_relation('Shelu', 'Neral', 4)168 graph.add_relation('Neral', 'Bhivpuri Rd.', 7)169 graph.add_relation('Bhivpuri Rd.', 'Karjat', 9)170 graph.add_relation('Karjat', 'Palasdhari', 5)171 graph.add_relation('Palasdhari', 'Kelavali', 7)172 graph.add_relation('Kelavali', 'Dolavali', 3)173 graph.add_relation('Dolavali', 'Lowjee', 4)174 graph.add_relation('Lowjee', 'Khopoli', 4)175 # Adding harbour line176 graph.add_relation(177 'Chatrapati Shivaji Maharaj Terminus (CSMT)', 'Masjid', 3)178 graph.add_relation('Masjid', 'Sandhurst Rd.', 2)179 graph.add_relation('Sandhurst Rd.', 'Dockyard Rd.', 2)180 graph.add_relation('Dockyard Rd.', 'Reay Rd.', 2)181 graph.add_relation('Reay Rd.', 'Cotton Green', 2)182 graph.add_relation('Cotton Green', 'Sewri', 3)183 graph.add_relation('Sewri', 'Vadala', 3)184 graph.add_relation('Vadala', 'GTB Nagar', 4)185 graph.add_relation('GTB Nagar', 'Chuna Bhatti', 3)186 graph.add_relation('Chuna Bhatti', 'Kurla', 3)187 graph.add_relation('Kurla', 'Tilak Nagar (LTT)', 3)188 graph.add_relation('Tilak Nagar (LTT)', 'Chembur', 3)189 graph.add_relation('Chembur', 'Govandi', 3)190 graph.add_relation('Govandi', 'Mankhurd', 3)191 graph.add_relation('Mankhurd', 'Vashi', 8)192 graph.add_relation('Vashi', 'Sanpada', 3)193 graph.add_relation('Sanpada', 'Juinagar', 3)194 graph.add_relation('Juinagar', 'Nerul', 3)195 graph.add_relation('Nerul', 'Seawood Darave', 3)196 graph.add_relation('Seawood Darave', 'Belapur', 4)197 graph.add_relation('Belapur', 'Kharghar', 4)198 graph.add_relation('Kharghar', 'Manasarovar', 3)199 graph.add_relation('Manasarovar', 'Khandeshwar', 3)200 graph.add_relation('Khandeshwar', 'Panvel', 3)201 graph.add_relation('Vadala', "King's Circle", 4)202 graph.add_relation("King's Circle", 'Mahim', 4)203 graph.add_relation("Mahim", 'Bandra', 4)204 graph.add_relation("Bandra", 'Khar Road', 3)205 graph.add_relation("Khar Road", 'Santacruz', 2)206 graph.add_relation("Santacruz", 'Vile Parle', 3)207 graph.add_relation("Vile Parle", 'Andheri', 5)208 graph.add_relation("Andheri", 'Jogeshwari', 4)209 graph.add_relation("Jogeshwari", 'Ram Mandir', 3)210 graph.add_relation("Ram Mandir", 'Goregaon', 2)211 # Adding metro line (Ghatkopar-Versova)212 graph.add_relation("Ghatkopar", "Jagruti Nagar", 3)213 graph.add_relation("Jagruti Nagar", "Asalpha", 2)214 graph.add_relation("Asalpha", "Saki Naka", 2)215 graph.add_relation("Saki Naka", "Marol Naka", 1)216 graph.add_relation("Marol Naka", "Airport Road", 2)217 graph.add_relation("Airport Road", "Chakala/JB Nagar", 2)218 graph.add_relation("Chakala/JB Nagar", "Western Express Highway", 2)219 graph.add_relation("Western Express Highway", "Andheri", 2)220 graph.add_relation("Andheri", "Azad Nagar", 4)221 graph.add_relation("Azad Nagar", "D N Nagar", 2)222 graph.add_relation("D N Nagar", "Versova", 1)223 # Adding Nerul-Uran line224 graph.add_relation("Nerul", "Seawood Darave", 3)225 graph.add_relation("Seawood Darave", "Bamadongri", 13)226 graph.add_relation("Belapur", "Bamadongri", 14)227 graph.add_relation("Bamadongri", "Kharkopar", 4)228 # Adding the Trans-Harbour line229 graph.add_relation("Thane", "Airoli", 8)230 graph.add_relation("Airoli", "Rabale", 3)231 graph.add_relation("Rabale", "Ghansoli", 3)232 graph.add_relation("Ghansoli", "Koparkhairane", 3)233 graph.add_relation("Koparkhairane", "Turbhe", 4)234 graph.add_relation("Turbhe", "Juinagar", 4)235 graph.add_relation("Juinagar", "Nerul", 4)236 graph.add_relation("Nerul", "Seawood Darave", 4)237 graph.add_relation("Seawood Darave", "Belapur", 5)238 graph.add_relation("Belapur", "Kharghar", 4)239 graph.add_relation("Kharghar", "Manasarovar", 3)240 graph.add_relation("Manasarovar", "Khandeshwar", 3)241 graph.add_relation("Khandeshwar", "Panvel", 5)242 graph.add_relation("Turbhe", "Sanpada", 4)243 graph.add_relation("Sanpada", "Vashi", 4)244 # Adding mono-rail245 graph.add_relation("Sant Gadge Maharaj Chowk", "Lower Parel", 2)246 graph.add_relation("Lower Parel", "Mint Colony", 2)247 graph.add_relation("Mint Colony", "Ambedkar Nagar", 3)248 graph.add_relation("Ambedkar Nagar", "Naigaon (near Dadar)", 3)249 graph.add_relation("Naigaon (near Dadar)", "Dadar East", 2)250 graph.add_relation("Dadar East", "Wadala Bridge", 3)251 graph.add_relation("Wadala Bridge", "Acharya Atre Nagar", 3)252 graph.add_relation("Acharya Atre Nagar", "Antop Hill", 2)253 graph.add_relation("Antop Hill", "GTB Nagar", 3)254 graph.add_relation("GTB Nagar", "Wadala", 2)255 graph.add_relation("Wadala", "Bhakti Park", 3)256 graph.add_relation("Bhakti Park", "Mysore Colony", 4)257 graph.add_relation("Mysore Colony", "Bharat Petroleum", 3)258 graph.add_relation("Bharat Petroleum", "Fertiliser Township", 3)259 graph.add_relation("Fertiliser Township", "VNP Marg Junction", 2)260 graph.add_relation("VNP Marg Junction", "Chembur", 3)261 with open('network.pkl', 'wb') as f:262 pickle.dump(graph, f)...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

1# from flask import Flask,render_template,request, url_for, redirect, flash , session2# from flask_sqlalchemy import SQLAlchemy3# from flask_login import login_user, login_required4# from flask_login import LoginManager, current_user5# from flask_login import logout_user, UserMixin6# from flask_wtf.csrf import CSRFProtect7#8# # 全局变量,为ShowAccount和regist之间传递账号9# account=None10# # 这个callback函数用于reload User object,根据session中存储的user_id,我们可以通过对current_user对象调用is_authenticated等属性来判断当前用户的认证状态。11# # 如果用户未登录,current_user默认会返回Flask-Login内置的AnonymousUserMixin类对象,它的is_authenticated和is_active属性会返回False,而is_anonymous属性则返回True。12# csrf=CSRFProtect()13# csrf.init_app(app)14# # 调用current_user前,先执行user_loader,传入的数据是session中的id(唯一),将CurrentUser中对应的项作为返回值15# @login_manager.user_loader16# def load_user(account):17# return CurrentUser.query.get(account)18# # 注册页面19# @app.route('/regist.html',methods=['GET','POST'])20# def regist():21# regForm=RegisterForm()22# # POST方法, 如果数据合理,那么放入数据库中;否则提示错误;23# if regForm.validate_on_submit():24# # 获取数据25# global account26# account=generate_account()27# while CurrentUser.query.get(account)!=None:28# account=generate_account()29# password=regForm.password.data30# name=regForm.name.data31# phonenumber=regForm.phonenumber.data32# sex=regForm.sex.data33# idcard=regForm.idcard.data34# email=regForm.email.data35# # 将数据添加入数据库中;36# current_user_message=CurrentUser(account,name,password,email,idcard,sex,phonenumber)37# db.session.add(current_user_message)38# db.session.commit()39# return redirect(url_for('back_to_login'))40# # 数据不合理/未提交,显示原页面附加错误信息41# return render_template('regist.html',form=regForm,count=CurrentUser.query.count())42# # 注册后显示账号43# @app.route('/accountback.html',methods=['GET','POST'])44# def back_to_login():45# sa=ShowAccount()46# global account47# # 返回登录页面48# if request.method=='POST':49# return redirect(url_for('basic'))50# return render_template('accountback.html',account=account)51# # 主页52# '''53# homepage.html作为主界面;分为两种情况:登录状态,非登陆状态;54# 登录状态:根据登录信息,获取老师和学生的信息55# 非登陆状态:显示界面,不显示信息; 在非登陆状态点击功能图标,会跳转入登录界面;56# 具有Login/Logout两个按钮(选项):(或者根据登录状态变更)57# 1.对于未登录状态,Login,并跳转入登陆界面58# 2.对于登陆状态,Logout,并跳转入原界面的非登陆状态59# '''60# @app.route('/homepage.html',methods=['GET','POST'])61# @app.route('/', methods=['GET', 'POST'])62# def homepage():63# # 用户登录64# if current_user.is_authenticated:65# #获得账号66# account=session.get('account')67# #返回老师和学生信息的列表,信息只有账号属性;68# teacher_list=db.session.query(Teacher).filter(Teacher.account==account).all()69# student_list=db.session.query(Student).filter(Student.account==account).all()70# # 将信息返回给前端,显示,count=Student.query.all()71# return render_template('homepage.html',students=student_list,teachers=teacher_list,count=Student.query.count())72# # 游客状态73# else:74# return render_template('homepage.html')75# # 添加关系; 建立表单的form76# @app.route('/add.html',methods=['GET','POST'])77# @login_required78# def add():79# # 获取账号信息80# account=session.get('account')81# # 添加信息82# add_relation=AddRelation()83# if add_relation.validate_on_submit():84# flash(u'成功validate')85# if CurrentUser.query.get(add_relation.account.data)==None:86# flash(u'该用户不存在,无法建立关系')87# return render_template('add.html',form=add_relation)88# else :89# # 对方是你的老师90# if add_relation.T_or_S.data=="teacher" :91# flash('teacher')92# t1=Teacher(add_relation.account.data,add_relation.starttime,add_relation.endtime.data)93# s1=Student(account,add_relation.starttime,add_relation.endtime.data)94# t2=[]95# t2.append(t1)96# s1.teachers=t297# db.session.add(s1)98# db.session.commit()99# else:100# flash(u'student')101# t1=Teacher(account,add_relation.starttime,add_relation.endtime.data)102# s1=Student(add_relation.account.data,add_relation.starttime,add_relation.endtime.data)103# t2=[]104# t2.append(t1)105# s1.teachers=t2106# db.session.add(s1)107# db.session.commit()108# redirect(url_for('homepage'))109# return render_template('add.html',form=add_relation)110# # logout:退出账号111# @app.route('/logout')112# @login_required113# def logout():114# logout_user()115# flash('Logout success.', 'info')...

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