def player_count(self): count = redis.get(self.cache_key) if not count: count = self.players_participating.count() redis.set(self.cache_key, count, ex=constants.PLAYER_COUNT_CACHE_DURATION) return count
def entry_count(self): count = redis.get(self.cache_key) if not count: count = self.player_entries.count() redis.set(self.cache_key, count, ex=constants.EVENT_ENTRY_COUNT_CACHE_DURATION) return count
def get(self, request): centers = { DISTRICT_KEY(district_id): sorted( json.loads(redis.get(DISTRICT_KEY(district_id)) or "[]"), key=lambda center: center["name"], ) for district_id in DISTRICT_IDS } updated = { DISTRICT_UPDATE_TIME_KEY(district_id): ((redis.get(DISTRICT_UPDATE_TIME_KEY(district_id)) or b"").decode("utf-8") or None) for district_id in DISTRICT_IDS } data = { "districts": DISTRICT_IDS_AND_DISTRICTS, "updated": updated, "centers": centers, } return Response(data)
def refetch_unavailable_players(): for draft in Draft.objects.filter(unavailable__isnull=False): logger.info(f"Fetching unavailable players from {draft}") new_entries = draft.entries original_entries_count = len(draft.entries) new_unavailable = [] for player in draft.unavailable: player_id = redis.get( PLAYER_ID_KEY(player.get("name"), player.get("team"))) if player_id: new_entries.append(player_id.decode("utf-8")) else: new_unavailable.append(player) if len(new_entries) == original_entries_count: logger.info("No new player IDs found") else: draft.entries = new_entries draft.unavailable = new_unavailable or None draft.save(update_fields=["entries", "unavailable"])
def get_current_gameweek(): return (redis.get(CURRENT_GAMEWEEK_KEY) or b"1").decode("utf-8")
def get_gameweek_fixtures_data(): return json.loads(redis.get(GAMEWEEK_FIXTURES_DATA_KEY) or "{}")
def get_team_fixtures_data(): return json.loads(redis.get(TEAM_FIXTURES_DATA_KEY) or "{}")
def get_gameweek_data(): return json.loads(redis.get(GAMEWEEK_DATA_KEY) or "{}")
def get_player_data(): return json.loads(redis.get(PLAYER_DATA_KEY) or "{}")
def get_team_data(): return json.loads(redis.get(TEAM_DATA_KEY) or "{}")
def _get_player_id(self, player): return redis.get(PLAYER_ID_KEY(player.get("name"), player.get("team")))