Skip to content

Commit

Permalink
fixes borken build
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Oct 9, 2024
1 parent dbd0133 commit 3744741
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 394 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ node_modules
.bashful
.pytest_cache
.mypy*

.direnv
.envrc
8 changes: 4 additions & 4 deletions clashleaders/model/avg_troop.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
StringField,
)

from clashleaders.model import Player
import clashleaders.model.player


class AverageTroop(Document):
Expand All @@ -33,21 +33,21 @@ def troop_id(self):

@classmethod
def update_all(cls):
good_tag = Player._get_collection().find_one(
good_tag = clashleaders.model.player.Player._get_collection().find_one(
{
"lab_levels.home_unicorn": {"$exists": True},
"lab_levels.builderbase_battle_machine": {"$exists": True},
"lab_levels.builderbase_super_pekka": {"$exists": True},
}
)["tag"]
good_player = Player.find_by_tag(good_tag)
good_player = clashleaders.model.player.Player.find_by_tag(good_tag)

group = {"$group": {"_id": "$townHallLevel"}}
for key in good_player.lab_levels.keys():
group["$group"][f"avg_{key}"] = {"$avg": f"$lab_levels.{key}"}
group["$group"][f"max_{key}"] = {"$max": f"$lab_levels.{key}"}

aggregated = list(Player.objects.aggregate(group))
aggregated = list(clashleaders.model.player.Player.objects.aggregate(group))

for th_avg in aggregated:
th_level = th_avg["_id"]
Expand Down
17 changes: 12 additions & 5 deletions clashleaders/model/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import clashleaders.model
from clashleaders.clash import api
from clashleaders.insights.player_activity import clan_history
from clashleaders.model import Clan
from clashleaders.model.clan_war import ClanWar
from clashleaders.model.historical_player import HistoricalPlayer
from clashleaders.util import correct_tag
import clashleaders.model.clan


class Player(Document):
Expand All @@ -40,9 +40,9 @@ class Player(Document):
"strict": False,
}

def most_recent_clan(self) -> Optional[Clan]:
def most_recent_clan(self) -> Optional[clashleaders.model.clan.Clan]:
return (
Clan.find_by_tag(self.clan["tag"])
clashleaders.model.clan.Clan.find_by_tag(self.clan["tag"])
if hasattr(self, "clan") and "tag" in self.clan
else None
)
Expand Down Expand Up @@ -92,7 +92,12 @@ def fetch_troops(self):

def clan_history(self):
history = clan_history(self).to_dict()
clans = {c.tag: c for c in Clan.objects(tag__in=list(history.values()))}
clans = {
c.tag: c
for c in clashleaders.model.clan.Clan.objects(
tag__in=list(history.values())
)
}
history = {k: clans[v] for k, v in history.items()}

return history
Expand All @@ -113,7 +118,9 @@ def to_dict(self, include_score=False) -> Dict:
data["percentile"] = self.player_score()

if data["clan"]:
data["clan"]["slug"] = Clan.find_by_tag(data["clan"]["tag"]).slug
data["clan"]["slug"] = clashleaders.model.clan.Clan.find_by_tag(
data["clan"]["tag"]
).slug

return data

Expand Down
4 changes: 2 additions & 2 deletions clashleaders/views/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mongoengine import DoesNotExist

from clashleaders import app, cache
from clashleaders.model import Clan
import clashleaders.model.clan

TEMPLATE = dict(small="badges/small.svg", large="badges/large.svg")

Expand All @@ -33,7 +33,7 @@ def clan_badge_png(size, tag):

def render_as_svg(template, tag):
try:
clan = Clan.find_by_tag(tag)
clan = clashleaders.model.clan.Clan.find_by_tag(tag)
except DoesNotExist:
return render_template("404.html"), 404
else:
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
"whatwg-fetch": "^3.6.20"
},
"devDependencies": {
"concurrently": "^8.2.2",
"concurrently": "^9.0.1",
"husky": "^9.1.6",
"lint-staged": "^13.2.1",
"prettier": "^3.1.1",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"webpack-bundle-analyzer": "^4.10.1"
},
"scripts": {
Expand Down
Loading

0 comments on commit 3744741

Please sign in to comment.