Beispiel #1
0
    def load_leagues(person_id):
        """ Return a Person with Leagues data loaded. """
        (person, leagues) = loader.load_neighbors(
                person_id,
                [API_EDGE_TYPE.IN_LEAGUE],
                [API_NODE_TYPE.LEAGUE])

        person.set_leagues(leagues)

        return person
Beispiel #2
0
    def load_opponents(league_id):
        """ Return a League with Opponents loaded from the data layer."""
        (league, opponents) = loader.load_neighbors(
                league_id,
                [API_EDGE_TYPE.HAS_LEAGUE_MEMBER],
                API_CONSTANT.OPPONENT_NODE_TYPES)

        league.set_opponents(opponents)

        return league
Beispiel #3
0
    def load_games(league_id):
        """ Return a League with opponents loaded from the data layer."""
        (league, games) = loader.load_neighbors(
                league_id,
                [API_EDGE_TYPE.HAS_SCHEDULED],
                [API_NODE_TYPE.GAME])

        league.set_games(games)

        return league
Beispiel #4
0
    def load_important_persons(game_id):
        """ Load the Game's Opponents, Commenters, Creator and attributes into
        a Game.

        Required:
        int game_id     the id of the Game

        Return:
        Game            Game SqNode

        """
        # TODO: commenters should really be loaded in SqNode. This is a mess
        # because load_neighbors returns a single list of neighbors and then we
        # break that list up by type.

        edge_types = []
        edge_types.extend(API_CONSTANT.RESULT_EDGE_TYPES)
        edge_types.append(API_EDGE_TYPE.HAS_COMMENT_FROM)
        edge_types.append(API_EDGE_TYPE.CREATED_BY)

        node_types = []
        node_types.extend(API_CONSTANT.OPPONENT_NODE_TYPES)
        # should include "PERSON_NODE_TYPES"

        (game, important_persons) = loader.load_neighbors(
                game_id,
                edge_types,
                node_types)

        # sort the folks into separate lists of opponents and commenters
        opponent_ids = set(game.results_by_opponent_id.keys())
        comments = game.get_edges().get(
                API_EDGE_TYPE.HAS_COMMENT_FROM,
                {})
        commenter_ids = set(
                [comment.to_node_id for comment in comments.values()])

        opponents = {}
        commenters = {}
        creator = None
        for person in important_persons.values():
            id = person.id
            if id in opponent_ids:
                opponents[id] = person
            if id in commenter_ids:
                commenters[id] = person
            if id == game.creator_id:
                creator = person
        game.set_opponents(opponents)
        game.set_commenters(commenters)
        game.set_creator(creator)

        return game
Beispiel #5
0
    def load_opponents(game_id):
        """ Load the Game's Opponents and attributes into a Game.

        Required:
        int game_id     the id of the Game

        Return:
        Game            Game SqNode

        """
        (game, opponents) = loader.load_neighbors(
                game_id,
                API_CONSTANT.RESULT_EDGE_TYPES,
                API_CONSTANT.OPPONENT_NODE_TYPES)

        game.set_opponents(opponents)

        return game