Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
 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)
Пример #4
0
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"])
Пример #5
0
def get_current_gameweek():
    return (redis.get(CURRENT_GAMEWEEK_KEY) or b"1").decode("utf-8")
Пример #6
0
def get_gameweek_fixtures_data():
    return json.loads(redis.get(GAMEWEEK_FIXTURES_DATA_KEY) or "{}")
Пример #7
0
def get_team_fixtures_data():
    return json.loads(redis.get(TEAM_FIXTURES_DATA_KEY) or "{}")
Пример #8
0
def get_gameweek_data():
    return json.loads(redis.get(GAMEWEEK_DATA_KEY) or "{}")
Пример #9
0
def get_player_data():
    return json.loads(redis.get(PLAYER_DATA_KEY) or "{}")
Пример #10
0
def get_team_data():
    return json.loads(redis.get(TEAM_DATA_KEY) or "{}")
Пример #11
0
 def _get_player_id(self, player):
     return redis.get(PLAYER_ID_KEY(player.get("name"), player.get("team")))