Skip to content

Commit

Permalink
stats fix again, fix lazyloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Rua committed Sep 7, 2015
1 parent de9eb29 commit 81382dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cassiopeia/core/statsapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_ranked_stats(summoner, season=None):
if(season and season not in cassiopeia.type.core.common.stats_seasons):
raise ValueError("Must use a valid season to get ranked stats for")

stats = cassiopeia.dto.statsapi.get_ranked_stats(summoner.id, season.value)
stats = cassiopeia.dto.statsapi.get_ranked_stats(summoner.id, season.value if season else None)
champions = {champion.id: champion for champion in cassiopeia.riotapi.get_champions_by_id(list(stats.champion_ids))}
champions[0] = None

Expand All @@ -32,5 +32,5 @@ def get_stats(summoner, season=None):
if(season and season not in cassiopeia.type.core.common.stats_seasons):
raise ValueError("Must use a valid season to get stats for")

stats = cassiopeia.dto.statsapi.get_stats(summoner.id, season.value)
stats = cassiopeia.dto.statsapi.get_stats(summoner.id, season.value if season else None)
return {cassiopeia.type.core.common.StatSummaryType(summary.playerStatSummaryType): cassiopeia.type.core.stats.StatsSummary(summary) for summary in stats.playerStatSummaries}
23 changes: 18 additions & 5 deletions cassiopeia/type/core/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import enum
import json
import weakref
import functools

import cassiopeia.type.api.exception

Expand Down Expand Up @@ -48,10 +49,7 @@ class WeakSet(set):
set: WeakSet
}

class lazyproperty(object):
"""Makes a property load only once and store the result value to be returned to all later calls
@decorator
"""
class LazyProperty(object):
def __init__(self, method):
"""
method function the method to turn into a lazy property
Expand Down Expand Up @@ -79,6 +77,21 @@ def __get__(self, obj, t=None):
self.values[obj] = weakref.ref(result)
return self.values[obj]()

def lazyproperty(method):
"""Makes a property load only once and store the result value to be returned to all later calls
method function the method to turn into a lazy property
return function the method as a lazy property
"""
prop = LazyProperty(method)

@property
@functools.wraps(method)
def lazy(self):
return prop.__get__(self)

return lazy

class immutablemethod(object):
"""Makes a method un-deletable and un-repleacable
Expand All @@ -97,9 +110,9 @@ def __delete__(self, obj):
raise AttributeError("can't delete method")

def __get__(self, obj, type=None):
@functools.wraps(self.method)
def curried(*args, **kwargs):
return self.method(obj, *args, **kwargs)
curried.__doc__ = self.method.__doc__
return curried


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="cassiopeia",
version="0.0.3",
version="0.0.4",
author="Rob Rua",
author_email="[email protected]",
url="https://github.com/robrua/cassiopeia",
Expand Down

0 comments on commit 81382dd

Please sign in to comment.