How to use human_format method in autotest

Best Python code snippet using autotest_python

upgrade.py

Source:upgrade.py Github

copy

Full Screen

...130 """Skip upgrading if we don't have enough exp to buy at least one131 complete set of upgrades, in order to maintain our perfect ratios :)"""132 if total_price > current_exp:133 if self.report:134 print("No XP Upgrade :{:^8} of {:^8}".format(self.human_format(current_exp),self.human_format(total_price)))135 return136 amount = int(current_exp // total_price)137 e_power = amount * self.e2m_ratio138 e_cap = amount * self.ecap * self.e2m_ratio139 e_bars = amount * self.ebar * self.e2m_ratio140 m_power = amount141 m_cap = amount * self.mcap142 m_bars = amount * self.mbar143 self.exp()144 self.click(*coords.EM_POW_BOX)145 self.send_string(str(e_power))146 time.sleep(userset.MEDIUM_SLEEP)147 self.click(*coords.EM_CAP_BOX)148 self.send_string(str(e_cap))149 time.sleep(userset.MEDIUM_SLEEP)150 self.click(*coords.EM_BAR_BOX)151 self.send_string(str(e_bars))152 time.sleep(userset.MEDIUM_SLEEP)153 self.click(*coords.EM_POW_BUY)154 self.click(*coords.EM_CAP_BUY)155 self.click(*coords.EM_BAR_BUY)156 self.exp_magic()157 self.click(*coords.EM_POW_BOX)158 self.send_string(str(m_power))159 time.sleep(userset.MEDIUM_SLEEP)160 self.click(*coords.EM_CAP_BOX)161 self.send_string(str(m_cap))162 time.sleep(userset.MEDIUM_SLEEP)163 self.click(*coords.EM_BAR_BOX)164 self.send_string(str(m_bars))165 time.sleep(userset.MEDIUM_SLEEP)166 self.click(*coords.EM_POW_BUY)167 self.click(*coords.EM_CAP_BUY)168 self.click(*coords.EM_BAR_BUY)169 self.set_value_with_ocr("XP")170 total_spent = coords.EPOWER_COST * e_power + coords.ECAP_COST * e_cap + coords.EBAR_COST * e_bars171 total_spent += coords.MPOWER_COST * m_power + coords.MCAP_COST * m_cap + coords.MBAR_COST * m_bars172 if self.report:173 print("Spent XP:{:^8}".format(self.human_format(total_spent)))174 print("Energy | Pow:{:^8}{:^3}Cap:{:^8}{:^3}Bar:{:^8}{:^3}Magic | Pow:{:^8}{:^3}Cap:{:^8}{:^3}Bar:{:^8}".format(175 self.human_format(e_power), "|",176 self.human_format(e_cap), "|",177 self.human_format(e_bars), "|",178 self.human_format(m_power), "|",179 self.human_format(m_cap), "|",180 self.human_format(m_bars)))181 def human_format(self, num):182 num = float('{:.3g}'.format(num))183 if num > 1e14:184 return185 magnitude = 0186 while abs(num) >= 1000:187 magnitude += 1188 num /= 1000.0189 return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])190class UpgradeAdventure(Stats):191 """Buys things for exp."""192 def __init__(self, power, toughness, health, regen, ratio, report=False):193 self.power = power194 self.toughness = toughness195 self.health = health196 self.regen = regen197 self.ratio = ratio198 self.report = report199 def buy(self):200 """Buy upgrades for power, toughness, health and regen201 Requires the confirmation popup button for EXP purchases in settings202 to be turned OFF.203 This uses all available exp, so use with caution.204 """205 self.set_value_with_ocr("XP")206 if Stats.OCR_failed:207 print('OCR failed, exiting upgrade routine.')208 return209 current_exp = Stats.xp210 total_price = (coords.APOWER_COST * self.power * self.ratio)211 total_price += (coords.ATOUGHNESS_COST * self.toughness * self.ratio)212 total_price += (coords.AHEALTH_COST * self.health * 10)213 total_price += math.floor(coords.AREGEN_COST * self.regen / 10)214 """Skip upgrading if we don't have enough exp to buy at least one215 complete set of upgrades, in order to maintain our perfect ratios :)"""216 if total_price > current_exp:217 if self.report:218 print("No XP Upgrade :{:^8} of {:^8}".format(self.human_format(current_exp), self.human_format(total_price)))219 return220 amount = int(current_exp // total_price)221 a_power = amount * self.ratio222 a_toughness = amount * self.ratio223 a_health = amount * 10224 a_regen = math.floor(amount / 10)225 if a_regen < 1:226 a_regen = 1.0227 self.exp_adventure()228 self.click(*coords.EM_ADV_BOX)229 self.send_string(str(a_power))230 time.sleep(userset.MEDIUM_SLEEP)231 self.click(*coords.EM_POW_BOX)232 self.send_string(str(a_toughness))233 time.sleep(userset.MEDIUM_SLEEP)234 self.click(*coords.EM_CAP_BOX)235 self.send_string(str(a_health))236 time.sleep(userset.MEDIUM_SLEEP)237 self.click(*coords.EM_BAR_BOX)238 self.send_string(str(a_regen))239 time.sleep(userset.MEDIUM_SLEEP)240 self.click(*coords.EM_ADV_BUT)241 self.click(*coords.EM_POW_BUY)242 self.click(*coords.EM_CAP_BUY)243 self.click(*coords.EM_BAR_BUY)244 self.set_value_with_ocr("XP")245 total_spent = coords.APOWER_COST * a_power246 total_spent += coords.ATOUGHNESS_COST * a_toughness247 total_spent += coords.AHEALTH_COST * a_health248 total_spent += coords.AREGEN_COST * a_regen249 if self.report:250 print("Spent XP:{:^8}".format(self.human_format(total_spent)))251 print("Power:{:^8}{:^3} Defense:{:^8}{:^3} Health:{:^8}{:^3} Regen:{:^8}".format(252 self.human_format(a_power), "|",253 self.human_format(a_toughness), "|",254 self.human_format(a_health), "|",255 self.human_format(a_regen)))256 def human_format(self, num):257 num = float('{:.3g}'.format(num))258 if num > 1e14:259 return260 magnitude = 0261 while abs(num) >= 1000:262 magnitude += 1263 num /= 1000.0264 return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])265class UpgradeRich(Stats):266 """Buys things for exp."""267 def __init__(self, attack, defense, report=False):268 self.attack = attack269 self.defense = defense270 self.report = report271 def buy(self):272 """Buy upgrades for both attack and defense273 Requires the confirmation popup button for EXP purchases in settings274 to be turned OFF.275 This uses all available exp, so use with caution.276 """277 self.set_value_with_ocr("XP")278 if Stats.OCR_failed:279 print('OCR failed, exiting upgrade routine.')280 return281 current_exp = Stats.xp282 if current_exp < 1000:283 return284 total_price = (coords.RATTACK_COST * self.attack)285 total_price += (coords.RDEFENSE_COST * self.defense)286 """Skip upgrading if we don't have enough exp to buy at least one287 complete set of upgrades, in order to maintain our perfect ratios :)"""288 if total_price > current_exp:289 if self.report:290 print("No XP Upgrade :{:^8} of {:^8}".format(self.human_format(current_exp), self.human_format(total_price)))291 return292 amount = int(current_exp // total_price)293 a_attack = amount * self.attack294 a_defense = amount * self.defense295 self.exp_rich()296 self.click(*coords.EM_ADV_BOX)297 self.send_string(str(a_attack))298 time.sleep(userset.MEDIUM_SLEEP)299 self.click(*coords.EM_ADV_BOX)300 self.send_string(str(a_defense))301 time.sleep(userset.MEDIUM_SLEEP)302 self.click(*coords.EM_ADV_BOX)303 self.click(*coords.EM_ADV_BOX)304 self.set_value_with_ocr("XP")305 total_spent = coords.RATTACK_COST * a_attack306 total_spent += coords.RDEFENSE_COST * a_defense307 if self.report:308 print("Spent XP:{:^8}{:^3}Attack:{:^8}{:^3}Defense:{:^8}".format(309 self.human_format(total_spent), "|",310 self.human_format(a_attack), "|",311 self.human_format(a_defense)))312 def human_format(self, num):313 num = float('{:.3g}'.format(num))314 if num > 1e14:315 return316 magnitude = 0317 while abs(num) >= 1000:318 magnitude += 1319 num /= 1000.0320 return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])321class UpgradeHackPower(Stats):322 """Buys things for exp."""323 def __init__(self, hcap, hbar, hpower, report=False):324 """Example: UpgradeHackPower(10000, 1, 1).325 Keyword arguments:326 hcap -- The amount of hack energy in the ratio. Must be over 1000 and divisible by 250 or 0.327 hbar -- The amount of bars328 hpower -- the amount of new power329 """330 self.hcap = hcap331 self.hbar = hbar332 self.hpower = hpower333 self.report = report334 def buy(self):335 """Buy upgrades for hack energy336 Requires the confirmation popup button for EXP purchases in settings337 to be turned OFF.338 This uses all available exp, so use with caution.339 """340 if (self.hcap < 10000 or self.hcap % 250 != 0) and self.hcap != 0:341 print("Ecap value not divisible by 250 or lower than 10000, not" +342 " spending exp.")343 return344 self.set_value_with_ocr("XP")345 if Stats.OCR_failed:346 print('OCR failed, exiting upgrade routine.')347 return348 current_exp = Stats.xp349 total_price = coords.HPOWER_COST * self.hpower + coords.HCAP_COST * self.hcap + coords.HBAR_COST * self.hbar350 """Skip upgrading if we don't have enough exp to buy at least one351 complete set of upgrades, in order to maintain our perfect ratios :)"""352 if total_price > current_exp:353 if self.report:354 print("No XP Upgrade :{:^8} of {:^8}".format(self.human_format(current_exp),355 self.human_format(total_price)))356 return357 amount = int(current_exp // total_price)358 h_power = amount * self.hpower359 h_cap = amount * self.hcap360 h_bars = amount * self.hbar361 self.exp_hack()362 self.click(*coords.EM_POW_BOX)363 self.send_string(str(h_power))364 time.sleep(userset.MEDIUM_SLEEP)365 self.click(*coords.EM_CAP_BOX)366 self.send_string(str(h_cap))367 time.sleep(userset.MEDIUM_SLEEP)368 self.click(*coords.EM_BAR_BOX)369 self.send_string(str(h_bars))370 time.sleep(userset.MEDIUM_SLEEP)371 if h_power > 0:372 self.click(*coords.EM_POW_BUY)373 if h_cap > 0:374 self.click(*coords.EM_CAP_BUY)375 if h_bars > 0:376 self.click(*coords.EM_BAR_BUY)377 self.set_value_with_ocr("XP")378 total_spent = coords.HPOWER_COST * h_power + coords.HCAP_COST * h_cap + coords.HBAR_COST * h_bars379 if self.report:380 print("Spent XP:{:^8}".format(self.human_format(total_spent)))381 print("New | Pow:{:^8}{:^3}Cap:{:^8}{:^3}Bar:{:^8}".format(382 self.human_format(h_power), "|",383 self.human_format(h_cap), "|",384 self.human_format(h_bars)))385 def human_format(self, num):386 num = float('{:.3g}'.format(num))387 if num > 1e14:388 return389 magnitude = 0390 while abs(num) >= 1000:391 magnitude += 1392 num /= 1000.0...

Full Screen

Full Screen

filter.py

Source:filter.py Github

copy

Full Screen

...9# print number in a readable format.10# default is up to 3 decimal digits and can be changed11# works on numbers in the range of 1e-15 to 1e 1e15 include negatives numbers12# can force the number to a specific magnitude unit13def human_format(num:float, force=None, ndigits=3):14 perfixes = ('p', 'n', 'u', 'm', '', 'K', 'M', 'G', 'T')15 one_index = perfixes.index('')16 if force:17 if force in perfixes:18 index = perfixes.index(force)19 magnitude = 3*(index - one_index)20 num = num/(10**magnitude)21 else:22 raise ValueError('force value not supported.')23 else:24 div_sum = 025 if(abs(num) >= 1000):26 while abs(num) >= 1000:27 div_sum += 128 num /= 100029 else:30 while abs(num) <= 1:31 div_sum -= 132 num *= 100033 temp = round(num, ndigits) if ndigits else num34 if temp < 1000:35 num = temp 36 else:37 num = 138 div_sum += 139 index = one_index + div_sum40 return str(num).rstrip('0').rstrip('.') + perfixes[index]41# some tests42print(human_format(999) ,' = ' , '999') 43print(human_format(999.999) ,' = ' , '999.999') 44print(human_format(999.9999) ,' = ' , '1K') 45print(human_format(999999) ,' = ' , '999.999K') 46print(human_format(999499) ,' = ' , '999.499K') 47print(human_format(9994) ,' = ' , '9.994K') 48print(human_format(9900) ,' = ' , '9.9K') 49print(human_format(6543165413) ,' = ' , '6.543G') 50print(human_format(46780.9) ,' = ' , '46.781K') 51print(human_format(0.001) ,' = ' , '1m') 52print(human_format(0.000000999999) ,' = ' , '999.999n') 53print(human_format(1.00394200) ,' = ' , '1.004') 54print(human_format(0.0999) ,' = ' , '99.9m') 55print(human_format(0.00000000999999) ,' = ' , '10n') 56print(human_format(0.0000000099995) ,' = ' , '9.999n') 57print(human_format(0.000000009999) ,' = ' , '9.999n') 58print(human_format(999999 ,ndigits=2) ,' = ' , '1M') 59print(human_format(9994 ,force='') ,' = ' , '9994K') 60print(human_format(6543165413 ,ndigits=5) ,' = ' , '6.54317G') 61print(human_format(6543165413 ,ndigits=None) ,' = ' , '6.543165413G') 62print(human_format(7436313 ,ndigits=2) ,' = ' , '7.44M') 63print(human_format(2344 ,ndigits=2) ,' = ' , '2.34K')...

Full Screen

Full Screen

test_tags.py

Source:test_tags.py Github

copy

Full Screen

1from ui.templatetags.radio import human_format2def test_human_format():3 assert human_format(-1) == '-1'4 assert human_format(0) == '0'5 assert human_format(1) == '1'6 assert human_format(1.53) == '1.5'7 assert human_format(10) == '10'8 assert human_format(100) == '100'9 assert human_format(1000) == '1K'10 assert human_format(1300) == '1.3K'11 assert human_format(1345) == '1.3K'12 assert human_format(1300000) == '1.3M'13 assert human_format(1950) == '1.9K'14 assert human_format(2147483647) == '2.1G'15 assert human_format(5000) == '5K'...

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