def test_round_sf(self): var = 151515.151515 test=lzfloat(var) self.assertEqual(test.round_sf(1),200000.0) self.assertEqual(test.round_sf(2),150000.0) self.assertEqual(test.round_sf(7),151515.2) self.assertEqual(test.round_sf(8),151515.15)
async def drawplayer(player, kav, totaldamage=0, killer=True, peoplegettingfame=0, debugchannel=None): # Base image link to load the images _baseimagelink = "https://render.albiononline.com/v1/item/" # kav is used to determine if hte player is killer, assist or victim # Create a new image playerimg = img.new("RGBA", (600, 1200), BACKGROUND) # set lambda functions to put text in the middle of width and height wmiddle = lambda x: (600 - x) / 2 hmiddle = lambda x, y, z: x + (y - z) / 2 # set drawing image for putting text drawimg = imgdraw.Draw(playerimg) # Get width and height of text width, height = drawimg.textsize(kav, font=defaultfont) # Set a text for the heading, padding of 10. drawimg.text((wmiddle(width), hmiddle(10, 50, height)), text=kav, font=defaultfont, fill=RED) # height after this starts from 65.0 width, height = drawimg.textsize(player["Name"], font=namesfont) drawimg.text((wmiddle(width), hmiddle(65, 50, height)), text=player["Name"], font=namesfont, fill=WHITE) # After this line of the text will start at height 140 # Get user guild name as shown in the game fullguildname = "{0}{1}".format(player["AllianceName"], player["GuildName"]) # Get the width and height of the guild name in text width, height = drawimg.textsize(fullguildname, font=namesfont_small) drawimg.text((wmiddle(width), hmiddle(150, 25, height)), text=fullguildname, font=namesfont_small, fill=BLUE) # set a variable for easy access equipments = player["Equipment"] """ File structure for data.json: [itemname, photolocation, textspace] itemname: UNIQUE_NAME key for the using item, can be used as a key to look for the image online from the database photolocation: location data on the image, it is a 2 point tuple that helps determine the x and y value of the upper left corner of the photo textspace: location data for the count of the item. Usually only useful in potion slot and food slot, used to determine the count of the item. """ async with aiohttp.ClientSession( headers={"Connection": "keep-alive"}) as session: # unpacks the data for item, imgspace, textspace in data: # check if the item exists if equipments[item]: # downloads image loadingimg = await get_image(_baseimagelink, equipments[item]["Type"], session, equipments[item]["Quality"], debugchannel) if loadingimg == False: return False # puts the image on the background using the given data playerimg.paste(loadingimg, imgspace) # put the count on the pasted image using the given data drawimg.text(textspace, text=str(equipments[item]["Count"]), font=systemfont, fill=WHITE) # Check if user is using a two-handed weapon try: twohand = await is_two_main_hand(equipments["MainHand"]["Type"]) except (AttributeError, TypeError) as e: twohand = False if twohand and equipments["MainHand"]: # downloads the image again from the database async with aiohttp.ClientSession( headers={"Connection": "close"}) as session: content = await get_image(_baseimagelink, equipments["MainHand"]["Type"], session, equipments["MainHand"]["Count"], debugchannel=debugchannel) # make the image transparent content.putalpha(100) playerimg.paste(content, (400, 380)) # provides the count drawimg.text((533, 490), text=str(equipments["MainHand"]["Count"]), font=systemfont, fill=WHITE) # Calculate their gear worth async with aiohttp.ClientSession( headers={"Connection": "close"}) as session: gearworth = await calculate_gearworth(player, session, debugchannel) # Set IP width, height = drawimg.textsize("IP: {}".format( round(player["AverageItemPower"], 2)), font=largesystemfont) drawimg.text((wmiddle(width), 930), "IP: {}".format(round(player["AverageItemPower"], 2)), font=largesystemfont, fill=WHITE) if killer: damageline = "Damage done:\n{}%[{}/{}]".format( lzfloat(player["DamageDone"] / totaldamage * 100).round_sf(4), round(int(player["DamageDone"])), totaldamage) else: damageline = "Death Fame: {} [{}]\n ={}/particiant".format( player["DeathFame"], peoplegettingfame, player["DeathFame"] // peoplegettingfame) width, height = drawimg.textsize(damageline, font=infotext) # Both death fame and the damage done are multiline texts. drawimg.multiline_text((wmiddle(width), hmiddle(1000, 70, height)), damageline, font=infotext, fill=WHITE) # Convert the gear worth into integer and round the gear worth to 5 signifacant figures gearworthline = "Estimated Gear Worth: {:,}".format( lzint(gearworth).round_sf(5)) width, height = drawimg.textsize(gearworthline, font=infotext) # Set gear worth drawimg.text((wmiddle(width), hmiddle(1120, 40, height)), gearworthline, font=infotext, fill=(RED if gearworth >= 1000000 else WHITE)) return playerimg
def test_significant_figures(self): var= 00000.0123000 test=lzfloat(var) self.assertEqual(test.significant_figures,3)
def test_digits_afterzero(self): var = 12345.678912345 test=lzfloat(var) self.assertEqual(test.digits_afterzero,9)
def test_digits_beforezero(self): var = 12345.6789 test=lzfloat(var) self.assertEqual(test.digits_beforezero,5)
def test_len(self): var = 10.1002 test=lzfloat(var) self.assertEqual(len(test),6) test= lzfloat(1234.123123) self.assertEqual(len(test),10)