Skip to content

Instantly share code, notes, and snippets.

@Natim
Last active January 10, 2022 03:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natim/f95344db0838b6b8a9b58a5b4a5666a9 to your computer and use it in GitHub Desktop.
Save Natim/f95344db0838b6b8a9b58a5b4a5666a9 to your computer and use it in GitHub Desktop.
from functools import partial
RULES = {
'six_h': {'high': 390, 'low': 330},
'twelve_h': {'high': 750, 'low': 690},
'twentyfour_h': {'high': 1490, 'low': 1410},
'seven_d': {'high': 169, 'low': 168}
}
class StatsHelper(object):
def __init__(self, *args, **kwargs):
for k, v in RULES.items():
setattr(self, 'get_stats_{}'.format(k), partial(self._get_stats, low=v['low'], high=v['high']))
super(StatsHelper, self).__init__(*args, **kwargs)
def _get_stats(self, low, high):
print('CALLED with {}, {}'.format(low, high))
if __name__ == '__main__':
s = StatsHelper()
print(s)
# import pdb ; pdb.set_trace()
s.get_stats_six_h()
s.get_stats_seven_d()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment