Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
DEViantUA authored Apr 26, 2024
1 parent b2970c1 commit 504d64c
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 127 deletions.
4 changes: 4 additions & 0 deletions enkacard/encbanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ async def creat(self, template = 1, akasha = False, snow = False):
if str(key.id) in self.character_art:
art = self.character_art[str(key.id)]

if not self.character_id is None:
if not str(key.id) in self.character_id:
continue

if template == 1:
task.append(teample_one.Creat(key,self.translateLang,art,self.hide_uid,self.uid,self.enc.player.nickname).start())
else:
Expand Down
3 changes: 1 addition & 2 deletions enkacard/src/generator/akasha_rank.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import aiohttp
import random
from ..utils import pill, git
from PIL import ImageDraw,Image

Expand Down Expand Up @@ -41,7 +40,7 @@ async def get_info_character(self, id):
async with session.get(url) as response:
if response.status == 200:
data = await response.json()
return data["data"].get("calculations",{})
return data["data"]
else:
return {}

Expand Down
5 changes: 3 additions & 2 deletions enkacard/src/generator/profile_teample_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ async def creat_background(self):
async def creat_charter(self,key):

charter_profile = Image.new("RGBA", (147, 211), (0,0,0,50))
if str(key.id) in self.img:
url_id = self.img[str(key.id)]
if not self.img is None:
if str(key.id) in self.img:
url_id = self.img[str(key.id)]
else:
url_id = key.icon.url

Expand Down
93 changes: 37 additions & 56 deletions enkacard/src/generator/teample_two.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import asyncio
from PIL import ImageDraw,Image,ImageChops
from enkanetwork.model.stats import CharacterStats

from ..utils import pill, git,diagram,options
from enkanetwork.enum import EquipmentsType
from .two import background, artifact, stat, skill
from .one import weapon,constant
from .akasha_rank import AkashaCreat
import random
_of = git.ImageCache()







class Creat:
def __init__(self,characters,lang,img,hide,uid,name) -> None:
self.character = characters
Expand Down Expand Up @@ -98,60 +95,44 @@ async def add_logo(self):
self.background.alpha_composite(logo, (1108,710))

async def creat_diagram(self):
elementUp = True
akashaElement = False
data_user = []

user_diagram = False
dataAkasha = await AkashaCreat(uid = self.uid).get_info_character(self.character.id)
if dataAkasha == []:
dataAkasha = {}
if dataAkasha != {}:
dataAkasha = dataAkasha[random.choice(list(dataAkasha.keys()))]['stats']
dataAkasha_new = []

for key in self.character.stats:
if key[1].id in [40,41,42,43,44,45,46]:
if elementUp:
key = max((x for x in self.character.stats if 40 <= x[1].id <= 46), key=lambda x: x[1].value)
elementUp = False
akashaElement = True
else:
continue
if key[1].value != 0 and key[0] in options.IconAddTrue:
akasha_name = options.AkashaStats.get(key[0], None)
if not akasha_name is None or akashaElement:
if akashaElement:
for keys in dataAkasha:
if "DMG" in keys and not "_CRITICAL" in keys:
akasha_name = keys
akashaElement = False

name = options.assets.get_hash_map(key[0])

if "." in name:
name = name.replace(".",".\n")
else:
name = name.replace(" ","\n")

try:
value = key[1].to_percentage()
procent = True
except:
value = key[1].to_rounded()
procent = False

if dataAkasha != {}:
if procent:
dataAkasha_new.append({"name": name, "value": float('{:.2f}'.format(dataAkasha[akasha_name]))})
else:
dataAkasha_new.append({"name": name, "value": round(dataAkasha[akasha_name])})
if not dataAkasha["chartsData"] is None:
chartsData = dataAkasha["chartsData"]["charts1pMetadata"][1]["avgStats"]
else:
user_diagram = True
chartsData = options._map_default
user_data = []
akasha_data = []

data_user.append({"name": name, "value": value})

if dataAkasha == {}:
dataAkasha_new = [{'name': entry['name'], 'value': entry['value']} for entry in data_user]

self.diagram = await diagram.create_normalized_radial_chart(data_user,dataAkasha_new,self.character.element.value)
for key in chartsData:
if user_diagram:
name = options.assets.get_hash_map(options._mapHash.get(key))
value = options.map_enka(key, self.character.stats)
if value.value == 0 and chartsData[key] == 0:
continue
try:
value = value.to_percentage()
except:
value = value.to_rounded()
chartsData[key] = options.format_value(key, chartsData[key], options._mapProcent.get(key), 1)
user_data.append({"name": name.replace(".",".\n").replace(" ","\n"), "value": value})
akasha_data.append({"name": name.replace(".",".\n").replace(" ","\n"), "value": value})
else:
name = options.assets.get_hash_map(options._mapHash.get(key))
value = options.map_enka(key, self.character.stats)
if value.value == 0 and chartsData[key] == 0:
continue
try:
value = value.to_percentage()
except:
value = value.to_rounded()
chartsData[key] = options.format_value(key, chartsData[key], options._mapProcent.get(key), 1)
user_data.append({"name": name.replace(".",".\n").replace(" ","\n"), "value": value})
akasha_data.append({"name": name.replace(".",".\n").replace(" ","\n"), "value": chartsData[key]})

self.diagram = await diagram.RadialChart(user_data, akasha_data, self.character.element.value).create_normalized_radial_chart() #create_normalized_radial_chart(user_data,akasha_data,self.character.element.value)

async def creat_stat(self):
self.stat_background = Image.new("RGBA", (519, 601), (0,0,0,0))
Expand Down
183 changes: 120 additions & 63 deletions enkacard/src/utils/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import numpy as np
from matplotlib import font_manager
from pathlib import Path
import warnings
import random

warnings.filterwarnings("ignore")

assets = assets = Path(__file__).parent.parent / 'assets'

Expand All @@ -15,79 +19,132 @@
custom_font = font_manager.FontProperties(fname=font_path)
plt.rcParams['font.family'] = custom_font.get_name()

async def create_normalized_radial_chart(data, data_rect, rgb):
rgb = pill.element_color_text.get(rgb, (149,107,5,255))
params = [item['name'] for item in data]
values = [item['value'] for item in data]
indices = [2, 1, 0, 7, 6, 5, 4, 3, 9, 10, 11, 12]

class RadialChart:
def __init__(self, data, data_rect, rgb):
self.data = data
self.data_rect = data_rect
self.rgb = rgb

@property
def data(self):
return self._data

@data.setter
def data(self, value):
self._data = self._reorder_data_by_indices(value)

@property
def data_rect(self):
return self._data_rect

@data_rect.setter
def data_rect(self, value):
self._data_rect = self._reorder_data_by_indices(value)

@staticmethod
def _reorder_data_by_indices(lst):
normalized_indices = [i % len(lst) for i in indices if i < len(lst)]
return [lst[i] for i in normalized_indices]

async def create_normalized_radial_chart(self):

rgb = pill.element_color_text.get(self.rgb, (149, 107, 5, 255))
params = [item['name'] for item in self.data]
values = [item['value'] for item in self.data]

max_values = {item['name']: item['value'] for item in self.data_rect}

num_vars = len(params)
normalized_values = []
for i in range(num_vars):
if max_values[params[i]] != 0:
if max_values[params[i]] < values[i]:
normalized_values.append(7)
else:
normalized_values.append(values[i] / max_values[params[i]])

else:
normalized_values.append(0)

max_values = {item['name']: item['value'] for item in data_rect}
normalized_values += [normalized_values[0]]

max_data_rect_values = [item['value'] for item in data_rect]
angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()
angles += angles[:1]

num_vars = len(params)

normalized_values = [values[i] / max_values[params[i]] if max_values[params[i]] != 0 else 0 for i in range(num_vars)]
normalized_values += [normalized_values[0]]
fig, ax = plt.subplots(subplot_kw=dict(polar=True))

ax.grid(False)

angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()
angles += angles[:1]
normalized_values_rect = [6.0 if max_values[params[i]] != 0 else 0 for i in range(num_vars)]
normalized_values_rect += [normalized_values_rect[0]]

fig, ax = plt.subplots(subplot_kw=dict(polar=True))

ax.grid(False)
num_background_lines = 7

normalized_values_rect = [max_data_rect_values[i] / max_values[params[i]] if max_values[params[i]] != 0 else 0 for i in range(num_vars)]
normalized_values_rect += [normalized_values_rect[0]]

num_background_lines = 6
max_data_rect_value = max(normalized_values_rect)
min_data_rect_value = min(normalized_values_rect)

max_data_rect_value = max(normalized_values_rect)
step = (max_data_rect_value - min_data_rect_value) / (num_background_lines - 1) if max_data_rect_value != min_data_rect_value else 1

radii_rect = [6] * len(normalized_values_rect)

step = max_data_rect_value / num_background_lines
radii_values = [self._get_value(item, max_values) for item in self.data]
radii_values.append(radii_values[0])

for i in range(1, num_background_lines + 2):
radii = [step * i] * len(angles)
radii.append(radii[0])
ax.plot(np.append(angles, angles[0]), radii, color='white', linestyle='-', linewidth=0.5, zorder=0, alpha=0.3)

for i in range(1, len(data_rect)+1):
radii = [step * i for step in range(len(data_rect))]
ax.plot([angles[i], angles[i]], [0.16, 1.16], color='white', linestyle='-', linewidth=0.5, zorder=1, alpha=0.3)
for i in range(1, num_background_lines + 1):
radii = [step * (i - 1) + 1] * len(angles)
radii.append(radii[0])
ax.plot(np.append(angles, angles[0]), radii, color='white', linestyle='-', linewidth=0.5, zorder=0,
alpha=0.3)

valuess = [item['value'] for item in data_rect]
valuess += [valuess[0]]
ax.plot(angles, normalized_values_rect, linewidth=2, color='white', marker='o', linestyle='solid', zorder=0, alpha=0.5)
for i, (angle, value) in enumerate(zip(angles, normalized_values_rect)):
if valuess[i] % 1 == 0:
val = str(valuess[i])
for i in range(1, len(self.data_rect) + 1):
radii = [i + 0.16] * len(self.data_rect)
ax.plot([angles[i], angles[i]], [0.16, num_background_lines + 0.16], color='white', linestyle='-',
linewidth=0.5, zorder=1, alpha=0.3)

valuess = [item['value'] for item in self.data_rect]
valuess += [valuess[0]]

ax.plot(angles, radii_rect, linewidth=2, color='white', marker='o', linestyle='solid', zorder=0, alpha=0.5)
for i, (angle, radius) in enumerate(zip(angles, radii_rect)):
if valuess[i] % 1 == 0:
val = str(valuess[i])
else:
val = '{:.1f}%'.format(valuess[i])

ax.annotate(val, (angle, radius), textcoords="offset points", xytext=(-10, -10), color="white",
fontsize=9, ha='left', alpha=1)

ax.plot(angles, radii_values, linewidth=1, color=(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255), marker='o',
zorder=1)
ax.fill(angles, radii_values, color=(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255), alpha=0.3)

ax.xaxis.grid(linewidth=0)
ax.set_yticklabels([])
ax.set_xticks(np.linspace(0, 2 * np.pi, len(params), endpoint=False))
ax.set_xticklabels(params, color='white', fontproperties=custom_font, fontsize=10)

ax.spines['polar'].set_visible(False)

buffer = io.BytesIO()
plt.savefig(buffer, format='png', transparent=True)
buffer.seek(0)

img = Image.open(buffer)

plt.close(fig)

return img

@staticmethod
def _get_value(value_info, max_value_dict):
max_value = max_value_dict.get(value_info['name'], None)
if max_value is None:
return 1
if value_info['value'] > max_value:
normalized_value = 7 + (value_info['value'] - max_value) / (max_value * 0.3)
return min(7.5, normalized_value)
else:
val = '{:.1f}%'.format(valuess[i])

ax.annotate(val, (angle, value), textcoords="offset points", xytext=(-10, -10), color = "white", fontsize=7, ha='left', alpha = 1)

normalized_values_v = []
for key in normalized_values:
if key > 1.0:
key = 1.2
normalized_values_v.append(key)

ax.plot(angles, normalized_values_v, linewidth=1, color = (rgb[0]/255,rgb[1]/255,rgb[2]/255), marker='o', zorder=1)
ax.fill(angles, normalized_values_v, color= (rgb[0]/255,rgb[1]/255,rgb[2]/255), alpha=0.3)

ax.xaxis.grid(linewidth=0)
ax.set_yticklabels([])
ax.set_xticks(angles)
ax.set_xticklabels(params + params[:1], color='white', fontproperties=custom_font,fontsize=10)
ax.spines['polar'].set_visible(False)

buffer = io.BytesIO()
plt.savefig(buffer, format='png', transparent=True)
buffer.seek(0)

img = Image.open(buffer)

plt.close(fig)

return img
return int(1 + 5 * ((value_info['value'] / max_value) ** 2.5))

9 changes: 6 additions & 3 deletions enkacard/src/utils/enkanetwork_update/enka_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import json


DATA_URL = "https://gitlab.com/Dimbreath/AnimeGameData/-/raw/main/{FOLDER}/{value}"
LANG_URL = "https://gitlab.com/Dimbreath/AnimeGameData/-/raw/main/{LANG_FOLDER}/TextMap{key}.json"
DATA_URL = "https://gitlab.com/Dimbreath/AnimeGameData/-/raw/master/{FOLDER}/{value}"
LANG_URL = "https://gitlab.com/Dimbreath/AnimeGameData/-/raw/master/{LANG_FOLDER}/TextMap{key}.json"
_PATH = None

from .pathfinding import search
Expand Down Expand Up @@ -43,7 +43,7 @@

def save_json(NAME_JSON, data, path = "data"):
global _PATH

with open(f"{_PATH}/{path}/{NAME_JSON}", "w", encoding="utf-8") as file:
json.dump(data, file, indent=4, ensure_ascii=False)

Expand Down Expand Up @@ -292,6 +292,9 @@ async def dowload(path = None):
_PATH = await search()
else:
_PATH = path

if "data" in _PATH:
_PATH = _PATH.replace("/data", "")

print(f"Path to enkanetwork.py: {_PATH}")
print("="*25)
Expand Down
Loading

0 comments on commit 504d64c

Please sign in to comment.