How to use _format_row method in autotest

Best Python code snippet using autotest_python

statdb.py

Source:statdb.py Github

copy

Full Screen

...927 return True, msg928 msg = self.formatcomp(milestone1, milestone2)929 return True, msg930 @staticmethod931 def _format_row(rowname, data1, data2, datacolor="@W",932 headercolor="@C"):933 """934 format a row of data935 """936 lstr = '%s%-14s : %s%-12s %s%-12s' % (headercolor, rowname,937 datacolor, data1,938 datacolor, data2)939 return lstr940 def show_quest(self, args):941 """942 show info for a specific quest in the database943 """944 msg = []945 tid = args['number']946 questinfo = self.api('%s.getrow' % self.sname)(tid, 'quests')947 if questinfo:948 questinfo = questinfo[0]949 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')950 div = '@B' + '-' * linelen951 msg.append("@G%-6s %-2s %-2s %-2s %-2s %-3s" \952 " %-2s %-2s %-2s %-2s %-4s %-3s %s" % \953 ("ID", "QP", "MC", "TR", "LK",954 "DBL", "TL", "TP", "TN",955 "PR", "Gold", "Lvl", "Time"))956 msg.append(div)957 dbl = ''958 if int(questinfo['double']) == 1:959 dbl = dbl + 'D'960 if int(questinfo['daily']) == 1:961 dbl = dbl + 'E'962 leveld = self.api('aardu.convertlevel')(questinfo['level'])963 ttime = self.api('utils.formattime')(questinfo['finishtime'] - \964 questinfo['starttime'])965 if int(questinfo['failed']) == 1:966 ttime = 'Failed'967 msg.append("%-6s %2s %2s %2s %2s %3s" \968 " %2s %2s %2s %2s %4s %3s %8s" % \969 (questinfo['quest_id'], questinfo['qp'],970 questinfo['mccp'], questinfo['tierqp'], questinfo['lucky'],971 dbl, questinfo['totqp'], questinfo['tp'],972 questinfo['trains'], questinfo['pracs'], questinfo['gold'],973 leveld['level'], ttime))974 msg.append(div)975 msg.append('%-25s %-25s %-20s' % (questinfo['mobname'],976 questinfo['mobroom'],977 questinfo['mobarea']))978 msg.append(div)979 return True, msg980 def cmd_quests(self, args=None): # pylint: disable=too-many-statements981 """982 show quest stats983 """984 if self.statdb.getlastrowid('stats') <= 0:985 return True, ['No stats available']986 if self.statdb.getlastrowid('quests') <= 0:987 return True, ['No quests stats are available']988 count = 0989 if args:990 if args['number']:991 return self.show_quest(args)992 else:993 count = args['count']994 msg = []995 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')996 div = '@B' + '-' * linelen997 tqrow = self.statdb.select(998 """SELECT AVG(finishtime - starttime) as avetime,999 SUM(qp) as qp,1000 AVG(qp) as qpquestave,1001 AVG(tierqp) as tierqpave,1002 SUM(tierqp) as tierqp,1003 AVG(mccp) as mccpave,1004 SUM(mccp) as mccp,1005 AVG(lucky) as luckyave,1006 SUM(lucky) as lucky,1007 AVG(opk) as opkave,1008 SUM(opk) as opk,1009 AVG(hardcore) as hardcoreave,1010 SUM(hardcore) as hardcore,1011 SUM(tp) as tp,1012 AVG(tp) as tpave,1013 SUM(trains) as trains,1014 AVG(trains) as trainsave,1015 SUM(pracs) as pracs,1016 AVG(pracs) as pracsave,1017 COUNT(*) as qindb,1018 SUM(totqp) as dboverall,1019 AVG(totqp) as dboverallave,1020 SUM(gold) as gold,1021 AVG(gold) as avegold FROM quests where failed = 0""")1022 stats = tqrow[0]1023 tfrow = self.statdb.select(1024 "SELECT COUNT(*) as failedindb FROM quests where failed != 0")1025 stats.update(tfrow[0])1026 tsrow = self.statdb.select(1027 """SELECT qpearned, questscomplete, questsfailed,1028 totallevels FROM stats WHERE milestone = 'current'""")1029 stats.update(tsrow[0])1030 stats['indb'] = stats['failedindb'] + stats['qindb']1031 stats['qplevelave'] = stats['qpearned']/float(stats['totallevels'])1032 msg.append(self._format_row('DB Stats', 'Total', 'In DB', '@G', '@G'))1033 msg.append(div)1034 msg.append(self._format_row("Quests",1035 stats['questscomplete'] + stats['questsfailed'],1036 stats['indb']))1037 msg.append(self._format_row("Quests Comp",1038 stats['questscomplete'], stats['qindb']))1039 msg.append(self._format_row("Quests Failed",1040 stats['questsfailed'], stats['failedindb']))1041 msg.append('')1042 msg.append(self._format_row("QP Stats", "Total", "Average", '@G', '@G'))1043 msg.append(div)1044 msg.append(self._format_row("Overall QP", stats['qpearned'],1045 format_float(stats['qplevelave'], "/level")))1046 msg.append(self._format_row("Quest QP", stats['qp'],1047 format_float(stats['qpquestave'], "/quest")))1048 msg.append(self._format_row("MCCP", stats['mccp'],1049 format_float(stats['mccpave'], "/quest")))1050 msg.append(self._format_row("Lucky", stats['lucky'],1051 format_float(stats['luckyave'], "/quest")))1052 msg.append(self._format_row("Tier", stats['tierqp'],1053 format_float(stats['tierqpave'], "/quest")))1054 msg.append(self._format_row("OPK", stats['opk'],1055 format_float(stats['opkave'], "/quest")))1056 msg.append(self._format_row("Hardcore", stats['hardcore'],1057 format_float(stats['hardcoreave'], "/quest")))1058 msg.append(self._format_row("QP Per Quest", "",1059 format_float(stats['dboverallave'], "/quest")))1060 msg.append(self._format_row("Gold",1061 self.api('utils.readablenumber')(stats['gold'], 2),1062 "%d/quest" % stats['avegold']))1063 msg.append(self._format_row("Time", "",1064 self.api('utils.formattime')(stats['avetime'])))1065 msg.append('')1066 msg.append(self._format_row("Bonus Rewards", "Total",1067 "Average", '@G', '@G'))1068 msg.append(div)1069 msg.append(self._format_row("TP", stats['tp'],1070 format_float(stats['tpave'], "/quest")))1071 msg.append(self._format_row("Trains", stats['trains'],1072 format_float(stats['trainsave'], "/quest")))1073 msg.append(self._format_row("Pracs", stats['pracs'],1074 format_float(stats['pracsave'], "/quest")))1075 if int(count) > 0:1076 lastitems = self.statdb.getlast('quests', int(count))1077 if len(lastitems) > 0: # pylint: disable=len-as-condition1078 msg.append('')1079 msg.append("@G%-6s %-2s %-2s %-2s %-2s %-2s %-2s %-3s" \1080 " %-2s %-2s %-2s %-2s %-4s %-3s %s" % \1081 ("ID", "QP", "MC", "TR", "LK",1082 "PK", "HC", "DBL", "TL", "TP", "TN",1083 "PR", "Gold", "Lvl", "Time"))1084 msg.append(div)1085 for item in lastitems:1086 dbl = ''1087 if int(item['double']) == 1:1088 dbl = dbl + 'D'1089 if int(item['daily']) == 1:1090 dbl = dbl + 'E'1091 leveld = self.api('aardu.convertlevel')(item['level'])1092 ttime = self.api('utils.formattime')(item['finishtime'] - \1093 item['starttime'])1094 if int(item['failed']) == 1:1095 ttime = 'Failed'1096 msg.append("%-6s %2s %2s %2s %2s %2s %2s %3s" \1097 " %2s %2s %2s %2s %4s %3s %8s" % \1098 (item['quest_id'], item['qp'],1099 item['mccp'], item['tierqp'], item['lucky'], item['opk'],1100 item['hardcore'], dbl, item['totqp'], item['tp'],1101 item['trains'], item['pracs'], item['gold'],1102 leveld['level'], ttime))1103 return True, msg1104 def show_level(self, args): # pylint: disable=too-many-locals,too-many-statements,too-many-branches1105 """1106 show info for a specific level in the database1107 """1108 msg = []1109 tid = args['number']1110 levelinfo = self.api('%s.getrow' % self.sname)(tid, 'levels')1111 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')1112 div = '@B' + '-' * linelen1113 if levelinfo:1114 levelinfo = levelinfo[0]1115 bonus = 01116 if int(levelinfo['bonustrains']) > 0:1117 bonus = bonus + int(levelinfo['bonustrains'])1118 if int(levelinfo['blessingtrains']) > 0:1119 bonus = bonus + int(levelinfo['blessingtrains'])1120 if int(levelinfo['battlelearntrains'] > 0):1121 bonus = bonus + int(levelinfo['battlelearntrains'])1122 leveld = self.api('aardu.convertlevel')(levelinfo['level'])1123 levels = 're%st%sr%sl%s' % (leveld['redos'], leveld['tier'],1124 leveld['remort'], leveld['level'])1125 if levelinfo['finishtime'] != '-1' and levelinfo['starttime'] != '-1':1126 ttime = self.api('utils.formattime')(levelinfo['finishtime'] - \1127 levelinfo['starttime'])1128 else:1129 ttime = ''1130 if levelinfo['type'] == 'level':1131 ltype = 'lev'1132 else:1133 ltype = 'pup'1134 msg.append("@G%-6s %-5s %-7s %-s" % ("ID", "Type", "TotLvl", "Actual"))1135 msg.append("%-6s %-5s %-7s %-s" % (levelinfo['level_id'], ltype, levelinfo['level'],1136 levels))1137 msg.append("@G%-6s %2s %2s %-2s %-2s " % ("", "HP", "MN", "MV", "PR"))1138 msg.append("%-6s %2s %2s %-2s %-2s" % ("", levelinfo['hp'], levelinfo['mp'],1139 levelinfo['mv'], levelinfo['pracs']))1140 msg.append("@G%-6s %-2s %-2s %-2s %-2s" % ("", "TR", "BO", "BL", "BT"))1141 msg.append("%-6s %-2s %-2s %-2s %-2s" % ("", levelinfo['trains'],1142 levelinfo['bonustrains'],1143 levelinfo['blessingtrains'],1144 levelinfo['battlelearntrains']))1145 msg.append("@G%-6s %-1s %-1s %-1s %-1s %-1s %-1s" % \1146 ("", "S", "I", "W", "C", "D", "L"))1147 msg.append("%-6s %-1s %-1s %-1s %-1s %-1s %-1s" % \1148 ("", levelinfo['str'], levelinfo['int'],1149 levelinfo['wis'], levelinfo['con'], levelinfo['dex'],1150 levelinfo['luc']))1151 stmt = "SELECT count(*) as count, AVG(totalxp) as average FROM " \1152 "mobkills where time > %d and time < %d and xp > 0" % \1153 (levelinfo['starttime'], levelinfo['finishtime'])1154 tst = self.api('statdb.select')(stmt)1155 count = tst[0]['count']1156 ave = tst[0]['average']1157 if levelinfo['starttime'] or levelinfo['finishtime']:1158 msg.append(div)1159 if levelinfo['starttime']:1160 msg.append('Started : %s' % time.strftime(1161 "%a, %d %b %Y %H:%M:%S +0000",1162 time.localtime(levelinfo['starttime'])))1163 if levelinfo['finishtime']:1164 if levelinfo['finishtime'] == -1:1165 fstr = 'Current'1166 else:1167 fstr = time.strftime("%a, %d %b %Y %H:%M:%S +0000",1168 time.localtime(levelinfo['finishtime']))1169 msg.append('Finished : %s' % fstr)1170 if count > 0 and ave > 0:1171 msg.append(div)1172 length = levelinfo['finishtime'] - levelinfo['starttime']1173 if ttime:1174 tmsg = "It took %s with " % ttime1175 else:1176 tmsg = ""1177 tmsg = tmsg + '@G%s@w mobs killed' % count1178 tmsg = tmsg + ' (@G%02.02f@w xp/mob)' % (ave)1179 perlevel = self.api('GMCP.getv')('char.base.perlevel')1180 if length and perlevel:1181 expmin = self.api('GMCP.getv')('char.base.perlevel')/(length/60)1182 tmsg = tmsg + ' @G%02d@w xp/min' % (expmin)1183 msg.append(tmsg)1184 msg.append(div)1185 return True, msg1186 def cmd_levels(self, args=None): # pylint: disable=too-many-locals,too-many-branches,too-many-statements1187 """1188 show level stats1189 """1190 if self.statdb.getlastrowid('stats') <= 0:1191 return True, ['No stats available']1192 if self.statdb.getlastrowid('levels') <= 0:1193 return True, ['No levels/pups stats available']1194 count = 01195 if args:1196 if args['number']:1197 return self.show_level(args)1198 else:1199 count = args['count']1200 msg = []1201 pups = {}1202 levels = {}1203 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')1204 div = '@B' + '-' * linelen1205 lrow = self.statdb.select(1206 "SELECT totallevels, qpearned FROM stats WHERE milestone = 'current'")1207 levels.update(lrow[0])1208 prow = self.statdb.select(1209 "SELECT MAX(powerupsall) as powerupsall FROM stats")1210 pups.update(prow[0])1211 levels['qpave'] = int(levels['qpearned']) / int(levels['totallevels'])1212 llrow = self.statdb.select("""1213 SELECT AVG(trains) as avetrains,1214 AVG(bonustrains) as avebonustrains,1215 AVG(blessingtrains) as aveblessingtrains,1216 AVG(battlelearntrains) as avebattlelearntrains,1217 SUM(trains + bonustrains + blessingtrains + battlelearntrains) as totaltrains,1218 SUM(pracs) as totalpracs,1219 COUNT(*) as indb1220 FROM levels where type = 'level' and trains > 01221 """)1222 levels.update(llrow[0])1223 ltrow = self.statdb.select("""1224 SELECT AVG(finishtime - starttime) as avetime FROM levels1225 where type = 'level' and finishtime <> -1 and trains > 01226 """)1227 levels.update(ltrow[0])1228 pprow = self.statdb.select("""1229 SELECT AVG(trains) as avetrains,1230 AVG(bonustrains) as avebonustrains,1231 AVG(blessingtrains) as aveblessingtrains,1232 AVG(battlelearntrains) as avebattlelearntrains,1233 SUM(trains + bonustrains + blessingtrains + battlelearntrains) as totaltrains,1234 COUNT(*) as indb1235 FROM levels where type = 'pup'1236 """)1237 pups.update(pprow[0])1238 ptrow = self.statdb.select("""1239 SELECT AVG(finishtime - starttime) as avetime FROM levels1240 where type = 'pup' and finishtime <> -11241 """)1242 pups.update(ptrow[0])1243 msg.append(self._format_row('Type', 'Levels', 'Pups', '@G', '@G'))1244 msg.append(div)1245 msg.append(self._format_row("Total Overall",1246 levels['totallevels'], pups['powerupsall']))1247 msg.append(self._format_row("Total In DB",1248 levels['indb'], pups['indb']))1249 msg.append(self._format_row("Total Trains",1250 levels['totaltrains'] or 0, pups['totaltrains'] or 0))1251 trainitems = [1252 ['Ave Trains', 'avetrains'],1253 ['Ave Bon Trains', 'avebonustrains'],1254 ['Ave Bls Trains', 'aveblessingtrains'],1255 ['Ave BaL Trains', 'avebattlelearntrains'],1256 ]1257 levelave = float(0)1258 pupave = float(0)1259 for i in trainitems:1260 title = i[0]1261 lkey = i[1]1262 lave = format_float(levels[lkey])1263 pave = format_float(pups[lkey])1264 levelave = float(levelave) + float(lave)1265 pupave = float(pupave) + float(pave)1266 msg.append(self._format_row(title,1267 lave or 0, pave or 0))1268 msg.append(self._format_row("Ave Overall",1269 levelave or 0, pupave or 0))1270 msg.append(self._format_row("Total Pracs",1271 levels['totalpracs'], ""))1272 if levels['avetime']:1273 lavetime = self.api('utils.formattime')(levels['avetime'])1274 else:1275 lavetime = ""1276 if pups['avetime']:1277 pavetime = self.api('utils.formattime')(pups['avetime'])1278 else:1279 pavetime = ""1280 msg.append(self._format_row("Time", lavetime, pavetime))1281 if int(count) > 0:1282 lastitems = self.statdb.getlast('levels', int(count))1283 if len(lastitems) > 0: # pylint: disable=len-as-condition1284 msg.append('')1285 msg.append("@G%-6s %-3s %2s %2s %2s %-2s %-2s %-2s" \1286 " %-2s %-1s %-1s %-1s %-1s %-1s %-1s %s" % \1287 ("ID", "Lvl", "T",1288 "TR", "BT", "PR", "HP", "MN", "MV", "S",1289 "I", "W", "C", "D", "L", "Time"))1290 msg.append(div)1291 for item in lastitems:1292 bonus = 01293 if int(item['bonustrains']) > 0:1294 bonus = bonus + int(item['bonustrains'])1295 if int(item['blessingtrains']) > 0:1296 bonus = bonus + int(item['blessingtrains'])1297 leveld = self.api('aardu.convertlevel')(item['level'])1298 if item['finishtime'] != '-1' and item['starttime'] != '-1':1299 ttime = self.api('utils.formattime')(item['finishtime'] - \1300 item['starttime'])1301 else:1302 ttime = ''1303 if item['type'] == 'level':1304 ltype = 'L'1305 else:1306 ltype = 'P'1307 msg.append("%-6s %-3s %2s %2s %2s %-2s %-2s %-2s" \1308 " %-2s %-1s %-1s %-1s %-1s %-1s %-1s %s" % \1309 (item['level_id'], leveld['level'], ltype, item['trains'],1310 bonus, item['pracs'], item['hp'], item['mp'],1311 item['mv'], item['str'], item['int'], item['wis'],1312 item['con'], item['dex'], item['luc'], ttime))1313 return True, msg1314 def show_cp(self, args):1315 """1316 show info for a specific cp in the database1317 """1318 msg = []1319 tid = args['number']1320 cpinfo = self.api('%s.getrow' % self.sname)(tid, 'campaigns')1321 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')1322 div = '@B' + '-' * linelen1323 if cpinfo:1324 cpinfo = cpinfo[0]1325 mobs = self.api('%s.select' % self.sname)(1326 "SELECT * FROM cpmobs WHERE cp_id = %s" % tid)1327 msg.append("@G%-6s %-12s %-2s %-2s %-2s %-2s %-2s %6s %-4s %s" % \1328 ("ID", "Lvl", "QP", "BN",1329 "TP", "TN", "PR", "Gold", "Mobs", "Time"))1330 msg.append(div)1331 leveld = self.api('aardu.convertlevel')(cpinfo['level'])1332 levelstr = 'T%d R%d L%d' % (leveld['tier'], leveld['remort'],1333 leveld['level'])1334 if cpinfo['finishtime'] != '-1' and cpinfo['starttime'] != '-1':1335 ttime = self.api('utils.formattime')(cpinfo['finishtime'] - \1336 cpinfo['starttime'])1337 else:1338 ttime = ''1339 if int(cpinfo['failed']) == 1:1340 ttime = 'Failed'1341 msg.append("%-6s %-12s %-2s %2s %2s %2s %2s %6s %-3s %s" % \1342 (cpinfo['cp_id'], levelstr, cpinfo['qp'], cpinfo['bonusqp'],1343 cpinfo['tp'], cpinfo['trains'], cpinfo['pracs'], cpinfo['gold'],1344 len(mobs), ttime))1345 msg.append(div)1346 msg.append("@G%-30s %-30s" % ("Name", "Location"))1347 msg.append(div)1348 for i in mobs:1349 msg.append("@G%-30s %-30s" % (i['name'],1350 i['location']))1351 msg.append(div)1352 return True, msg1353 def cmd_cps(self, args=None): # pylint: disable=too-many-locals,too-many-branches,too-many-statements1354 """1355 show cp stats1356 """1357 if self.statdb.getlastrowid('stats') <= 0:1358 return True, ['No stats available']1359 if self.statdb.getlastrowid('campaigns') <= 0:1360 return True, ['No campaign stats available']1361 count = 01362 if args:1363 if args['number']:1364 return self.show_cp(args)1365 else:1366 count = args['count']1367 msg = []1368 stats = {}1369 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')1370 div = '@B' + '-' * linelen1371 trow = self.statdb.select(1372 "SELECT campaignsdone, campaignsfld, totallevels " \1373 "FROM stats WHERE milestone = 'current'")1374 stats.update(trow[0])1375 trow = self.statdb.select(1376 """SELECT AVG(finishtime - starttime) as avetime,1377 SUM(qp) as totalqp,1378 AVG(qp) as aveqp,1379 SUM(tp) as totaltp,1380 AVG(tp) as avetp,1381 SUM(trains) as totaltrains,1382 AVG(trains) as avetrains,1383 SUM(pracs) as totalpracs,1384 AVG(pracs) as avepracs,1385 COUNT(*) as cindb,1386 SUM(gold) as totalgold,1387 AVG(gold) as avegold1388 FROM campaigns where failed = 0""")1389 stats.update(trow[0])1390 trow = self.statdb.select(1391 "SELECT COUNT(*) as failedindb FROM campaigns where failed != 0")1392 stats.update(trow[0])1393 stats['indb'] = int(stats['cindb']) + int(stats['failedindb'])1394 stats['totalcps'] = int(stats['campaignsdone']) + \1395 int(stats['campaignsfld'])1396 msg.append(self._format_row('DB Stats', 'Total', 'In DB', '@G', '@G'))1397 msg.append(div)1398 msg.append(self._format_row("Overall",1399 stats['totalcps'], stats['indb'] or 0))1400 msg.append(self._format_row("Completed",1401 stats['campaignsdone'], stats['cindb'] or 0))1402 msg.append(self._format_row("Failed",1403 stats['campaignsfld'], stats['failedindb'] or 0))1404 msg.append('')1405 msg.append(self._format_row('CP Stats', 'Total', 'Average', '@G', '@G'))1406 msg.append(div)1407 msg.append(self._format_row("QP",1408 stats['totalqp'] or 0,1409 format_float(stats['aveqp'], "/CP")))1410 if stats['totalgold']:1411 tempg = self.api('utils.readablenumber')(stats['totalgold'])1412 else:1413 tempg = 01414 msg.append(self._format_row("Gold",1415 tempg,1416 "%d/CP" % stats['avegold']))1417 if stats['avetime']:1418 atime = self.api('utils.formattime')(stats['avetime'])1419 else:1420 atime = ""1421 msg.append(self._format_row("Time", "", atime))1422 msg.append('')1423 msg.append(self._format_row("Bonus Rewards", "Total",1424 "Average", '@G', '@G'))1425 msg.append(div)1426 msg.append(self._format_row("TP",1427 stats['totaltp'] or 0,1428 format_float(stats['avetp'], "/CP")))1429 msg.append(self._format_row("Trains",1430 stats['totaltrains'] or 0,1431 format_float(stats['avetrains'], "/CP")))1432 msg.append(self._format_row("Pracs",1433 stats['totalpracs'] or 0,1434 format_float(stats['avepracs'], "/CP")))1435 if int(count) > 0:1436 lastitems = self.statdb.getlast('campaigns', int(count))1437 mobc = self.statdb.selectbykeyword(1438 'SELECT cp_id, count(*) as mobcount from cpmobs group by cp_id',1439 'cp_id')1440 if len(lastitems) > 0: # pylint: disable=len-as-condition1441 msg.append('')1442 msg.append("@G%-6s %-12s %-2s %-2s %-2s %-2s %-2s %6s %-4s %s" % \1443 ("ID", "Lvl", "QP", "BN", "TP", "TN",1444 "PR", "Gold", "Mobs", "Time"))1445 msg.append(div)1446 for item in lastitems:1447 leveld = self.api('aardu.convertlevel')(item['level'])1448 levelstr = 'T%d R%d L%d' % (leveld['tier'], leveld['remort'],1449 leveld['level'])1450 if item['finishtime'] != '-1' and item['starttime'] != '-1':1451 ttime = self.api('utils.formattime')(item['finishtime'] - \1452 item['starttime'])1453 else:1454 ttime = ''1455 if int(item['failed']) == 1:1456 ttime = 'Failed'1457 msg.append("%-6s %-12s %-2s %2s %2s %2s %2s %6s %-3s %s" % \1458 (item['cp_id'], levelstr, item['qp'], item['bonusqp'],1459 item['tp'], item['trains'], item['pracs'], item['gold'],1460 mobc[item['cp_id']]['mobcount'], ttime))1461 return True, msg1462 def show_gq(self, args):1463 """1464 show info for a specific gq in the database1465 """1466 msg = []1467 tid = args['number']1468 gqinfo = self.api('%s.getrow' % self.sname)(tid, 'gquests')1469 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')1470 div = '@B' + '-' * linelen1471 if gqinfo:1472 gqinfo = gqinfo[0]1473 mobs = self.api('%s.select' % self.sname)(1474 "SELECT * FROM gqmobs WHERE gq_id = %s" % tid)1475 msg.append("@G%-6s %-12s %-2s %-2s %-2s %-2s %-2s %6s %-4s %s" % \1476 ("ID", "Lvl", "QP", "QM", "TP",1477 "TN", "PR", "Gold", "Mobs", "Time"))1478 msg.append(div)1479 leveld = self.api('aardu.convertlevel')(gqinfo['level'])1480 levelstr = 'T%d R%d L%d' % (leveld['tier'], leveld['remort'],1481 leveld['level'])1482 if gqinfo['finishtime'] != '-1' and gqinfo['starttime'] != '-1':1483 ttime = self.api('utils.formattime')(gqinfo['finishtime'] - \1484 gqinfo['starttime'])1485 else:1486 ttime = ''1487 msg.append("%-6s %-12s %2s %2s %2s %2s %2s %6s %-3s %s" % \1488 (gqinfo['gq_id'], levelstr, gqinfo['qp'], gqinfo['qpmobs'],1489 gqinfo['tp'], gqinfo['trains'], gqinfo['pracs'],1490 gqinfo['gold'], len(mobs), ttime))1491 msg.append(div)1492 msg.append("@G%-5s %-30s %-30s" % ("Num", "Name", "Location"))1493 msg.append(div)1494 for i in mobs:1495 msg.append("@G%-5s %-30s %-30s" % (i['num'], i['name'],1496 i['location']))1497 msg.append(div)1498 return True, msg1499 def cmd_gqs(self, args=None): # pylint: disable=too-many-locals,too-many-statements1500 """1501 show gq stats1502 """1503 if self.statdb.getlastrowid('stats') <= 0:1504 return True, ['No stats available']1505 if self.statdb.getlastrowid('gquests') <= 0:1506 return True, ['No gq stats available']1507 count = 01508 if args:1509 if args['number']:1510 return self.show_gq(args)1511 else:1512 count = args['count']1513 msg = []1514 stats = {}1515 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')1516 div = '@B' + '-' * linelen1517 wrow = self.statdb.select(1518 """SELECT AVG(finishtime - starttime) as avetime,1519 SUM(qp) as qp,1520 AVG(qp) as qpave,1521 SUM(qpmobs) as qpmobs,1522 AVG(qpmobs) as qpmobsave,1523 SUM(tp) as tp,1524 AVG(tp) as tpave,1525 SUM(trains) as trains,1526 AVG(trains) as trainsave,1527 SUM(pracs) as pracs,1528 AVG(pracs) as pracsave,1529 COUNT(*) as indb,1530 SUM(gold) as gold,1531 AVG(gold) as avegold1532 FROM gquests where won = 1""")1533 stats['won'] = wrow[0]1534 trow = self.statdb.select(1535 "SELECT gquestswon FROM stats WHERE milestone = 'current'")1536 stats.update(trow[0])1537 trow = self.statdb.select(1538 """SELECT AVG(finishtime - starttime) as avetime,1539 SUM(qpmobs) as totalqp,1540 AVG(qpmobs) as aveqp,1541 COUNT(*) as indb1542 FROM gquests where won != 1""")1543 stats['lost'] = trow[0]1544 trow = self.statdb.select(1545 """SELECT SUM(qpmobs + qp) as overallqp,1546 AVG(qpmobs + qp) as aveoverallqp1547 FROM gquests""")1548 stats.update(trow[0])1549 stats['indb'] = stats['won']['indb'] + stats['lost']['indb']1550 stats['overall'] = stats['gquestswon'] + stats['lost']['indb']1551 msg.append(self._format_row('GQ Stats', 'Total', 'In DB', '@G', '@G'))1552 msg.append(div)1553 msg.append(self._format_row("Won",1554 stats['gquestswon'], stats['won']['indb'] or 0))1555 msg.append(self._format_row("Lost",1556 "", stats['lost']['indb'] or 0))1557 msg.append(self._format_row("Overall",1558 stats['overall'], stats['indb'] or 0))1559 msg.append(self._format_row("QP",1560 stats['overallqp'],1561 format_float(stats['aveoverallqp'], "/GQ")))1562 msg.append('')1563 msg.append(self._format_row('GQ Won Stats', 'Total', 'Average',1564 '@G', '@G'))1565 msg.append(div)1566 msg.append(self._format_row("GQ QP",1567 stats['won']['qp'],1568 format_float(stats['won']['qpave'], "/GQ")))1569 msg.append(self._format_row("GQ MOB QP",1570 stats['won']['qpmobs'],1571 format_float(stats['won']['qpmobsave'], "/GQ")))1572 if stats['won']['avetime']:1573 atime = self.api('utils.formattime')(stats['won']['avetime'])1574 else:1575 atime = ""1576 msg.append(self._format_row("Time", "", atime))1577 msg.append(self._format_row("Gold",1578 self.api('utils.readablenumber')(stats['won']['gold']),1579 "%d/GQ" % stats['won']['avegold']))1580 msg.append(self._format_row("TP",1581 stats['won']['tp'],1582 format_float(stats['won']['tpave'], "/GQ")))1583 msg.append(self._format_row("Trains",1584 stats['won']['trains'],1585 format_float(stats['won']['trainsave'], "/GQ")))1586 msg.append(self._format_row("Pracs",1587 stats['won']['pracs'],1588 format_float(stats['won']['pracsave'], "/GQ")))1589 msg.append('')1590 msg.append(self._format_row('GQ Lost Stats', 'Total', 'Average',1591 '@G', '@G'))1592 msg.append(div)1593 msg.append(self._format_row("GQ MOB QP",1594 stats['lost']['totalqp'],1595 format_float(stats['lost']['aveqp'], "/GQ")))1596 if int(count) > 0:1597 lastitems = self.statdb.getlast('gquests', int(count))1598 mobc = self.statdb.selectbykeyword(1599 'SELECT gq_id, SUM(num) as mobcount from gqmobs group by gq_id',1600 'gq_id')1601 if len(lastitems) > 0: # pylint: disable=len-as-condition1602 msg.append('')1603 msg.append("@G%-6s %-12s %-2s %-2s %-2s %-2s %-2s %6s %-4s %s" % \1604 ("ID", "Lvl", "QP", "QM", "TP",1605 "TN", "PR", "Gold", "Mobs", "Time"))1606 msg.append(div)1607 for item in lastitems:1608 leveld = self.api('aardu.convertlevel')(item['level'])1609 levelstr = 'T%d R%d L%d' % (leveld['tier'], leveld['remort'],1610 leveld['level'])1611 if item['finishtime'] != '-1' and item['starttime'] != '-1':1612 ttime = self.api('utils.formattime')(item['finishtime'] - \1613 item['starttime'])1614 else:1615 ttime = ''1616 msg.append("%-6s %-12s %2s %2s %2s %2s %2s %6s %-3s %s" % \1617 (item['gq_id'], levelstr, item['qp'], item['qpmobs'],1618 item['tp'], item['trains'], item['pracs'], item['gold'],1619 mobc[item['gq_id']]['mobcount'], ttime))1620 return True, msg1621 def cmd_mobs(self, args=None): # pylint: disable=too-many-locals,too-many-branches,too-many-statements1622 """1623 show mobs stats1624 """1625 if self.statdb.getlastrowid('stats') <= 0:1626 return True, ['No stats available']1627 if self.statdb.getlastrowid('mobkills') <= 0:1628 return True, ['No mob stats available']1629 count = 01630 if args:1631 count = args['count']1632 msg = []1633 stats = {}1634 linelen = self.api('plugins.getp')('proxy').api('setting.gets')('linelen')1635 div = '@B' + '-' * linelen1636 trow = self.statdb.select(1637 "SELECT monsterskilled FROM stats WHERE milestone = 'current'")1638 stats.update(trow[0])1639 trow = self.statdb.select(1640 """SELECT SUM(xp) AS xp,1641 SUM(rarexp) as rarexp,1642 SUM(bonusxp) AS bonusxp,1643 SUM(blessingxp) AS blessingxp,1644 SUM(totalxp) as totalxp,1645 AVG(xp) AS avexp,1646 AVG(totalxp) AS avetotalxp,1647 SUM(tp) AS tp,1648 SUM(vorpal) AS vorpal,1649 SUM(assassinate) AS assassinate,1650 SUM(disintegrate) AS disintegrate,1651 SUM(banishment) AS banishment,1652 SUM(slit) AS slit,1653 SUM(deathblow) AS deathblow,1654 SUM(gold) AS gold,1655 AVG(gold) AS avegold,1656 COUNT(*) AS indb1657 FROM mobkills""")1658 stats.update(trow[0])1659 trow = self.statdb.select(1660 """SELECT AVG(bonusxp) as avebonusxp,1661 COUNT(*) as bonusmobsindb1662 FROM mobkills where bonusxp > 0""")1663 stats.update(trow[0])1664 trow = self.statdb.select(1665 """SELECT AVG(blessingxp) as aveblessxp,1666 COUNT(*) as blessmobsindb1667 FROM mobkills where blessingxp > 0""")1668 stats.update(trow[0])1669 trow = self.statdb.select(1670 """SELECT AVG(rarexp) as averarexp,1671 COUNT(*) as raremobsindb1672 FROM mobkills where rarexp > 0""")1673 stats.update(trow[0])1674 msg.append(self._format_row('DB Stats', 'Total', 'In DB', '@G', '@G'))1675 msg.append(div)1676 msg.append(self._format_row("Overall",1677 stats['monsterskilled'], stats['indb'] or 0))1678 msg.append(self._format_row("Rare Mobs",1679 "", stats['raremobsindb'] or 0))1680 msg.append(self._format_row("Bonus Mobs",1681 "", stats['bonusmobsindb'] or 0))1682 msg.append(self._format_row("Blessing Mobs",1683 "", stats['blessmobsindb'] or 0))1684 msg.append('')1685 msg.append(self._format_row('Stats', 'Total', 'Average', '@G', '@G'))1686 msg.append(div)1687 msg.append(self._format_row("XP",1688 stats['xp'],1689 format_float(stats['avexp'], "/kill")))1690 msg.append(self._format_row("Rare XP",1691 stats['rarexp'],1692 format_float(stats['averarexp'], "/kill")))1693 msg.append(self._format_row("Double XP",1694 stats['bonusxp'],1695 format_float(stats['avebonusxp'], "/kill")))1696 msg.append(self._format_row("Blessing XP",1697 stats['blessingxp'],1698 format_float(stats['aveblessxp'], "/kill")))1699 msg.append(self._format_row("Total XP",1700 stats['totalxp'],1701 format_float(stats['avetotalxp'], "/kill")))1702 msg.append(self._format_row("Gold",1703 self.api('utils.readablenumber')(stats['gold']),1704 "%d/kill" % stats['avegold']))1705 msg.append(self._format_row("TP",1706 stats['tp'],1707 format_float(stats['tp'] / float(stats['indb']),1708 "/kill")))1709 avetype = stats['vorpal'] / float(stats['indb'])1710 msg.append(self._format_row("Vorpal",1711 stats['vorpal'],1712 format_float(avetype, "/kill") or ""))1713 avetype = stats['assassinate'] / float(stats['indb'])1714 msg.append(self._format_row("Assassinate",1715 stats['assassinate'],1716 format_float(avetype, "/kill") or ""))1717 avetype = stats['slit'] / float(stats['indb'])1718 msg.append(self._format_row("Slit",1719 stats['slit'],1720 format_float(avetype, "/kill") or ""))1721 avetype = stats['banishment'] / float(stats['indb'])1722 msg.append(self._format_row("Banishment",1723 stats['banishment'],1724 format_float(avetype, "/kill") or ""))1725 avetype = stats['deathblow'] / float(stats['indb'])1726 msg.append(self._format_row("Deathblow",1727 stats['deathblow'],1728 format_float(avetype, "/kill") or ""))1729 avetype = stats['disintegrate'] / float(stats['indb'])1730 msg.append(self._format_row("Disintegrate",1731 stats['disintegrate'],1732 format_float(avetype, "/kill") or ""))1733 if int(count) > 0:1734 lastitems = self.statdb.getlast('mobkills', int(count))1735 if lastitems:1736 msg.append('')1737 msg.append("@G%3s %-18s %-3s %-3s %-3s %-3s %2s %1s %s" % \1738 ("Lvl", "Mob", "TXP", "XP", "RXP",1739 "OXP", "TP", "S", "Gold"))1740 msg.append(div)1741 for item in lastitems:1742 leveld = self.api('aardu.convertlevel')(item['level'])1743 levelstr = leveld['level']1744 bonus = ''...

Full Screen

Full Screen

_cursor_formatters.py

Source:_cursor_formatters.py Github

copy

Full Screen

...74 yield self._format_dump(b)75 else:76 row = self.cursor.fetchone()77 while row is not None:78 yield self._format_row(row)79 row = self.cursor.fetchone()80 finally:81 self.cursor.close()82 def _prepare_row(self, row):83 return row84 def _format_dump(self, data):85 raise NotImplementedError("{} does not support formatting dumped data.".format(self.__class__.__name__))86 def _format_row(self, row):87 raise NotImplementedError("{} does not support formatting streaming data.".format(self.__class__.__name__))88class PandasCursorFormatter(CursorFormatter):89 """90 Formats a cursor into pandas datatypes.91 Dumped data is transformed into a pandas DataFrame.92 Streamed data is transformed into lists of pandas Series objects.93 """94 def _init(self, index_fields=None, date_fields=None):95 self.index_fields = index_fields96 self.date_fields = date_fields97 def _format_dump(self, data):98 import pandas as pd99 df = pd.DataFrame(data=data, columns=self.column_names)100 if self.date_fields is not None:101 try:102 df = pd.io.sql._parse_date_columns(df, self.date_fields)103 except Exception as e:104 logger.warning('Unable to parse date columns. Perhaps your version of pandas is outdated.'105 'Original error message was: {}: {}'.format(e.__class__.__name__, str(e)))106 if self.index_fields is not None:107 df.set_index(self.index_fields, inplace=True)108 return df109 def _format_row(self, row):110 import pandas as pd111 # TODO: Handle parsing of date fields112 return pd.Series(row, index=self.column_names)113class DictCursorFormatter(CursorFormatter):114 """115 Formats a cursor into a list of dictionaries.116 """117 def _format_dump(self, data):118 return [self._format_row(row) for row in data]119 def _format_row(self, row):120 return dict(zip(self.column_names, row))121class TupleCursorFormatter(CursorFormatter):122 """123 Formats a cursor into a list of tuples.124 """125 def _format_dump(self, data):126 return [self._format_row(row) for row in data]127 def _format_row(self, row):128 return tuple(row)129class RawCursorFormatter(CursorFormatter):130 """131 Applies the trivial transformation to each row in the cursor.132 """133 def _format_dump(self, data):134 return data135 def _format_row(self, row):136 return row137class CsvCursorFormatter(CursorFormatter):138 """139 Formats each row of the cursor as a comma-separated value string.140 """141 FORMAT_PARAMS = {142 'delimiter': ',',143 'doublequote': False,144 'escapechar': '\\',145 'lineterminator': '\r\n',146 'quotechar': '"',147 'quoting': csv.QUOTE_MINIMAL148 }149 def _init(self, include_header=True):150 self.output = io.StringIO() if six.PY3 else io.BytesIO()151 self.include_header = include_header152 self.writer = csv.writer(self.output, **self.FORMAT_PARAMS)153 def _format_dump(self, data):154 if self.include_header:155 self.writer.writerow(self.column_names)156 try:157 self.writer.writerows(data)158 return self.output.getvalue()159 finally:160 self.output.truncate(0)161 self.output.seek(0)162 def _format_row(self, row):163 try:164 self.writer.writerow(row)165 return self.output.getvalue()166 finally:167 self.output.truncate(0)168 self.output.seek(0)169class HiveCursorFormatter(CsvCursorFormatter):170 """171 Formats each row of the cursor as a tab-separated value string.172 Note: `None` values are transformed into the hive-specific representation of173 `'\\N'`.174 """175 FORMAT_PARAMS = {176 'delimiter': '\t',...

Full Screen

Full Screen

pandas_summary.py

Source:pandas_summary.py Github

copy

Full Screen

...11 df = pd.DataFrame()12 def reset(self):13 self.df.drop(self.df.index, inplace=True)14 def add(self, summary_row):15 def _format_row(row):16 if self.summary_cols is None:17 return row18 19 return {key: value for key, value in row.items() if key in self.summary_cols}20 if isinstance(summary_row, list):21 rows = [_format_row({**self.static_fields, **row}) for row in summary_row]22 else:23 rows = [_format_row({**self.static_fields, **summary_row})]24 self.df = self.df.append(rows, ignore_index=True)25 def dump(self, path, reset=True):26 if not self.df.empty:27 is_first_dump = not os.path.exists(path)28 self.df.to_csv(path, mode='a',29 index=False, header=is_first_dump)30 log_string = self.df.tail(10).mean()31 if reset:32 self.reset()33 return log_string34 def load(self, path):35 if os.path.exists(path):36 self.df = pd.read_csv(path)37 else:...

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