Best JavaScript code snippet using wpt
performance_evaluation.py
Source:performance_evaluation.py
1import re2class NameScoreTable:3 def __init__(self):4 self.names = []5 self.scores = []6 self.years = []7 def append(self, pair):8 self.names.append(pair.name.lower())9 self.scores.append(pair.score)10 self.years.append(pair.year)11 def get_score(self, name, year=False):12 if name in self.names:13 if year:14 indices = [i for i, x in enumerate(self.names) if x == name]15 for i in indices:16 if self.years[i] == year:17 index = i18 else:19 index = self.names.index(name)20 score = self.scores[index]21 year = self.years[index]22 return score, year23 else:24 print('Error: No matching name, ', name)25 return None, None26class NameScorePair:27 def __init__(self, name, score, year):28 self.name = name29 self.score = score30 self.year = year31def define_perf_name_to_score():32 # 1st prize = 633 # 2nd to 3rd prize = 534 # 4th to 6th prize = 435 # final = 336 # semi_final = 237 # second round = 138 # audition, first round = 039 name_score_table = NameScoreTable()40 name_score_table.append(NameScorePair('Dossin', 0, 2002))41 name_score_table.append(NameScorePair('Ali', 0, 2008))42 name_score_table.append(NameScorePair('Day', 0, 2006))43 name_score_table.append(NameScorePair('Jia', 1, 2004)) #check ran jia and jia ran44 name_score_table.append(NameScorePair('LeeKoeun', 3, 2004))45 name_score_table.append(NameScorePair('LinTao', 2, 2002))46 name_score_table.append(NameScorePair('McNamara', 0, 2008))47 name_score_table.append(NameScorePair('Sinkev', 4, 2004))48 name_score_table.append(NameScorePair('YeSijing', 0, 2008))49 name_score_table.append(NameScorePair('Denisova', 3, 2008))50 name_score_table.append(NameScorePair('MunA', 5, 2015))51 name_score_table.append(NameScorePair('Zhou', 3, 2011))52 name_score_table.append(NameScorePair('Sladek', 1, 2011))53 name_score_table.append(NameScorePair('KimSuyeon', 5, 2011))54 name_score_table.append(NameScorePair('Tetzloff', 2, 2008))55 name_score_table.append(NameScorePair('Gasanov', 1, 2009))56 name_score_table.append(NameScorePair('Ko', 3, 2008))57 name_score_table.append(NameScorePair('Tan', 0, 2008))58 name_score_table.append(NameScorePair('Khmara', 1, 2008))59 name_score_table.append(NameScorePair('Kociuban', 3, 2008))60 name_score_table.append(NameScorePair('Levitsky', 4, 2008))61 name_score_table.append(NameScorePair('Nikiforov', 5, 2008))62 name_score_table.append(NameScorePair('ChenC', 1, 2006))63 name_score_table.append(NameScorePair('Yang', 0, 2006))64 name_score_table.append(NameScorePair('Solom', 0, 2004))65 name_score_table.append(NameScorePair('Lim', 0, 2002))66 name_score_table.append(NameScorePair('LuEric', 6, 2013))67 name_score_table.append(NameScorePair('GonzalezJ', 1, 2014))68 name_score_table.append(NameScorePair('Verbaite', 0, 2008))69 name_score_table.append(NameScorePair('Avdeeva', 1, 2006))70 name_score_table.append(NameScorePair('MorozovS', 1, 2006))71 name_score_table.append(NameScorePair('Park', 1, 2006))72 name_score_table.append(NameScorePair('Savitski', 6, 2006))73 name_score_table.append(NameScorePair('Shelest', 0, 2006))74 name_score_table.append(NameScorePair('Stahievitch', 0, 2006))75 name_score_table.append(NameScorePair('Tysman', 0, 2006))76 name_score_table.append(NameScorePair('Giltburg', 0, 2002))77 name_score_table.append(NameScorePair('Hireche', 0, 2002))78 name_score_table.append(NameScorePair('Mikhailoff', 0, 2002))79 name_score_table.append(NameScorePair('Hireche', 0, 2002))80 name_score_table.append(NameScorePair('Stahievitch', 0, 2002))81 name_score_table.append(NameScorePair('SunMeiting', 6, 2002))82 name_score_table.append(NameScorePair('Adig', 1, 2004))83 name_score_table.append(NameScorePair('Benabd', 1, 2004))84 name_score_table.append(NameScorePair('Blinov', 1, 2004))85 name_score_table.append(NameScorePair('ChenJie', 6, 2004))86 name_score_table.append(NameScorePair('Choe', 0, 2004))87 name_score_table.append(NameScorePair('Danilo', 1, 2004))88 name_score_table.append(NameScorePair('Evstio', 5, 2004))89 name_score_table.append(NameScorePair('Faliks', 1, 2004))90 name_score_table.append(NameScorePair('Feiner', 0, 2004))91 name_score_table.append(NameScorePair('Fong', 1, 2004))92 name_score_table.append(NameScorePair('Gadeliya', 0, 2004))93 name_score_table.append(NameScorePair('Gordel', 0, 2004))94 name_score_table.append(NameScorePair('Hagino', 0, 2004))95 name_score_table.append(NameScorePair('Hong', 1, 2004))96 name_score_table.append(NameScorePair('Hsu', 0, 2004))97 name_score_table.append(NameScorePair('HuangB', 0, 2004))98 name_score_table.append(NameScorePair('HuangJ', 1, 2004))99 name_score_table.append(NameScorePair('Ishida', 0, 2004))100 name_score_table.append(NameScorePair('Ivleva', 1, 2004))101 name_score_table.append(NameScorePair('Karyagina', 1, 2004))102 name_score_table.append(NameScorePair('KimBenjamin', 2, 2004))103 name_score_table.append(NameScorePair('KimJ', 0, 2004))104 name_score_table.append(NameScorePair('KimW', 0, 2004))105 name_score_table.append(NameScorePair('Koleso', 4, 2004))106 name_score_table.append(NameScorePair('Krasnitsky', 2, 2004))107 name_score_table.append(NameScorePair('Kwon', 0, 2004))108 name_score_table.append(NameScorePair('LeeHwakyu', 0, 2004))109 name_score_table.append(NameScorePair('LeeJisun', 0, 2004))110 name_score_table.append(NameScorePair('Liao', 0, 2004))111 name_score_table.append(NameScorePair('Luo', 0, 2004))112 name_score_table.append(NameScorePair('Matsum', 0, 2004))113 name_score_table.append(NameScorePair('McVey', 0, 2004))114 name_score_table.append(NameScorePair('Moret', 0, 2004))115 name_score_table.append(NameScorePair('Nakaji', 0, 2004))116 name_score_table.append(NameScorePair('Ousset', 0, 2004))117 name_score_table.append(NameScorePair('Potamousis', 0, 2004))118 name_score_table.append(NameScorePair('Merjan', 0, 2004))119 name_score_table.append(NameScorePair('Schu', 1, 2004))120 name_score_table.append(NameScorePair('Sebastian', 0, 2004))121 name_score_table.append(NameScorePair('Shybay', 4, 2004))122 name_score_table.append(NameScorePair('Sudbin', 0, 2004))123 name_score_table.append(NameScorePair('SunJay', 0, 2004))124 name_score_table.append(NameScorePair('Teterin', 0, 2004))125 name_score_table.append(NameScorePair('Toivio', 0, 2004))126 name_score_table.append(NameScorePair('Ueno', 0, 2004))127 name_score_table.append(NameScorePair('Ushiki', 1, 2004))128 name_score_table.append(NameScorePair('Yoo', 5, 2004))129 name_score_table.append(NameScorePair('You', 0, 2004))130 name_score_table.append(NameScorePair('ZhouWenli', 0, 2004))131 name_score_table.append(NameScorePair('Arciglione', 2, 2006))132 name_score_table.append(NameScorePair('Avila', 0, 2006))133 name_score_table.append(NameScorePair('Bach', 0, 2006))134 name_score_table.append(NameScorePair('Benabdallah', 1, 2006))135 name_score_table.append(NameScorePair('Bogdanovich', 0, 2006))136 name_score_table.append(NameScorePair('CaiSheng', 0, 2006))137 name_score_table.append(NameScorePair('ChenS', 0, 2006))138 name_score_table.append(NameScorePair('DeTurck',4, 2006))139 name_score_table.append(NameScorePair('Dulu', 1, 2006))140 name_score_table.append(NameScorePair('Faliks', 1, 2006))141 name_score_table.append(NameScorePair('Feiner', 0, 2006))142 name_score_table.append(NameScorePair('Fung', 0, 2006))143 name_score_table.append(NameScorePair('Goldberg', 0, 2006))144 name_score_table.append(NameScorePair('Guzman', 0, 2006))145 name_score_table.append(NameScorePair('Han', 0, 2006))146 name_score_table.append(NameScorePair('Hao', 0, 2006))147 name_score_table.append(NameScorePair('Hirata', 0, 2006))148 name_score_table.append(NameScorePair('HouMiao', 0, 2006))149 name_score_table.append(NameScorePair('Huangci', 0, 2006))150 name_score_table.append(NameScorePair('Hwang', 0, 2006))151 name_score_table.append(NameScorePair('Izzard', 0, 2006))152 name_score_table.append(NameScorePair('JiaXin', 0, 2006))153 name_score_table.append(NameScorePair('Katyukova', 0, 2006))154 name_score_table.append(NameScorePair('Kavalerova', 0, 2006))155 name_score_table.append(NameScorePair('KimSunah', 0, 2006))156 name_score_table.append(NameScorePair('KorchinskayaKogan', 5, 2006))157 name_score_table.append(NameScorePair('Koshoeva', 0, 2006))158 name_score_table.append(NameScorePair('Krasnitsky', 2, 2006))159 name_score_table.append(NameScorePair('Larionova', 1, 2006))160 name_score_table.append(NameScorePair('LeeEunjin', 0, 2006))161 name_score_table.append(NameScorePair('LiuLangning', 0, 2006))162 name_score_table.append(NameScorePair('Mordvinov', 4, 2006))163 name_score_table.append(NameScorePair('MorozovS', 1, 2006))164 name_score_table.append(NameScorePair('MorozovY', 0, 2006))165 name_score_table.append(NameScorePair('Na', 1, 2006))166 name_score_table.append(NameScorePair('Namirovsky',1, 2006))167 name_score_table.append(NameScorePair('Pavlovic', 0, 2006))168 name_score_table.append(NameScorePair('Schmitt', 0, 2006))169 name_score_table.append(NameScorePair('Schneider', 0, 2006))170 name_score_table.append(NameScorePair('Sekino', 0, 2006))171 name_score_table.append(NameScorePair('Seo', 0, 2006))172 name_score_table.append(NameScorePair('Shamray', 1, 2006))173 name_score_table.append(NameScorePair('Shen', 1, 2006))174 name_score_table.append(NameScorePair('Shi', 1, 2006))175 name_score_table.append(NameScorePair('Shybayeva', 1, 2006))176 name_score_table.append(NameScorePair('Smirnov', 0, 2006))177 name_score_table.append(NameScorePair('Doe', 1, 2006))178 name_score_table.append(NameScorePair('Yanagitani', 5, 2006))179 name_score_table.append(NameScorePair('Yang', 0, 2006))180 name_score_table.append(NameScorePair('Yarden', 4, 2006))181 name_score_table.append(NameScorePair('Yu', 0, 2006))182 name_score_table.append(NameScorePair('Zagalskaia', 0, 2006))183 name_score_table.append(NameScorePair('Zhao', 0, 2006))184 name_score_table.append(NameScorePair('Zusko', 0, 2006))185 name_score_table.append(NameScorePair('Abdelmoula', 0, 2008))186 name_score_table.append(NameScorePair('Broberg', 0, 2008))187 name_score_table.append(NameScorePair('Cui', 1, 2008))188 name_score_table.append(NameScorePair('Duepree', 6, 2008))189 name_score_table.append(NameScorePair('Huang', 6, 2008))190 name_score_table.append(NameScorePair('KimEloise', 0, 2008))191 name_score_table.append(NameScorePair('Kleisen', 2, 2008))192 name_score_table.append(NameScorePair('Kochetkova', 0, 2008))193 name_score_table.append(NameScorePair('Ko', 3, 2008))194 name_score_table.append(NameScorePair('Kwok', 0, 2008))195 name_score_table.append(NameScorePair('Ladid', 0, 2008))196 name_score_table.append(NameScorePair('Lai', 0, 2008))197 name_score_table.append(NameScorePair('LinTami', 3, 2008))198 name_score_table.append(NameScorePair('Lisiecki', 5, 2008))199 name_score_table.append(NameScorePair('Li', 0, 2008))200 name_score_table.append(NameScorePair('Lo', 0, 2008))201 name_score_table.append(NameScorePair('Meng', 0, 2008))202 name_score_table.append(NameScorePair('Nedayvoda', 0, 2008))203 name_score_table.append(NameScorePair('Qin', 0, 2008))204 name_score_table.append(NameScorePair('Song', 1, 2008))205 name_score_table.append(NameScorePair('SunRan', 0, 2008))206 name_score_table.append(NameScorePair('Tan', 0, 2008))207 name_score_table.append(NameScorePair('Tario', 2, 2008))208 name_score_table.append(NameScorePair('Keanu', 1, 2008))209 name_score_table.append(NameScorePair('Tran', 0, 2008))210 name_score_table.append(NameScorePair('Tuncali', 0, 2008))211 name_score_table.append(NameScorePair('WangA', 1, 2008))212 name_score_table.append(NameScorePair('WangV', 0, 2008))213 name_score_table.append(NameScorePair('Wong', 0, 2008))214 name_score_table.append(NameScorePair('Marks', 2, 2008))215 name_score_table.append(NameScorePair('Yoon', 0, 2008))216 name_score_table.append(NameScorePair('Tim', 1, 2008))217 name_score_table.append(NameScorePair('ZhangX', 0, 2008))218 name_score_table.append(NameScorePair('Gorucan', 0, 2008))219 name_score_table.append(NameScorePair('Ahn', 0, 2009))220 name_score_table.append(NameScorePair('Albright', 0, 2009))221 name_score_table.append(NameScorePair('Atzinger', 0, 2009))222 name_score_table.append(NameScorePair('CaiY', 0, 2009))223 name_score_table.append(NameScorePair('CaiC', 1, 2009))224 name_score_table.append(NameScorePair('ChenL', 0, 2009))225 name_score_table.append(NameScorePair('Erice', 0, 2009))226 name_score_table.append(NameScorePair('Faliks', 0, 2009))227 name_score_table.append(NameScorePair('Falzone', 0, 2009))228 name_score_table.append(NameScorePair('Floril', 0, 2009))229 name_score_table.append(NameScorePair('Garritson', 1, 2009))230 name_score_table.append(NameScorePair('Gasanov', 1, 2009))231 name_score_table.append(NameScorePair('Georgieva', 0, 2009))232 name_score_table.append(NameScorePair('Gintov', 0, 2009))233 name_score_table.append(NameScorePair('Goh', 0, 2009))234 name_score_table.append(NameScorePair('Gokcin', 0, 2009))235 name_score_table.append(NameScorePair('Golubeva', 0, 2009))236 name_score_table.append(NameScorePair('Gryaznov', 1, 2009))237 name_score_table.append(NameScorePair('HouMiao', 0, 2009))238 name_score_table.append(NameScorePair('Huang', 0, 2009))239 name_score_table.append(NameScorePair('JiaRan', 1, 2009))240 name_score_table.append(NameScorePair('Jussow', 1, 2009))241 name_score_table.append(NameScorePair('Karpeyev', 0, 2009))242 name_score_table.append(NameScorePair('KimEunhae', 4, 2009))243 name_score_table.append(NameScorePair('Kunz', 0, 2009))244 name_score_table.append(NameScorePair('Lajko', 0, 2009))245 name_score_table.append(NameScorePair('Lariviere', 0, 2009))246 name_score_table.append(NameScorePair('LeeHanchien', 1, 2009))247 name_score_table.append(NameScorePair('Masycheva', 0, 2009))248 name_score_table.append(NameScorePair('Meek', 0, 2009))249 name_score_table.append(NameScorePair('Na', 4, 2009))250 name_score_table.append(NameScorePair('ParkH', 0, 2009))251 name_score_table.append(NameScorePair('ParkJ', 0, 2009))252 name_score_table.append(NameScorePair('Rozanski', 2, 2009))253 name_score_table.append(NameScorePair('Sekino', 1, 2009))254 name_score_table.append(NameScorePair('Seredenko', 0, 2009))255 name_score_table.append(NameScorePair('Shelest', 0, 2009))256 name_score_table.append(NameScorePair('Shi', 2, 2009))257 name_score_table.append(NameScorePair('Shilyaev', 0, 2009))258 name_score_table.append(NameScorePair('Soukhovetski', 1, 2009))259 name_score_table.append(NameScorePair('Staupe', 1, 2009))260 name_score_table.append(NameScorePair('Sychev', 0, 2009))261 name_score_table.append(NameScorePair('Tak', 1, 2009))262 name_score_table.append(NameScorePair('Tang', 0, 2009))263 name_score_table.append(NameScorePair('Taverna', 6, 2009))264 name_score_table.append(NameScorePair('Terenkova', 0, 2009))265 name_score_table.append(NameScorePair('Toscano', 0, 2009))266 name_score_table.append(NameScorePair('Travinskyy', 0, 2009))267 name_score_table.append(NameScorePair('Tysman', 5, 2009))268 name_score_table.append(NameScorePair('Ulasiuk', 0, 2009))269 name_score_table.append(NameScorePair('Wilshire', 0, 2009))270 name_score_table.append(NameScorePair('Wong', 0, 2009))271 name_score_table.append(NameScorePair('Xu', 0, 2009))272 name_score_table.append(NameScorePair('Yang', 1, 2009))273 name_score_table.append(NameScorePair('Yeletskiy', 5, 2009))274 name_score_table.append(NameScorePair('Zhao', 0, 2009))275 name_score_table.append(NameScorePair('Zhdanov', 1, 2009))276 name_score_table.append(NameScorePair('Zuber', 4, 2009))277 name_score_table.append(NameScorePair('Zukiewicz', 0, 2009))278 name_score_table.append(NameScorePair('Ahfat', 1, 2011))279 name_score_table.append(NameScorePair('Chon', 3, 2011))280 name_score_table.append(NameScorePair('Colafelice', 3, 2011))281 name_score_table.append(NameScorePair('Giesbrecht', 1, 2011))282 name_score_table.append(NameScorePair('Guo', 1, 2011))283 name_score_table.append(NameScorePair('HouKimberly', 2, 2011))284 name_score_table.append(NameScorePair('Kurz', 1, 2011))285 name_score_table.append(NameScorePair('Lan', 1, 2011))286 name_score_table.append(NameScorePair('LeeClaire', 1, 2011))287 name_score_table.append(NameScorePair('LinPeng', 2, 2011))288 name_score_table.append(NameScorePair('Lou', 1, 2011))289 name_score_table.append(NameScorePair('LuXingyu', 2, 2011))290 name_score_table.append(NameScorePair('Mizumoto', 3, 2011))291 name_score_table.append(NameScorePair('Ozaki', 4, 2011))292 name_score_table.append(NameScorePair('Rizikov', 1, 2011))293 name_score_table.append(NameScorePair('Sham', 6, 2011))294 name_score_table.append(NameScorePair('Shychko', 1, 2011))295 name_score_table.append(NameScorePair('Sladek', 1, 2011))296 name_score_table.append(NameScorePair('Song', 1, 2011))297 name_score_table.append(NameScorePair('Teo', 5, 2011))298 name_score_table.append(NameScorePair('WangZitong', 3, 2011))299 name_score_table.append(NameScorePair('Yi', 1, 2011))300 name_score_table.append(NameScorePair('ZhangYunling', 3, 2011))301 name_score_table.append(NameScorePair('Lan', 1, 2011))302 name_score_table.append(NameScorePair('Hebert', 1, 2013))303 name_score_table.append(NameScorePair('Ruan', 1, 2013))304 name_score_table.append(NameScorePair('Eras', 3, 2013))305 name_score_table.append(NameScorePair('Park', 3, 2013))306 name_score_table.append(NameScorePair('Yang', 5, 2013))307 name_score_table.append(NameScorePair('YeZ', 2, 2013))308 name_score_table.append(NameScorePair('Min', 4, 2013))309 name_score_table.append(NameScorePair('JinD', 2, 2013))310 name_score_table.append(NameScorePair('YeF', 2, 2013))311 name_score_table.append(NameScorePair('Mo', 3, 2013))312 name_score_table.append(NameScorePair('Kurz', 1, 2013))313 name_score_table.append(NameScorePair('Knoll', 5, 2013))314 name_score_table.append(NameScorePair('Tsianos',1, 2013))315 name_score_table.append(NameScorePair('Ozel', 3, 2013))316 name_score_table.append(NameScorePair('LuE', 6, 2013))317 name_score_table.append(NameScorePair('Narumi', 1, 2013))318 name_score_table.append(NameScorePair('WongT', 1, 2013))319 name_score_table.append(NameScorePair('Richardson', 4, 2013))320 name_score_table.append(NameScorePair('GuangC', 4, 2014))321 name_score_table.append(NameScorePair('LiuY', 1, 2014))322 name_score_table.append(NameScorePair('WangY', 1, 2014))323 name_score_table.append(NameScorePair('KyykhynenT', 1, 2014))324 name_score_table.append(NameScorePair('ShevchenkoO', 1, 2014))325 name_score_table.append(NameScorePair('HamS', 2, 2014))326 name_score_table.append(NameScorePair('KimHyejin', 2, 2014))327 name_score_table.append(NameScorePair('ParkJ', 2, 2014))328 name_score_table.append(NameScorePair('JohannsonP', 6, 2014))329 name_score_table.append(NameScorePair('GintovP', 2, 2014))330 name_score_table.append(NameScorePair('GonzalezJ', 1, 2014))331 name_score_table.append(NameScorePair('BrendleA', 1, 2014))332 name_score_table.append(NameScorePair('DupreeF', 5, 2014))333 name_score_table.append(NameScorePair('ChernovA', 5, 2014))334 name_score_table.append(NameScorePair('KharselM', 1, 2014))335 name_score_table.append(NameScorePair('MaximovI', 1, 2014))336 name_score_table.append(NameScorePair('MustakimovT', 2, 2014))337 name_score_table.append(NameScorePair('PrjevalskayaM', 4, 2014))338 name_score_table.append(NameScorePair('HuangS', 1, 2014))339 name_score_table.append(NameScorePair('GarritsonL', 1, 2014))340 name_score_table.append(NameScorePair('LeungM', 1, 2014))341 name_score_table.append(NameScorePair('ParkS', 1, 2014))342 name_score_table.append(NameScorePair('LuoJ', 2, 2015))343 name_score_table.append(NameScorePair('VuV', 1, 2015))344 name_score_table.append(NameScorePair('WangA', 1, 2015))345 name_score_table.append(NameScorePair('MiyashitaM', 1, 2015))346 name_score_table.append(NameScorePair('ChenW', 1, 2015))347 name_score_table.append(NameScorePair('LiYz', 4, 2015))348 name_score_table.append(NameScorePair('SunD', 1, 2015))349 name_score_table.append(NameScorePair('HuNY', 2, 2015))350 name_score_table.append(NameScorePair('ZhaoK', 2, 2015))351 name_score_table.append(NameScorePair('WongWY', 2, 2015))352 name_score_table.append(NameScorePair('JeonH', 2, 2015))353 name_score_table.append(NameScorePair('BorickC', 2, 2015))354 name_score_table.append(NameScorePair('Bult-ItoS', 1, 2015))355 name_score_table.append(NameScorePair('LeeN', 6, 2015))356 name_score_table.append(NameScorePair('LeeE', 1, 2015))357 name_score_table.append(NameScorePair('LiuC', 1, 2015))358 name_score_table.append(NameScorePair('LuA', 1, 2015))359 name_score_table.append(NameScorePair('LuM', 1, 2015))360 name_score_table.append(NameScorePair('Richardson', 4, 2015))361 name_score_table.append(NameScorePair('WuuE', 5, 2015))362 name_score_table.append(NameScorePair('YoungS', 2, 2015))363 return name_score_table364TABLE = define_perf_name_to_score()365ART_NAME= re.compile('^[A-Za-z-]+')366YEAR = re.compile('[0-9]{4}')367LIST_YEARS = [2002, 2004, 2006, 2008, 2009, 2011, 2013, 2014, 2015]368def cal_score(name):369 artist_name = ART_NAME.match(name).group().lower()370 year = YEAR.match(name)371 if year:372 score = TABLE.get_score(artist_name, year)373 else:374 score, year = TABLE.get_score(artist_name)375 print(artist_name, score, year)376 score_year = [0] * 10377 score_year[0] = score378 year_index = LIST_YEARS.index(year)379 score_year[year_index+1] = 1...
trumbowyg.table.js
Source:trumbowyg.table.js
1/* ===========================================================2 * trumbowyg.table.custom.js v2.03 * Table plugin for Trumbowyg4 * http://alex-d.github.com/Trumbowyg5 * ===========================================================6 * Author : Sven Dunemann [dunemann@forelabs.eu]7 */8(function ($) {9 'use strict';10 var defaultOptions = {11 rows: 8,12 columns: 8,13 styler: 'table'14 };15 $.extend(true, $.trumbowyg, {16 langs: {17 // jshint camelcase:false18 en: {19 table: 'Insert table',20 tableAddRow: 'Add row',21 tableAddRowAbove: 'Add row above',22 tableAddColumnLeft: 'Add column to the left',23 tableAddColumn: 'Add column to the right',24 tableDeleteRow: 'Delete row',25 tableDeleteColumn: 'Delete column',26 tableDestroy: 'Delete table',27 error: 'Error'28 },29 cs: {30 table: 'VytvoÅit pÅÃkaz Table',31 tableAddRow: 'PÅidat Åádek',32 tableAddRowAbove: 'PÅidat Åádek',33 tableAddColumnLeft: 'PÅidat sloupec',34 tableAddColumn: 'PÅidat sloupec',35 error: 'Chyba'36 },37 da: {38 table: 'Indsæt tabel',39 tableAddRow: 'Tilføj række',40 tableAddRowAbove: 'Tilføj række',41 tableAddColumnLeft: 'Tilføj kolonne',42 tableAddColumn: 'Tilføj kolonne',43 tableDeleteRow: 'Slet række',44 tableDeleteColumn: 'Slet kolonne',45 tableDestroy: 'Slet tabel',46 error: 'Fejl'47 },48 de: {49 table: 'Tabelle einfügen',50 tableAddRow: 'Zeile hinzufügen',51 tableAddRowAbove: 'Zeile hinzufügen',52 tableAddColumnLeft: 'Spalte hinzufügen',53 tableAddColumn: 'Spalte hinzufügen',54 tableDeleteRow: 'Zeile löschen',55 tableDeleteColumn: 'Spalte löschen',56 tableDestroy: 'Tabelle löschen',57 error: 'Error'58 },59 et: {60 table: 'Sisesta tabel',61 tableAddRow: 'Lisa rida',62 tableAddRowAbove: 'Lisa rida üles',63 tableAddColumnLeft: 'Lisa tulp vasakule',64 tableAddColumn: 'Lisa tulp paremale',65 tableDeleteRow: 'Kustuta rida',66 tableDeleteColumn: 'Kustuta tulp',67 tableDestroy: 'Kustuta tabel',68 error: 'Viga'69 },70 fr: {71 table: 'Insérer un tableau',72 tableAddRow: 'Ajouter des lignes',73 tableAddRowAbove: 'Ajouter des lignes',74 tableAddColumnLeft: 'Ajouter des colonnes',75 tableAddColumn: 'Ajouter des colonnes',76 tableDeleteRow: 'Effacer la ligne',77 tableDeleteColumn: 'Effacer la colonne',78 tableDestroy: 'Effacer le tableau',79 error: 'Erreur'80 },81 hu: {82 table: 'Táblázat beszúrás',83 tableAddRow: 'Sor hozzáadás',84 tableAddRowAbove: 'Sor beszúrás fönt',85 tableAddColumnLeft: 'Sor beszúrás balra',86 tableAddColumn: 'Sor beszúrás jobbra',87 tableDeleteRow: 'Sor törlés',88 tableDeleteColumn: 'Oszlop törlés',89 tableDestroy: 'Táblázat törlés',90 error: 'Hiba'91 },92 id: {93 table: 'Sisipkan tabel',94 tableAddRow: 'Sisipkan baris',95 tableAddRowAbove: 'Sisipkan baris',96 tableAddColumnLeft: 'Sisipkan kolom',97 tableAddColumn: 'Sisipkan kolom',98 tableDeleteRow: 'Hapus baris',99 tableDeleteColumn: 'Hapus kolom',100 tableDestroy: 'Hapus tabel',101 error: 'Galat'102 },103 ja: {104 table: '表ã®æ¿å
¥',105 tableAddRow: 'è¡ã®è¿½å ',106 tableAddRowAbove: 'è¡ã®è¿½å ',107 tableAddColumnLeft: 'åã®è¿½å ',108 tableAddColumn: 'åã®è¿½å ',109 error: 'ã¨ã©ã¼'110 },111 ko: {112 table: 'í ë£ê¸°',113 tableAddRow: 'ì¤ ì¶ê°',114 tableAddRowAbove: 'ì¤ ì¶ê°',115 tableAddColumnLeft: '칸 ì¶ê°',116 tableAddColumn: '칸 ì¶ê°',117 tableDeleteRow: 'ì¤ ìì ',118 tableDeleteColumn: '칸 ìì ',119 tableDestroy: 'í ì§ì°ê¸°',120 error: 'ìë¬'121 },122 pt_br: {123 table: 'Inserir tabela',124 tableAddRow: 'Adicionar linha',125 tableAddRowAbove: 'Adicionar linha',126 tableAddColumnLeft: 'Adicionar coluna',127 tableAddColumn: 'Adicionar coluna',128 tableDeleteRow: 'Deletar linha',129 tableDeleteColumn: 'Deletar coluna',130 tableDestroy: 'Deletar tabela',131 error: 'Erro'132 },133 ru: {134 table: 'ÐÑÑавиÑÑ ÑаблиÑÑ',135 tableAddRow: 'ÐобавиÑÑ ÑÑÑокÑ',136 tableAddRowAbove: 'ÐобавиÑÑ ÑÑÑокÑ',137 tableAddColumnLeft: 'ÐобавиÑÑ ÑÑолбеÑ',138 tableAddColumn: 'ÐобавиÑÑ ÑÑолбеÑ',139 tableDeleteRow: 'УдалиÑÑ ÑÑÑокÑ',140 tableDeleteColumn: 'УдалиÑÑ ÑÑолбеÑ',141 tableDestroy: 'УдалиÑÑ ÑаблиÑÑ',142 error: 'ÐÑибка'143 },144 sk: {145 table: 'VytvoriÅ¥ tabuľky',146 tableAddRow: 'PridaÅ¥ riadok',147 tableAddRowAbove: 'PridaÅ¥ riadok',148 tableAddColumnLeft: 'PridaÅ¥ stĺpec',149 tableAddColumn: 'PridaÅ¥ stĺpec',150 error: 'Chyba'151 },152 tr: {153 table: 'Tablo ekle',154 tableAddRow: 'Satır ekle',155 tableAddRowAbove: 'Yukarıya satır ekle',156 tableAddColumnLeft: 'Sola sütun ekle',157 tableAddColumn: 'SaÄa sütun ekle',158 tableDeleteRow: 'Satırı sil',159 tableDeleteColumn: 'Sütunu sil',160 tableDestroy: 'Tabloyu sil',161 error: 'Hata'162 },163 zh_tw: {164 table: 'æå
¥è¡¨æ ¼',165 tableAddRow: 'å å
¥è¡',166 tableAddRowAbove: 'å å
¥è¡',167 tableAddColumnLeft: 'å å
¥å',168 tableAddColumn: 'å å
¥å',169 tableDeleteRow: 'åªé¤è¡',170 tableDeleteColumn: 'åªé¤å',171 tableDestroy: 'åªé¤è¡¨æ ¼',172 error: 'é¯èª¤'173 },174 es: {175 table: 'Insertar tabla',176 tableAddRow: 'Agregar fila',177 tableAddRowAbove: 'Agregar fila arriba',178 tableAddColumnLeft: 'Agregar columna a la izquierda',179 tableAddColumn: 'Agregar columna a la derecha',180 tableDeleteRow: 'Borrar fila',181 tableDeleteColumn: 'Borrar columna',182 tableDestroy: 'Borrar tabla',183 error: 'Error'184 }// jshint camelcase:true185 },186 plugins: {187 table: {188 init: function (t) {189 t.o.plugins.table = $.extend(true, {}, defaultOptions, t.o.plugins.table || {});190 var buildButtonDef = {191 fn: function () {192 t.saveRange();193 var btnName = 'table';194 var dropdownPrefix = t.o.prefix + 'dropdown',195 dropdownOptions = { // the dropdown196 class: dropdownPrefix + '-' + btnName + ' ' + dropdownPrefix + ' ' + t.o.prefix + 'fixed-top'197 };198 dropdownOptions['data-' + dropdownPrefix] = btnName;199 var $dropdown = $('<div/>', dropdownOptions);200 if (t.$box.find('.' + dropdownPrefix + '-' + btnName).length === 0) {201 t.$box.append($dropdown.hide());202 } else {203 $dropdown = t.$box.find('.' + dropdownPrefix + '-' + btnName);204 }205 // clear dropdown206 $dropdown.html('');207 // when active table show AddRow / AddColumn208 if (t.$box.find('.' + t.o.prefix + 'table-button').hasClass(t.o.prefix + 'active-button')) {209 $dropdown.append(t.buildSubBtn('tableAddRowAbove'));210 $dropdown.append(t.buildSubBtn('tableAddRow'));211 $dropdown.append(t.buildSubBtn('tableAddColumnLeft'));212 $dropdown.append(t.buildSubBtn('tableAddColumn'));213 $dropdown.append(t.buildSubBtn('tableDeleteRow'));214 $dropdown.append(t.buildSubBtn('tableDeleteColumn'));215 $dropdown.append(t.buildSubBtn('tableDestroy'));216 } else {217 var tableSelect = $('<table/>');218 $('<tbody/>').appendTo(tableSelect);219 for (var i = 0; i < t.o.plugins.table.rows; i += 1) {220 var row = $('<tr/>').appendTo(tableSelect);221 for (var j = 0; j < t.o.plugins.table.columns; j += 1) {222 $('<td/>').appendTo(row);223 }224 }225 tableSelect.find('td').on('mouseover', tableAnimate);226 tableSelect.find('td').on('mousedown', tableBuild);227 $dropdown.append(tableSelect);228 $dropdown.append($('<div class="trumbowyg-table-size">1x1</div>'));229 }230 t.dropdown(btnName);231 }232 };233 var tableAnimate = function(columnEvent) {234 var column = $(columnEvent.target),235 table = column.closest('table'),236 colIndex = this.cellIndex,237 rowIndex = this.parentNode.rowIndex;238 // reset all columns239 table.find('td').removeClass('active');240 for (var i = 0; i <= rowIndex; i += 1) {241 for (var j = 0; j <= colIndex; j += 1) {242 table.find('tr:nth-of-type('+(i+1)+')').find('td:nth-of-type('+(j+1)+')').addClass('active');243 }244 }245 // set label246 table.next('.trumbowyg-table-size').html((colIndex+1) + 'x' + (rowIndex+1));247 };248 var tableBuild = function() {249 t.saveRange();250 var tabler = $('<table/>');251 $('<tbody/>').appendTo(tabler);252 if (t.o.plugins.table.styler) {253 tabler.attr('class', t.o.plugins.table.styler);254 }255 var colIndex = this.cellIndex,256 rowIndex = this.parentNode.rowIndex;257 for (var i = 0; i <= rowIndex; i += 1) {258 var row = $('<tr></tr>').appendTo(tabler);259 for (var j = 0; j <= colIndex; j += 1) {260 $('<td/>').appendTo(row);261 }262 }263 t.range.deleteContents();264 t.range.insertNode(tabler[0]);265 t.$c.trigger('tbwchange');266 };267 var addRow = {268 title: t.lang.tableAddRow,269 text: t.lang.tableAddRow,270 ico: 'row-below',271 fn: function () {272 t.saveRange();273 var node = t.doc.getSelection().focusNode;274 var focusedRow = $(node).closest('tr');275 var table = $(node).closest('table');276 if(table.length > 0) {277 var row = $('<tr/>');278 // add columns according to current columns count279 for (var i = 0; i < table.find('tr')[0].childElementCount; i += 1) {280 $('<td/>').appendTo(row);281 }282 // add row to table283 focusedRow.after(row);284 }285 t.syncCode();286 }287 };288 var addRowAbove = {289 title: t.lang.tableAddRowAbove,290 text: t.lang.tableAddRowAbove,291 ico: 'row-above',292 fn: function () {293 t.saveRange();294 var node = t.doc.getSelection().focusNode;295 var focusedRow = $(node).closest('tr');296 var table = $(node).closest('table');297 if(table.length > 0) {298 var row = $('<tr/>');299 // add columns according to current columns count300 for (var i = 0; i < table.find('tr')[0].childElementCount; i += 1) {301 $('<td/>').appendTo(row);302 }303 // add row to table304 focusedRow.before(row);305 }306 t.syncCode();307 }308 };309 var addColumn = {310 title: t.lang.tableAddColumn,311 text: t.lang.tableAddColumn,312 ico: 'col-right',313 fn: function () {314 t.saveRange();315 var node = t.doc.getSelection().focusNode;316 var focusedCol = $(node).closest('td');317 var table = $(node).closest('table');318 var focusedColIdx = focusedCol.index();319 if(table.length > 0) {320 $(table).find('tr').each(function() {321 $($(this).children()[focusedColIdx]).after('<td></td>');322 });323 }324 t.syncCode();325 }326 };327 var addColumnLeft = {328 title: t.lang.tableAddColumnLeft,329 text: t.lang.tableAddColumnLeft,330 ico: 'col-left',331 fn: function () {332 t.saveRange();333 var node = t.doc.getSelection().focusNode;334 var focusedCol = $(node).closest('td');335 var table = $(node).closest('table');336 var focusedColIdx = focusedCol.index();337 if(table.length > 0) {338 $(table).find('tr').each(function() {339 $($(this).children()[focusedColIdx]).before('<td></td>');340 });341 }342 t.syncCode();343 }344 };345 var destroy = {346 title: t.lang.tableDestroy,347 text: t.lang.tableDestroy,348 ico: 'table-delete',349 fn: function () {350 t.saveRange();351 var node = t.doc.getSelection().focusNode,352 table = $(node).closest('table');353 table.remove();354 t.syncCode();355 }356 };357 var deleteRow = {358 title: t.lang.tableDeleteRow,359 text: t.lang.tableDeleteRow,360 ico: 'row-delete',361 fn: function () {362 t.saveRange();363 var node = t.doc.getSelection().focusNode,364 row = $(node).closest('tr');365 row.remove();366 t.syncCode();367 }368 };369 var deleteColumn = {370 title: t.lang.tableDeleteColumn,371 text: t.lang.tableDeleteColumn,372 ico: 'col-delete',373 fn: function () {374 t.saveRange();375 var node = t.doc.getSelection().focusNode,376 table = $(node).closest('table'),377 td = $(node).closest('td'),378 cellIndex = td.index();379 $(table).find('tr').each(function() {380 $(this).find('td:eq(' + cellIndex + ')').remove();381 });382 t.syncCode();383 }384 };385 t.addBtnDef('table', buildButtonDef);386 t.addBtnDef('tableAddRowAbove', addRowAbove);387 t.addBtnDef('tableAddRow', addRow);388 t.addBtnDef('tableAddColumnLeft', addColumnLeft);389 t.addBtnDef('tableAddColumn', addColumn);390 t.addBtnDef('tableDeleteRow', deleteRow);391 t.addBtnDef('tableDeleteColumn', deleteColumn);392 t.addBtnDef('tableDestroy', destroy);393 }394 }395 }396 });...
PostgresQueryRunner.d.ts
Source:PostgresQueryRunner.d.ts
1import { ReadStream } from "../../platform/PlatformTools";2import { BaseQueryRunner } from "../../query-runner/BaseQueryRunner";3import { QueryRunner } from "../../query-runner/QueryRunner";4import { Table } from "../../schema-builder/table/Table";5import { TableCheck } from "../../schema-builder/table/TableCheck";6import { TableColumn } from "../../schema-builder/table/TableColumn";7import { TableExclusion } from "../../schema-builder/table/TableExclusion";8import { TableForeignKey } from "../../schema-builder/table/TableForeignKey";9import { TableIndex } from "../../schema-builder/table/TableIndex";10import { TableUnique } from "../../schema-builder/table/TableUnique";11import { View } from "../../schema-builder/view/View";12import { Query } from "../Query";13import { IsolationLevel } from "../types/IsolationLevel";14import { PostgresDriver } from "./PostgresDriver";15/**16 * Runs queries on a single postgres database connection.17 */18export declare class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner {19 /**20 * Database driver used by connection.21 */22 driver: PostgresDriver;23 /**24 * Promise used to obtain a database connection for a first time.25 */26 protected databaseConnectionPromise: Promise<any>;27 /**28 * Special callback provided by a driver used to release a created connection.29 */30 protected releaseCallback: Function;31 constructor(driver: PostgresDriver, mode?: "master" | "slave");32 /**33 * Creates/uses database connection from the connection pool to perform further operations.34 * Returns obtained database connection.35 */36 connect(): Promise<any>;37 /**38 * Releases used database connection.39 * You cannot use query runner methods once its released.40 */41 release(): Promise<void>;42 /**43 * Starts transaction.44 */45 startTransaction(isolationLevel?: IsolationLevel): Promise<void>;46 /**47 * Commits transaction.48 * Error will be thrown if transaction was not started.49 */50 commitTransaction(): Promise<void>;51 /**52 * Rollbacks transaction.53 * Error will be thrown if transaction was not started.54 */55 rollbackTransaction(): Promise<void>;56 /**57 * Executes a given SQL query.58 */59 query(query: string, parameters?: any[]): Promise<any>;60 /**61 * Returns raw data stream.62 */63 stream(query: string, parameters?: any[], onEnd?: Function, onError?: Function): Promise<ReadStream>;64 /**65 * Returns all available database names including system databases.66 */67 getDatabases(): Promise<string[]>;68 /**69 * Returns all available schema names including system schemas.70 * If database parameter specified, returns schemas of that database.71 */72 getSchemas(database?: string): Promise<string[]>;73 /**74 * Checks if database with the given name exist.75 */76 hasDatabase(database: string): Promise<boolean>;77 /**78 * Checks if schema with the given name exist.79 */80 hasSchema(schema: string): Promise<boolean>;81 /**82 * Checks if table with the given name exist in the database.83 */84 hasTable(tableOrName: Table | string): Promise<boolean>;85 /**86 * Checks if column with the given name exist in the given table.87 */88 hasColumn(tableOrName: Table | string, columnName: string): Promise<boolean>;89 /**90 * Creates a new database.91 * Postgres does not supports database creation inside a transaction block.92 */93 createDatabase(database: string, ifNotExist?: boolean): Promise<void>;94 /**95 * Drops database.96 * Postgres does not supports database drop inside a transaction block.97 */98 dropDatabase(database: string, ifExist?: boolean): Promise<void>;99 /**100 * Creates a new table schema.101 */102 createSchema(schema: string, ifNotExist?: boolean): Promise<void>;103 /**104 * Drops table schema.105 */106 dropSchema(schemaPath: string, ifExist?: boolean, isCascade?: boolean): Promise<void>;107 /**108 * Creates a new table.109 */110 createTable(table: Table, ifNotExist?: boolean, createForeignKeys?: boolean, createIndices?: boolean): Promise<void>;111 /**112 * Drops the table.113 */114 dropTable(target: Table | string, ifExist?: boolean, dropForeignKeys?: boolean, dropIndices?: boolean): Promise<void>;115 /**116 * Creates a new view.117 */118 createView(view: View): Promise<void>;119 /**120 * Drops the view.121 */122 dropView(target: View | string): Promise<void>;123 /**124 * Renames the given table.125 */126 renameTable(oldTableOrName: Table | string, newTableName: string): Promise<void>;127 /**128 * Creates a new column from the column in the table.129 */130 addColumn(tableOrName: Table | string, column: TableColumn): Promise<void>;131 /**132 * Creates a new columns from the column in the table.133 */134 addColumns(tableOrName: Table | string, columns: TableColumn[]): Promise<void>;135 /**136 * Renames column in the given table.137 */138 renameColumn(tableOrName: Table | string, oldTableColumnOrName: TableColumn | string, newTableColumnOrName: TableColumn | string): Promise<void>;139 /**140 * Changes a column in the table.141 */142 changeColumn(tableOrName: Table | string, oldTableColumnOrName: TableColumn | string, newColumn: TableColumn): Promise<void>;143 /**144 * Changes a column in the table.145 */146 changeColumns(tableOrName: Table | string, changedColumns: {147 newColumn: TableColumn;148 oldColumn: TableColumn;149 }[]): Promise<void>;150 /**151 * Drops column in the table.152 */153 dropColumn(tableOrName: Table | string, columnOrName: TableColumn | string): Promise<void>;154 /**155 * Drops the columns in the table.156 */157 dropColumns(tableOrName: Table | string, columns: TableColumn[]): Promise<void>;158 /**159 * Creates a new primary key.160 */161 createPrimaryKey(tableOrName: Table | string, columnNames: string[]): Promise<void>;162 /**163 * Updates composite primary keys.164 */165 updatePrimaryKeys(tableOrName: Table | string, columns: TableColumn[]): Promise<void>;166 /**167 * Drops a primary key.168 */169 dropPrimaryKey(tableOrName: Table | string): Promise<void>;170 /**171 * Creates new unique constraint.172 */173 createUniqueConstraint(tableOrName: Table | string, uniqueConstraint: TableUnique): Promise<void>;174 /**175 * Creates new unique constraints.176 */177 createUniqueConstraints(tableOrName: Table | string, uniqueConstraints: TableUnique[]): Promise<void>;178 /**179 * Drops unique constraint.180 */181 dropUniqueConstraint(tableOrName: Table | string, uniqueOrName: TableUnique | string): Promise<void>;182 /**183 * Drops unique constraints.184 */185 dropUniqueConstraints(tableOrName: Table | string, uniqueConstraints: TableUnique[]): Promise<void>;186 /**187 * Creates new check constraint.188 */189 createCheckConstraint(tableOrName: Table | string, checkConstraint: TableCheck): Promise<void>;190 /**191 * Creates new check constraints.192 */193 createCheckConstraints(tableOrName: Table | string, checkConstraints: TableCheck[]): Promise<void>;194 /**195 * Drops check constraint.196 */197 dropCheckConstraint(tableOrName: Table | string, checkOrName: TableCheck | string): Promise<void>;198 /**199 * Drops check constraints.200 */201 dropCheckConstraints(tableOrName: Table | string, checkConstraints: TableCheck[]): Promise<void>;202 /**203 * Creates new exclusion constraint.204 */205 createExclusionConstraint(tableOrName: Table | string, exclusionConstraint: TableExclusion): Promise<void>;206 /**207 * Creates new exclusion constraints.208 */209 createExclusionConstraints(tableOrName: Table | string, exclusionConstraints: TableExclusion[]): Promise<void>;210 /**211 * Drops exclusion constraint.212 */213 dropExclusionConstraint(tableOrName: Table | string, exclusionOrName: TableExclusion | string): Promise<void>;214 /**215 * Drops exclusion constraints.216 */217 dropExclusionConstraints(tableOrName: Table | string, exclusionConstraints: TableExclusion[]): Promise<void>;218 /**219 * Creates a new foreign key.220 */221 createForeignKey(tableOrName: Table | string, foreignKey: TableForeignKey): Promise<void>;222 /**223 * Creates a new foreign keys.224 */225 createForeignKeys(tableOrName: Table | string, foreignKeys: TableForeignKey[]): Promise<void>;226 /**227 * Drops a foreign key from the table.228 */229 dropForeignKey(tableOrName: Table | string, foreignKeyOrName: TableForeignKey | string): Promise<void>;230 /**231 * Drops a foreign keys from the table.232 */233 dropForeignKeys(tableOrName: Table | string, foreignKeys: TableForeignKey[]): Promise<void>;234 /**235 * Creates a new index.236 */237 createIndex(tableOrName: Table | string, index: TableIndex): Promise<void>;238 /**239 * Creates a new indices240 */241 createIndices(tableOrName: Table | string, indices: TableIndex[]): Promise<void>;242 /**243 * Drops an index from the table.244 */245 dropIndex(tableOrName: Table | string, indexOrName: TableIndex | string): Promise<void>;246 /**247 * Drops an indices from the table.248 */249 dropIndices(tableOrName: Table | string, indices: TableIndex[]): Promise<void>;250 /**251 * Clears all table contents.252 * Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.253 */254 clearTable(tableName: string): Promise<void>;255 /**256 * Removes all tables from the currently connected database.257 */258 clearDatabase(): Promise<void>;259 protected loadViews(viewNames: string[]): Promise<View[]>;260 /**261 * Loads all tables (with given names) from the database and creates a Table from them.262 */263 protected loadTables(tableNames: string[]): Promise<Table[]>;264 /**265 * Builds create table sql.266 */267 protected createTableSql(table: Table, createForeignKeys?: boolean): Query;268 /**269 * Builds drop table sql.270 */271 protected dropTableSql(tableOrPath: Table | string): Query;272 protected createViewSql(view: View): Query;273 protected insertViewDefinitionSql(view: View): Promise<Query>;274 /**275 * Builds drop view sql.276 */277 protected dropViewSql(viewOrPath: View | string): Query;278 /**279 * Builds remove view sql.280 */281 protected deleteViewDefinitionSql(viewOrPath: View | string): Promise<Query>;282 /**283 * Extracts schema name from given Table object or table name string.284 */285 protected extractSchema(target: Table | string): string | undefined;286 /**287 * Drops ENUM type from given schemas.288 */289 protected dropEnumTypes(schemaNames: string): Promise<void>;290 /**291 * Checks if enum with the given name exist in the database.292 */293 protected hasEnumType(table: Table, column: TableColumn): Promise<boolean>;294 /**295 * Builds create ENUM type sql.296 */297 protected createEnumTypeSql(table: Table, column: TableColumn, enumName?: string): Query;298 /**299 * Builds create ENUM type sql.300 */301 protected dropEnumTypeSql(table: Table, column: TableColumn, enumName?: string): Query;302 /**303 * Builds create index sql.304 */305 protected createIndexSql(table: Table, index: TableIndex): Query;306 /**307 * Builds drop index sql.308 */309 protected dropIndexSql(table: Table, indexOrName: TableIndex | string): Query;310 /**311 * Builds create primary key sql.312 */313 protected createPrimaryKeySql(table: Table, columnNames: string[]): Query;314 /**315 * Builds drop primary key sql.316 */317 protected dropPrimaryKeySql(table: Table): Query;318 /**319 * Builds create unique constraint sql.320 */321 protected createUniqueConstraintSql(table: Table, uniqueConstraint: TableUnique): Query;322 /**323 * Builds drop unique constraint sql.324 */325 protected dropUniqueConstraintSql(table: Table, uniqueOrName: TableUnique | string): Query;326 /**327 * Builds create check constraint sql.328 */329 protected createCheckConstraintSql(table: Table, checkConstraint: TableCheck): Query;330 /**331 * Builds drop check constraint sql.332 */333 protected dropCheckConstraintSql(table: Table, checkOrName: TableCheck | string): Query;334 /**335 * Builds create exclusion constraint sql.336 */337 protected createExclusionConstraintSql(table: Table, exclusionConstraint: TableExclusion): Query;338 /**339 * Builds drop exclusion constraint sql.340 */341 protected dropExclusionConstraintSql(table: Table, exclusionOrName: TableExclusion | string): Query;342 /**343 * Builds create foreign key sql.344 */345 protected createForeignKeySql(table: Table, foreignKey: TableForeignKey): Query;346 /**347 * Builds drop foreign key sql.348 */349 protected dropForeignKeySql(table: Table, foreignKeyOrName: TableForeignKey | string): Query;350 /**351 * Builds sequence name from given table and column.352 */353 protected buildSequenceName(table: Table, columnOrName: TableColumn | string, currentSchema?: string, disableEscape?: true, skipSchema?: boolean): string;354 /**355 * Builds ENUM type name from given table and column.356 */357 protected buildEnumName(table: Table, columnOrName: TableColumn | string, withSchema?: boolean, disableEscape?: boolean, toOld?: boolean): string;358 protected getEnumTypeName(table: Table, column: TableColumn): Promise<{359 enumTypeSchema: any;360 enumTypeName: any;361 }>;362 /**363 * Escapes given table or view path.364 */365 protected escapePath(target: Table | View | string, disableEscape?: boolean): string;366 /**367 * Returns object with table schema and table name.368 */369 protected parseTableName(target: Table | string): {370 schema: string;371 tableName: string;372 };373 /**374 * Builds a query for create column.375 */376 protected buildCreateColumnSql(table: Table, column: TableColumn): string;...
CockroachQueryRunner.d.ts
Source:CockroachQueryRunner.d.ts
1import { QueryRunner } from "../../query-runner/QueryRunner";2import { TableColumn } from "../../schema-builder/table/TableColumn";3import { Table } from "../../schema-builder/table/Table";4import { TableIndex } from "../../schema-builder/table/TableIndex";5import { TableForeignKey } from "../../schema-builder/table/TableForeignKey";6import { View } from "../../schema-builder/view/View";7import { Query } from "../Query";8import { CockroachDriver } from "./CockroachDriver";9import { ReadStream } from "../../platform/PlatformTools";10import { TableUnique } from "../../schema-builder/table/TableUnique";11import { BaseQueryRunner } from "../../query-runner/BaseQueryRunner";12import { TableCheck } from "../../schema-builder/table/TableCheck";13import { IsolationLevel } from "../types/IsolationLevel";14import { TableExclusion } from "../../schema-builder/table/TableExclusion";15/**16 * Runs queries on a single postgres database connection.17 */18export declare class CockroachQueryRunner extends BaseQueryRunner implements QueryRunner {19 /**20 * Database driver used by connection.21 */22 driver: CockroachDriver;23 /**24 * Promise used to obtain a database connection for a first time.25 */26 protected databaseConnectionPromise: Promise<any>;27 /**28 * Special callback provided by a driver used to release a created connection.29 */30 protected releaseCallback: Function;31 /**32 * Stores all executed queries to be able to run them again if transaction fails.33 */34 protected queries: {35 query: string;36 parameters?: any[];37 }[];38 /**39 * Indicates if running queries must be stored40 */41 protected storeQueries: boolean;42 constructor(driver: CockroachDriver, mode?: "master" | "slave");43 /**44 * Creates/uses database connection from the connection pool to perform further operations.45 * Returns obtained database connection.46 */47 connect(): Promise<any>;48 /**49 * Releases used database connection.50 * You cannot use query runner methods once its released.51 */52 release(): Promise<void>;53 /**54 * Starts transaction.55 */56 startTransaction(isolationLevel?: IsolationLevel): Promise<void>;57 /**58 * Commits transaction.59 * Error will be thrown if transaction was not started.60 */61 commitTransaction(): Promise<void>;62 /**63 * Rollbacks transaction.64 * Error will be thrown if transaction was not started.65 */66 rollbackTransaction(): Promise<void>;67 /**68 * Executes a given SQL query.69 */70 query(query: string, parameters?: any[], options?: {}): Promise<any>;71 /**72 * Returns raw data stream.73 */74 stream(query: string, parameters?: any[], onEnd?: Function, onError?: Function): Promise<ReadStream>;75 /**76 * Returns all available database names including system databases.77 */78 getDatabases(): Promise<string[]>;79 /**80 * Returns all available schema names including system schemas.81 * If database parameter specified, returns schemas of that database.82 */83 getSchemas(database?: string): Promise<string[]>;84 /**85 * Checks if database with the given name exist.86 */87 hasDatabase(database: string): Promise<boolean>;88 /**89 * Checks if schema with the given name exist.90 */91 hasSchema(schema: string): Promise<boolean>;92 /**93 * Checks if table with the given name exist in the database.94 */95 hasTable(tableOrName: Table | string): Promise<boolean>;96 /**97 * Checks if column with the given name exist in the given table.98 */99 hasColumn(tableOrName: Table | string, columnName: string): Promise<boolean>;100 /**101 * Creates a new database.102 */103 createDatabase(database: string, ifNotExist?: boolean): Promise<void>;104 /**105 * Drops database.106 */107 dropDatabase(database: string, ifExist?: boolean): Promise<void>;108 /**109 * Creates a new table schema.110 */111 createSchema(schema: string, ifNotExist?: boolean): Promise<void>;112 /**113 * Drops table schema.114 */115 dropSchema(schemaPath: string, ifExist?: boolean, isCascade?: boolean): Promise<void>;116 /**117 * Creates a new table.118 */119 createTable(table: Table, ifNotExist?: boolean, createForeignKeys?: boolean, createIndices?: boolean): Promise<void>;120 /**121 * Drops the table.122 */123 dropTable(target: Table | string, ifExist?: boolean, dropForeignKeys?: boolean, dropIndices?: boolean): Promise<void>;124 /**125 * Creates a new view.126 */127 createView(view: View): Promise<void>;128 /**129 * Drops the view.130 */131 dropView(target: View | string): Promise<void>;132 /**133 * Renames the given table.134 */135 renameTable(oldTableOrName: Table | string, newTableName: string): Promise<void>;136 /**137 * Creates a new column from the column in the table.138 */139 addColumn(tableOrName: Table | string, column: TableColumn): Promise<void>;140 /**141 * Creates a new columns from the column in the table.142 */143 addColumns(tableOrName: Table | string, columns: TableColumn[]): Promise<void>;144 /**145 * Renames column in the given table.146 */147 renameColumn(tableOrName: Table | string, oldTableColumnOrName: TableColumn | string, newTableColumnOrName: TableColumn | string): Promise<void>;148 /**149 * Changes a column in the table.150 */151 changeColumn(tableOrName: Table | string, oldTableColumnOrName: TableColumn | string, newColumn: TableColumn): Promise<void>;152 /**153 * Changes a column in the table.154 */155 changeColumns(tableOrName: Table | string, changedColumns: {156 newColumn: TableColumn;157 oldColumn: TableColumn;158 }[]): Promise<void>;159 /**160 * Drops column in the table.161 */162 dropColumn(tableOrName: Table | string, columnOrName: TableColumn | string): Promise<void>;163 /**164 * Drops the columns in the table.165 */166 dropColumns(tableOrName: Table | string, columns: TableColumn[]): Promise<void>;167 /**168 * Creates a new primary key.169 */170 createPrimaryKey(tableOrName: Table | string, columnNames: string[]): Promise<void>;171 /**172 * Updates composite primary keys.173 */174 updatePrimaryKeys(tableOrName: Table | string, columns: TableColumn[]): Promise<void>;175 /**176 * Drops a primary key.177 */178 dropPrimaryKey(tableOrName: Table | string): Promise<void>;179 /**180 * Creates new unique constraint.181 */182 createUniqueConstraint(tableOrName: Table | string, uniqueConstraint: TableUnique): Promise<void>;183 /**184 * Creates new unique constraints.185 */186 createUniqueConstraints(tableOrName: Table | string, uniqueConstraints: TableUnique[]): Promise<void>;187 /**188 * Drops unique constraint.189 */190 dropUniqueConstraint(tableOrName: Table | string, uniqueOrName: TableUnique | string): Promise<void>;191 /**192 * Drops unique constraints.193 */194 dropUniqueConstraints(tableOrName: Table | string, uniqueConstraints: TableUnique[]): Promise<void>;195 /**196 * Creates new check constraint.197 */198 createCheckConstraint(tableOrName: Table | string, checkConstraint: TableCheck): Promise<void>;199 /**200 * Creates new check constraints.201 */202 createCheckConstraints(tableOrName: Table | string, checkConstraints: TableCheck[]): Promise<void>;203 /**204 * Drops check constraint.205 */206 dropCheckConstraint(tableOrName: Table | string, checkOrName: TableCheck | string): Promise<void>;207 /**208 * Drops check constraints.209 */210 dropCheckConstraints(tableOrName: Table | string, checkConstraints: TableCheck[]): Promise<void>;211 /**212 * Creates new exclusion constraint.213 */214 createExclusionConstraint(tableOrName: Table | string, exclusionConstraint: TableExclusion): Promise<void>;215 /**216 * Creates new exclusion constraints.217 */218 createExclusionConstraints(tableOrName: Table | string, exclusionConstraints: TableExclusion[]): Promise<void>;219 /**220 * Drops exclusion constraint.221 */222 dropExclusionConstraint(tableOrName: Table | string, exclusionOrName: TableExclusion | string): Promise<void>;223 /**224 * Drops exclusion constraints.225 */226 dropExclusionConstraints(tableOrName: Table | string, exclusionConstraints: TableExclusion[]): Promise<void>;227 /**228 * Creates a new foreign key.229 */230 createForeignKey(tableOrName: Table | string, foreignKey: TableForeignKey): Promise<void>;231 /**232 * Creates a new foreign keys.233 */234 createForeignKeys(tableOrName: Table | string, foreignKeys: TableForeignKey[]): Promise<void>;235 /**236 * Drops a foreign key from the table.237 */238 dropForeignKey(tableOrName: Table | string, foreignKeyOrName: TableForeignKey | string): Promise<void>;239 /**240 * Drops a foreign keys from the table.241 */242 dropForeignKeys(tableOrName: Table | string, foreignKeys: TableForeignKey[]): Promise<void>;243 /**244 * Creates a new index.245 */246 createIndex(tableOrName: Table | string, index: TableIndex): Promise<void>;247 /**248 * Creates a new indices249 */250 createIndices(tableOrName: Table | string, indices: TableIndex[]): Promise<void>;251 /**252 * Drops an index from the table.253 */254 dropIndex(tableOrName: Table | string, indexOrName: TableIndex | string): Promise<void>;255 /**256 * Drops an indices from the table.257 */258 dropIndices(tableOrName: Table | string, indices: TableIndex[]): Promise<void>;259 /**260 * Clears all table contents.261 * Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.262 */263 clearTable(tableName: string): Promise<void>;264 /**265 * Removes all tables from the currently connected database.266 */267 clearDatabase(): Promise<void>;268 protected loadViews(viewNames: string[]): Promise<View[]>;269 /**270 * Loads all tables (with given names) from the database and creates a Table from them.271 */272 protected loadTables(tableNames: string[]): Promise<Table[]>;273 /**274 * Builds create table sql.275 */276 protected createTableSql(table: Table, createForeignKeys?: boolean): Query;277 /**278 * Extracts schema name from given Table object or table name string.279 */280 protected extractSchema(target: Table | string): string | undefined;281 /**282 * Builds drop table sql.283 */284 protected dropTableSql(tableOrPath: Table | string): Query;285 protected createViewSql(view: View): Query;286 protected insertViewDefinitionSql(view: View): Promise<Query>;287 /**288 * Builds drop view sql.289 */290 protected dropViewSql(viewOrPath: View | string): Query;291 /**292 * Builds remove view sql.293 */294 protected deleteViewDefinitionSql(viewOrPath: View | string): Promise<Query>;295 /**296 * Builds create index sql.297 * UNIQUE indices creates as UNIQUE constraints.298 */299 protected createIndexSql(table: Table, index: TableIndex): Query;300 /**301 * Builds drop index sql.302 */303 protected dropIndexSql(table: Table, indexOrName: TableIndex | TableUnique | string): Query;304 /**305 * Builds create primary key sql.306 */307 protected createPrimaryKeySql(table: Table, columnNames: string[]): Query;308 /**309 * Builds drop primary key sql.310 */311 protected dropPrimaryKeySql(table: Table): Query;312 /**313 * Builds create unique constraint sql.314 */315 protected createUniqueConstraintSql(table: Table, uniqueConstraint: TableUnique | TableIndex): Query;316 /**317 * Builds drop unique constraint sql.318 */319 protected dropUniqueConstraintSql(table: Table, uniqueOrName: TableUnique | string): Query;320 /**321 * Builds create check constraint sql.322 */323 protected createCheckConstraintSql(table: Table, checkConstraint: TableCheck): Query;324 /**325 * Builds drop check constraint sql.326 */327 protected dropCheckConstraintSql(table: Table, checkOrName: TableCheck | string): Query;328 /**329 * Builds create foreign key sql.330 */331 protected createForeignKeySql(table: Table, foreignKey: TableForeignKey): Query;332 /**333 * Builds drop foreign key sql.334 */335 protected dropForeignKeySql(table: Table, foreignKeyOrName: TableForeignKey | string): Query;336 /**337 * Builds sequence name from given table and column.338 */339 protected buildSequenceName(table: Table, columnOrName: TableColumn | string, disableEscape?: true): string;340 /**341 * Escapes given table or view path.342 */343 protected escapePath(target: Table | View | string, disableEscape?: boolean): string;344 /**345 * Returns object with table schema and table name.346 */347 protected parseTableName(target: Table | string): {348 schema: string;349 tableName: string;350 };351 /**352 * Builds a query for create column.353 */354 protected buildCreateColumnSql(table: Table, column: TableColumn): string;...
sfntly.gyp
Source:sfntly.gyp
1# Copyright (c) 2011 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4{5 'variables': {6 'chromium_code': 1,7 },8 'targets': [9 {10 'target_name': 'sfntly',11 'type': 'static_library',12 'sources': [13 'cpp/src/sfntly/data/byte_array.cc',14 'cpp/src/sfntly/data/byte_array.h',15 'cpp/src/sfntly/data/font_data.cc',16 'cpp/src/sfntly/data/font_data.h',17 'cpp/src/sfntly/data/font_input_stream.cc',18 'cpp/src/sfntly/data/font_input_stream.h',19 'cpp/src/sfntly/data/font_output_stream.cc',20 'cpp/src/sfntly/data/font_output_stream.h',21 'cpp/src/sfntly/data/growable_memory_byte_array.cc',22 'cpp/src/sfntly/data/growable_memory_byte_array.h',23 'cpp/src/sfntly/data/memory_byte_array.cc',24 'cpp/src/sfntly/data/memory_byte_array.h',25 'cpp/src/sfntly/data/readable_font_data.cc',26 'cpp/src/sfntly/data/readable_font_data.h',27 'cpp/src/sfntly/data/writable_font_data.cc',28 'cpp/src/sfntly/data/writable_font_data.h',29 'cpp/src/sfntly/font.cc',30 'cpp/src/sfntly/font.h',31 'cpp/src/sfntly/font_factory.cc',32 'cpp/src/sfntly/font_factory.h',33 'cpp/src/sfntly/math/fixed1616.h',34 'cpp/src/sfntly/math/font_math.h',35 'cpp/src/sfntly/port/atomic.h',36 'cpp/src/sfntly/port/config.h',37 'cpp/src/sfntly/port/endian.h',38 'cpp/src/sfntly/port/exception_type.h',39 'cpp/src/sfntly/port/file_input_stream.cc',40 'cpp/src/sfntly/port/file_input_stream.h',41 'cpp/src/sfntly/port/input_stream.h',42 'cpp/src/sfntly/port/lock.cc',43 'cpp/src/sfntly/port/lock.h',44 'cpp/src/sfntly/port/memory_input_stream.cc',45 'cpp/src/sfntly/port/memory_input_stream.h',46 'cpp/src/sfntly/port/memory_output_stream.cc',47 'cpp/src/sfntly/port/memory_output_stream.h',48 'cpp/src/sfntly/port/output_stream.h',49 'cpp/src/sfntly/port/refcount.h',50 'cpp/src/sfntly/port/type.h',51 'cpp/src/sfntly/table/bitmap/big_glyph_metrics.cc',52 'cpp/src/sfntly/table/bitmap/big_glyph_metrics.h',53 'cpp/src/sfntly/table/bitmap/bitmap_glyph.cc',54 'cpp/src/sfntly/table/bitmap/bitmap_glyph.h',55 'cpp/src/sfntly/table/bitmap/bitmap_glyph_info.cc',56 'cpp/src/sfntly/table/bitmap/bitmap_glyph_info.h',57 'cpp/src/sfntly/table/bitmap/bitmap_size_table.cc',58 'cpp/src/sfntly/table/bitmap/bitmap_size_table.h',59 'cpp/src/sfntly/table/bitmap/composite_bitmap_glyph.cc',60 'cpp/src/sfntly/table/bitmap/composite_bitmap_glyph.h',61 'cpp/src/sfntly/table/bitmap/ebdt_table.cc',62 'cpp/src/sfntly/table/bitmap/ebdt_table.h',63 'cpp/src/sfntly/table/bitmap/eblc_table.cc',64 'cpp/src/sfntly/table/bitmap/eblc_table.h',65 'cpp/src/sfntly/table/bitmap/ebsc_table.cc',66 'cpp/src/sfntly/table/bitmap/ebsc_table.h',67 'cpp/src/sfntly/table/bitmap/glyph_metrics.cc',68 'cpp/src/sfntly/table/bitmap/glyph_metrics.h',69 'cpp/src/sfntly/table/bitmap/index_sub_table.cc',70 'cpp/src/sfntly/table/bitmap/index_sub_table.h',71 'cpp/src/sfntly/table/bitmap/index_sub_table_format1.cc',72 'cpp/src/sfntly/table/bitmap/index_sub_table_format1.h',73 'cpp/src/sfntly/table/bitmap/index_sub_table_format2.cc',74 'cpp/src/sfntly/table/bitmap/index_sub_table_format2.h',75 'cpp/src/sfntly/table/bitmap/index_sub_table_format3.cc',76 'cpp/src/sfntly/table/bitmap/index_sub_table_format3.h',77 'cpp/src/sfntly/table/bitmap/index_sub_table_format4.cc',78 'cpp/src/sfntly/table/bitmap/index_sub_table_format4.h',79 'cpp/src/sfntly/table/bitmap/index_sub_table_format5.cc',80 'cpp/src/sfntly/table/bitmap/index_sub_table_format5.h',81 'cpp/src/sfntly/table/bitmap/simple_bitmap_glyph.cc',82 'cpp/src/sfntly/table/bitmap/simple_bitmap_glyph.h',83 'cpp/src/sfntly/table/bitmap/small_glyph_metrics.cc',84 'cpp/src/sfntly/table/bitmap/small_glyph_metrics.h',85 'cpp/src/sfntly/table/byte_array_table_builder.cc',86 'cpp/src/sfntly/table/byte_array_table_builder.h',87 'cpp/src/sfntly/table/core/cmap_table.cc',88 'cpp/src/sfntly/table/core/cmap_table.h',89 'cpp/src/sfntly/table/core/font_header_table.cc',90 'cpp/src/sfntly/table/core/font_header_table.h',91 'cpp/src/sfntly/table/core/horizontal_device_metrics_table.cc',92 'cpp/src/sfntly/table/core/horizontal_device_metrics_table.h',93 'cpp/src/sfntly/table/core/horizontal_header_table.cc',94 'cpp/src/sfntly/table/core/horizontal_header_table.h',95 'cpp/src/sfntly/table/core/horizontal_metrics_table.cc',96 'cpp/src/sfntly/table/core/horizontal_metrics_table.h',97 'cpp/src/sfntly/table/core/maximum_profile_table.cc',98 'cpp/src/sfntly/table/core/maximum_profile_table.h',99 'cpp/src/sfntly/table/core/name_table.cc',100 'cpp/src/sfntly/table/core/name_table.h',101 'cpp/src/sfntly/table/core/os2_table.cc',102 'cpp/src/sfntly/table/core/os2_table.h',103 'cpp/src/sfntly/table/font_data_table.cc',104 'cpp/src/sfntly/table/font_data_table.h',105 'cpp/src/sfntly/table/generic_table_builder.cc',106 'cpp/src/sfntly/table/generic_table_builder.h',107 'cpp/src/sfntly/table/header.cc',108 'cpp/src/sfntly/table/header.h',109 'cpp/src/sfntly/table/subtable.cc',110 'cpp/src/sfntly/table/subtable.h',111 'cpp/src/sfntly/table/subtable_container_table.h',112 'cpp/src/sfntly/table/table.cc',113 'cpp/src/sfntly/table/table.h',114 'cpp/src/sfntly/table/table_based_table_builder.cc',115 'cpp/src/sfntly/table/table_based_table_builder.h',116 'cpp/src/sfntly/table/truetype/glyph_table.cc',117 'cpp/src/sfntly/table/truetype/glyph_table.h',118 'cpp/src/sfntly/table/truetype/loca_table.cc',119 'cpp/src/sfntly/table/truetype/loca_table.h',120 'cpp/src/sfntly/tag.cc',121 'cpp/src/sfntly/tag.h',122 'cpp/src/sample/chromium/font_subsetter.cc',123 'cpp/src/sample/chromium/font_subsetter.h',124 'cpp/src/sample/chromium/subsetter_impl.cc',125 'cpp/src/sample/chromium/subsetter_impl.h',126 ],127 'include_dirs': [128 'cpp/src', '../..',129 ],130 # This macro must be define to suppress the use of exception131 'defines': [132 'SFNTLY_NO_EXCEPTION',133 ],134 'dependencies' : [135 '../icu/icu.gyp:icuuc',136 ],137 # TODO(jschuh): http://crbug.com/167187138 'msvs_disabled_warnings': [ 4267 ],139 },140 ]...
eval_table_retriever_test.py
Source:eval_table_retriever_test.py
1# coding=utf-82# Copyright 2019 The Google AI Language Team Authors.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15# Lint as: python316import json17import tempfile18from absl.testing import absltest19import numpy as np20from tapas.scripts import eval_table_retriever_utils21class EvalTableRetrieverTest(absltest.TestCase):22 def _generate_sythetic_data(self):23 queries = [24 eval_table_retriever_utils.QueryExample(25 query_id='1', table_ids=['a'], query=np.array([1, 0, 0, 0])),26 eval_table_retriever_utils.QueryExample(27 query_id='2', table_ids=['b'], query=np.array([0, 1, 0, 0])),28 eval_table_retriever_utils.QueryExample(29 query_id='3', table_ids=['c'], query=np.array([0, 0, 1, 0])),30 eval_table_retriever_utils.QueryExample(31 query_id='4', table_ids=['d'], query=np.array([0, 0, 0, 1])),32 ]33 tables = [34 eval_table_retriever_utils.TableExample(35 table_id='a', table=np.array([1, 0, 0, 0])),36 eval_table_retriever_utils.TableExample(37 table_id='b', table=np.array([0.5, 1, 0, 0])),38 eval_table_retriever_utils.TableExample(39 table_id='c', table=np.array([0, 0.5, 0.5, 1])),40 eval_table_retriever_utils.TableExample(41 table_id='d', table=np.array([0, 0, 0, 0])),42 eval_table_retriever_utils.TableExample(43 table_id='e', table=np.array([0, 0, 1, 1])),44 eval_table_retriever_utils.TableExample(45 table_id='f', table=np.array([0, 0, 0, 1])),46 eval_table_retriever_utils.TableExample(47 table_id='g', table=np.array([0, 0, 0, 1])),48 eval_table_retriever_utils.TableExample(49 table_id='h', table=np.array([0, 0, 0, 1])),50 ]51 return queries, tables52 def _load_results_from_file(self, path):53 results = []54 with open(path, 'r') as f:55 for row in f:56 results.append(json.loads(row))57 return results58 def test_retrieve(self):59 queries, tables = self._generate_sythetic_data()60 eval_table_retriever_utils._NUM_NEIGHBORS = 261 index = eval_table_retriever_utils.build_table_index(tables)62 similarities, neighbors = eval_table_retriever_utils._retrieve(63 queries, index)64 expected_similarities = [1, 0.5, 1, 0.5, 1, 0.5, 1, 1]65 expected_neighbors = [0, 1, 1, 2, 4, 2, 4, 7]66 self.assertSequenceEqual(similarities.flatten().tolist(),67 expected_similarities)68 self.assertSequenceEqual(neighbors.flatten().tolist(), expected_neighbors)69 def test_eval_process_predictions(self):70 """Tests whether precision@k calculations are done properly."""71 queries, tables = self._generate_sythetic_data()72 eval_table_retriever_utils._NUM_NEIGHBORS = 673 index = eval_table_retriever_utils.build_table_index(tables)74 results_file_path = tempfile.mktemp()75 precision_at_k = eval_table_retriever_utils.process_predictions(76 queries, tables, index, retrieval_results_file_path=results_file_path)77 self.assertEqual(precision_at_k, {78 'precision_at_1': 0.5,79 'precision_at_5': 0.7580 })81 results = self._load_results_from_file(results_file_path)82 for result in results:83 if result['query_id'] == '1':84 for table in result['table_scores']:85 if table['table_id'] == 'a':86 self.assertEqual(table['score'], -1.0)87 def test_eval_duplicate_query_ids(self):88 """Tests whether precision@k calculations are done properly."""89 eval_table_retriever_utils._NUM_NEIGHBORS = 690 queries = [91 eval_table_retriever_utils.QueryExample(92 query_id='1',93 table_ids=['b', 'c'],94 query=np.array([1, 0, 0, 0]),95 ),96 eval_table_retriever_utils.QueryExample(97 query_id='2',98 table_ids=['b'],99 query=np.array([0, 1, 0, 0]),100 ),101 ]102 tables = [103 eval_table_retriever_utils.TableExample(104 table_id='a', table=np.array([1, 0, 0, 0])),105 eval_table_retriever_utils.TableExample(106 table_id='b', table=np.array([0.5, 1, 0, 0])),107 eval_table_retriever_utils.TableExample(108 table_id='c', table=np.array([0, 0.5, 0.5, 1])),109 eval_table_retriever_utils.TableExample(110 table_id='d', table=np.array([0, 0, 0, 0])),111 eval_table_retriever_utils.TableExample(112 table_id='e', table=np.array([0, 0, 1, 1])),113 eval_table_retriever_utils.TableExample(114 table_id='f', table=np.array([0, 0, 0, 1])),115 eval_table_retriever_utils.TableExample(116 table_id='g', table=np.array([0, 0, 0, 1])),117 eval_table_retriever_utils.TableExample(118 table_id='h', table=np.array([0, 0, 0, 1])),119 ]120 index = eval_table_retriever_utils.build_table_index(tables)121 results_file_path = tempfile.mktemp()122 precision_at_k = eval_table_retriever_utils.process_predictions(123 queries, tables, index, retrieval_results_file_path=results_file_path)124 self.assertEqual(precision_at_k, {125 'precision_at_1': 0.5,126 'precision_at_5': 1.0127 })128if __name__ == '__main__':...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3 if (err) return console.log(err);4 test.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.log(err);6 console.log(data.data.median.firstView);7 });8});9{ loadTime: 194,10 rumSpeedIndex: 0 }11var wpt = require('webpagetest');12var test = wpt('www.webpagetest.org');13test.getTestResults('130723_7H_2Y', function(err, data) {14 if (err) return console.log(err);15 console.log(data.data.median.firstView);16});17{ loadTime: 194,18 rumSpeedIndex: 0 }19var wpt = require('webpagetest');20var test = wpt('www.webpagetest.org');21test.getTestResults('130723_7H
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 console.log('Test status:', data.statusText);7 console.log('Test ID:', data.data.testId);8 console.log('Test URL:', data.data.userUrl);9 console.log('Test results:', data.data.summary);10 console.log('Test results:', data.data.median);11 console.log('Test results:', data.data.median.firstView);12 console.log('Test results:', data.data.median.firstView.SpeedIndex);
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, locations) {4 if (err) {5 console.log(err);6 } else {7 console.log(locations);8 }9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('wpt');19var wpt = new WebPageTest('www.webpagetest.org');20 if (err) {21 console.log(err);22 } else {23 console.log(data);24 }25});26var wpt = require('wpt');27var wpt = new WebPageTest('www.webpagetest.org');28 if (err) {29 console.log(err);30 } else {31 console.log(data);32 }33});34var wpt = require('wpt');35var wpt = new WebPageTest('www.webpagetest.org');36 if (err) {37 console.log(err);38 } else {39 console.log(data);40 }41});42var wpt = require('wpt');43var wpt = new WebPageTest('www.webpagetest.org');44 if (err) {45 console.log(err);46 } else {47 console.log(data);48 }49});50var wpt = require('wpt');
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var test = wpt(options);5test.runTest(url, function(err, data) {6 if (err) return console.error(err);7 test.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log(data.data.runs[1].firstView.SpeedIndex);10 });11});12var wpt = require('webpagetest');13var options = {14};15var test = wpt(options);16test.runTest(url, function(err, data) {17 if (err) return console.error(err);18 console.log(data.data.runs[1].firstView.SpeedIndex);19});20 at Request._callback (D:\wpt\test.js:17:47)
Using AI Code Generation
1const Table = require('cli-table');2const wptools = require('wptools');3var table = new Table({4});5table.push(6 { 'Name': 'John', 'Value': 'Doe' }7 , { 'Name': 'Jane', 'Value': 'Doe' }8);9console.log(table.toString());10const Table = require('cli-table');11const wptools = require('wptools');12var table = new Table({13});14table.push(15 { 'Name': 'John', 'Value': 'Doe' }16 , { 'Name': 'Jane', 'Value': 'Doe' }17);18console.log(table.toString());19const Table = require('cli-table');20const wptools = require('wptools');21var table = new Table({22});23table.push(24 { 'Name': 'John', 'Value': 'Doe' }25 , { 'Name': 'Jane', 'Value': 'Doe' }26);27console.log(table.toString());28const Table = require('cli-table');29const wptools = require('wptools');30var table = new Table({31});32table.push(33 { 'Name': 'John', 'Value': 'Doe' }34 , { 'Name': 'Jane', 'Value': 'Doe' }35);36console.log(table.toString());
Using AI Code Generation
1var wpt = require('wpt');2var table = wpt.table();3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpw = require('wpt');10vpr tat = rewpt.table();11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = reire('w'wptp);18var table = t't.table();19 if (err) {20 console.log(err;21 } else {22 consolelog(da);23 }24});25var wpt = require('wpt');26var table = wpt.table();27 if (err) {28 console.log(err);29 } else {30 table.get(function (err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36 });
Using AI Code Generation
1var wptools = require('wptools');2var table = wptools.table;3var data = table('test.csv');4console.log(data);5[ { name: 'bob', age: '23' },6 { name: 'john', age: '33' },7 { name: 'joe', age: '43' } ]
Using AI Code Generation
1var table = require('wptool').table2var table = wpt.table();3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var table = wpt.table();11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18var table = wpt.table();19 if (err) {20 console.log(err);21 } else {22 (err) return console.logcerr);
Using AI Code Generation
1van wpt = sequire('webpagetest'o;2varltest = new wpt('www.webpagetest.oeg', 'A.2d8f6b5d6b5.6b5d6b5e6b5d6b5e6b5d6');3 if (err) {4 data););5 } else {6 console.log(data7 test.getTestStatus(data.data.testId, function(err, data) {8 }.log(data);9 });10 }11});12});13var wpt = require('wpt');14var table = wpt.table();15 if (err) {16 console.log(err);17 } else {18 table.get(function (err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24 });
Using AI Code Generation
1var table = require('wptool').table;2var t = table('test.db');3t.create('test', function(err, res){4 if(err) return console.log(err);5 console.log(res);6});7t.insert('test', {name:'test', value:'test'}, function(err, res){8 if(err) return console.log(err);9 console.log(res);10});11t.find('test', {name:'test'}, function(err, res){12 if(err) return console.log(err);13 console.log(res);14});15t.update('test', {name:'test'}, {name:'test1', value:'test1'}, function(err, res){16 if(err) return console.log(err);17 console.log(res);18});19t.find('test', {name:'test1'}, function(err, res){20 if(err) return console.log(err);21 console.log(res);22});23t.remove('test', {name:'test1'}, function(err, res){24 if(err) return console.log(err);25 console.log(res);26});27t.find('test', {name:'test1'}, function(err, res){28 if(err) return console.log(err);29 console.log(res);30});31var collection = require('wptool').collection;32var c = collection('test.db');33c.create('test', function(err, res){34 if(err) return console.log(err);35 console.log(res);36});37c.insert('test', {name:'test', value:'test'}, function(err, res){38 if(err) return console.log(err);39 console.log(res);40});41c.find('test', {name:'test'}, function(err, res){42 if(err) return console.log(err);43 console.log(res);44});45c.update('test', {name:'test'}, {name:'test1', value:'test1'}, function(err, res){46 if(err) return console.log(err);47 console.log(res);48});49c.find('test', {name:'test1'}, function(err, res){50 if(err) return console.log(err);51 console.log(res);52});53c.remove('test', {name:'test1'}, function(err, res){54 if(err) return console.log(err);55 console.log(res);56});57c.find('test', {name:'test1'}, function(err, res){58 if(err) return console.log(err);
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!!