Skip to content

Commit

Permalink
show globetrotter and harmony in table + show champions selection
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRaphael0000 committed Aug 27, 2022
1 parent 84ef625 commit 310415a
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 249 deletions.
58 changes: 39 additions & 19 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

from challenges_tools import get_custom_optimized_compositions
from challenges_tools import get_summoner_challenges_infos
from challenges_tools import challenges
from challenges_tools import challenges_groups
from challenges_tools import challenges_data
from challenges_tools import challenges_config
from challenges_tools import find_challenges_details
from challenges_tools import champions
from challenges_tools import champions_alphabetical

Expand Down Expand Up @@ -84,7 +85,8 @@ def args_challenges_intersection(region, summoner):
return {
"champions": champions,
"champions_alphabetical": champions_alphabetical,
"challenges": enumerate(challenges),
"challenges_data": challenges_data,
"challenges_groups": challenges_groups,
"challenges_config": challenges_config,
"regions": regions,
"region": region,
Expand Down Expand Up @@ -202,43 +204,61 @@ def route_custom_compositions_wizard():
return render_template("custom_compositions.html", **args)


@app.route("/challenge_intersection/<challenges_id>")
@app.route("/intersection/<challenges_id>")
def route_challenge_intersection(challenges_id):
if challenges_id == "none":
response = {
"intersection": [],
"challenges_additional_intersection": list()
}
for id_, c in challenges_data.items():
for i, ci in enumerate(c):
response["challenges_additional_intersection"].append(
[f"{id_}:{i}", len(ci["champions"])])
return json.dumps(response)

try:
challenges_id = [int(s) for s in challenges_id.split(",")]
challenges_champions = [set(challenges[ci]["champions"])
for ci in challenges_id]
challenges_id = [s for s in challenges_id.split(",")]
challenges_champions = []
for ci in challenges_id:
split = ci.split(":")
if len(split) == 1:
id_, subid = split[0], 0
elif len(split) == 2:
id_, subid = split
id_, subid = int(id_), int(subid)
champions = challenges_data[id_][subid]["champions"]
challenges_champions.append(champions)
except:
return abort(404)

u = set.intersection(*challenges_champions)

response = {
"intersection": list(u),
"challenges_additional_intersection": list()
}
for i, c in enumerate(challenges):
s = set(c["champions"])
uc = u.intersection(s)
response["challenges_additional_intersection"].append([i, len(uc)])

for id_, c in challenges_data.items():
for i, ci in enumerate(c):
s = set(ci["champions"])
uc = u.intersection(s)
l = len(uc)
response["challenges_additional_intersection"].append(
[f"{id_}:{i}", l])

return json.dumps(response)


@app.route("/champions_selected/<champions>")
def route_champions_selected(champions=""):
try:
champions = set(champions.split(","))

valid_challenges = {}

for i, c in enumerate(challenges):
set_champions = set(c["champions"])
current_selection = len(set_champions.intersection(champions))
valid_challenges[i] = current_selection
comp = set(champions.split(","))
challenges_info = find_challenges_details(comp)
except:
return abort(404)

return json.dumps(valid_challenges)
return json.dumps(challenges_info)


@app.route("/best_fit_roles/<champions>")
Expand Down
51 changes: 33 additions & 18 deletions challenges_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,25 @@
]


challenges = json.load(open("static/challenges.json"))
for c in challenges:
c["champions_l"] = len(c["champions"])

for c in challenges:
challenges_data = json.load(open("static/challenges.json"))
for c in challenges_data:
c["max"] = len(c["champions"])
c["champions"] = set(c["champions"])
c["qte"] = c["qte"]


challenges_by_champions = defaultdict(list)
for challenge in challenges:
for challenge in challenges_data:
for champion in challenge["champions"]:
challenges_by_champions[champion].append(challenge["id"])
challenges_by_champions = dict(challenges_by_champions)

champions_by_challenge = {
challenge["id"]: challenge["champions"]
for challenge in challenges
for challenge in challenges_data
}

# load champions data
champions_alphabetical = sorted(champions, key=lambda c: champions[c]["name"])
champions_by_keys = {
int(champion["key"]): champion
for _, champion in champions.items()
}

try:
lol_watcher = None
Expand All @@ -89,20 +82,41 @@
# the region doesn't matter
challenges_config = lol_watcher.challenges.config(default_region)
challenges_config = {c["id"]: c for c in challenges_config}
for c in challenges_data:
challenges_config[c['id']]["qte"] = c["qte"]
challenges_config[c['id']]["max"] = c["max"]
except ValueError:
print("No Riot API key provided")
except ApiError:
print("This Riot API key can't access the challenges scope")


challenges_data_ = defaultdict(list)
for c in challenges_data:
challenges_data_[c["id"]].append(c)
challenges_data = challenges_data_


def find_challenges(comp):
challenges_achieved = set()
for c in challenges:
if len(c["champions"].intersection(comp)) >= c["qte"]:
challenges_achieved.add(c["id"])
for id_, challenge in challenges_data.items():
for c in challenge:
if len(c["champions"].intersection(comp)) >= c["qte"]:
challenges_achieved.add(c["id"])
return challenges_achieved


def find_challenges_details(comp):
challenges_details = {}
for id_, challenge in challenges_data.items():
for c in challenge:
current = list(set(comp).intersection(set(c["champions"])))
if id_ not in challenges_details or len(current) > len(challenges_details[id_]):
challenges_details[id_] = current
return challenges_details



def find_comp(champions_, threshold_min=0, threshold_max=sys.maxsize, max_depth=1e7):
# sort them by number of challenges to find good match first
champions_ = list(champions_)
Expand Down Expand Up @@ -190,7 +204,8 @@ def get_custom_optimized_compositions(region, summoners_names, power=1.3, max_de
summoner_masteries = lol_watcher.champion_mastery.by_summoner(
region=region, encrypted_summoner_id=summoner["id"])

masteries_by_id = {mastery["championId"]: mastery for mastery in summoner_masteries}
masteries_by_id = {mastery["championId"]
: mastery for mastery in summoner_masteries}
champion_masteries = {}

for champion_id, champion in champions.items():
Expand Down Expand Up @@ -264,8 +279,8 @@ def create_summoner_challenge(challenge_id):
return challenge_for_this_summoner

summoner_challenges = {
challenge["id"]: create_summoner_challenge(challenge["id"])
for challenge in challenges
challenge_id: create_summoner_challenge(challenge_id)
for challenge_id in challenges_data.keys()
}

total_points = summoner_challenges_infos["totalPoints"]
Expand Down
8 changes: 4 additions & 4 deletions champions_roles.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from pprint import pprint
from collections import defaultdict
import random
import json

import numpy as np

champions = json.load(
open("static/datadragon_cache/champion.json", "rb"))["data"]


filedata = open("static/txt/champions_roles.csv").read()

champions_by_ig_name = {champion["name"] : champion for _, champion in champions.items()}
champions_by_ig_name = {
champion["name"]: champion
for _, champion in champions.items()
}

lines = filedata.split("\n")

Expand Down
23 changes: 12 additions & 11 deletions static/css/challenges_intersection.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
}
}

.custom_table td {
.table_challenges td {
padding: 1px 10px;
}

.custom_table thead tr>th {
padding-bottom: 5px;
.table_challenges thead tr td {
font-weight: bold;
}

.custom_table th {
.table_challenges th {
padding: 1px 10px;
cursor: pointer;
}

.custom_table td.less_pad {
.table_challenges td.less_pad {
padding: 1px 1px !important;
}

.custom_table th.less_pad {
.table_challenges th.less_pad {
padding: 1px 1px !important;
}

.custom_table td label {
.table_challenges td label {
display: block;
}

Expand All @@ -36,10 +36,6 @@
transition: opacity 0.3s, color 0.3s;
}

.challenge_label:hover {
cursor: pointer;
}

.challenge_tr.selected {
color: yellow !important;
}
Expand Down Expand Up @@ -87,6 +83,11 @@
pointer-events: none;
}

.challenge_selection_img {
width: 21px;
height: 21px;
}

#search_champion {
position: absolute;
width: 30%;
Expand Down
7 changes: 6 additions & 1 deletion static/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ body {
font-size: 0.95em !important;
}

label:hover {
cursor: pointer;
display:inline;
}

.bg_img {
background-image: url("/static/img/Tahm_Kench_OriginalSkin.jpg");
position: fixed;
Expand All @@ -16,7 +21,7 @@ body {
}

.active {
border-bottom: 1px rgba(255,255,255,0.5) solid;
border-bottom: 1px rgba(255, 255, 255, 0.5) solid;
}

.socials {
Expand Down
Loading

0 comments on commit 310415a

Please sign in to comment.