Example #1
0
	def test_iter(self):
		var = 10
		test = lzint(var)
		val = 0
		for i in test:
			val += 1
		self.assertEqual(val,10)
		self.assertTrue(1 in test)
Example #2
0
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
Example #3
0
	def test_reciprocal(self):
		var = 100
		test=lzint(var)
		self.assertEqual(test.reciprocal,0.01)
Example #4
0
	def test_round_sf(self):
		var = 1555155
		test= lzint(var)
		self.assertEqual(test.round_sf(1),2000000)
		self.assertEqual(test.round_sf(2),1600000)
		self.assertEqual(test.round_sf(4),1555000)
Example #5
0
	def test_divisible_by(self):
		var = 12
		test= lzint(var)
		self.assertTrue(test.divisible_by(3))
		self.assertTrue(test.divisible_by(4))
		self.assertFalse(test.divisible_by(5))
Example #6
0
	def test_iseven(self):
		var = 101011
		test = lzint(var)
		self.assertFalse(test.iseven)
		test = lzint(test + 1)
		self.assertTrue(test.iseven)
Example #7
0
	def test_isodd(self):
		var = 101010
		test=lzint(var)
		self.assertFalse(test.isodd)
		test += 1
		self.assertTrue(lzint(test).isodd)
Example #8
0
	def test_len(self):
		var = 101010
		test= lzint(var)
		self.assertEqual(len(test),6)
Example #9
0
	def test_ifpositive(self):
		self.assertTrue(lzint(1).ispositive)
		self.assertFalse(lzint(-10).ispositive)
Example #10
0
		def _t(v=1):
			return lzint(v).iseven