示例#1
0
    def get_phase_groups(self):
        assert (self.id is not None
                ), "tournament id cannot be None if calling get_phase_groups"

        phase_groups = []
        data = NI.query(queries.get_tournament_phase_groups, {'id': self.id})
        validate_data(data)

        tournament_data = data['data']['tournament']
        if tournament_data is None:
            raise NoTournamentDataException(self.slug)

        event_data = tournament_data['events']
        if event_data is None:
            raise NoEventDataException(self.slug)

        phase_groups_data = [event['phaseGroups'] for event in event_data]
        for phase_group in phase_groups_data:
            if phase_group is None:
                raise NoPhaseGroupDataException(self.slug)
            [
                phase_groups.append(PhaseGroup.parse(phase_group_data))
                for phase_group_data in phase_group
            ]

        return phase_groups
示例#2
0
    def get_phase_groups(self):
        assert (
            self.id
            is not None), 'event id cannot be None if calling get_phase_groups'
        Logger.info('Getting Phase Groups for Event: {0}:{1}'.format(
            self.id, self.name))
        data = NI.query(queries.get_event_phase_groups, {'id': self.id})
        validate_data(data)

        try:
            event_data = data['data']['event']
            if event_data is None:
                raise NoEventDataException(self.identifier)

            phase_groups_data = event_data['phaseGroups']
            if phase_groups_data is None:
                raise NoPhaseGroupDataException(self.identifier)

            return [
                PhaseGroup.parse(phase_group_data)
                for phase_group_data in phase_groups_data
            ]
        except AttributeError as e:
            raise Exception(
                "No phase group data pulled back for event {}".format(
                    self.identifier))
示例#3
0
    def get(id: int):
        assert (id is not None), "PhaseGroup.get cannot have None for id parameter"
        data = NI.query(queries.phase_group_by_id, {'id': id})
        validate_data(data)
        PhaseGroup.validate_data(data['data'])

        base_data = data['data']['phaseGroup']
        return PhaseGroup.parse(base_data)
示例#4
0
    def get(slug: str):
        assert (slug is not None), "Tournament.get must have a slug parameter"
        data = NI.query(queries.get_tournament_by_slug, {'slug': slug})
        validate_data(data)

        try:
            tournament_data = data['data']['tournament']
            if tournament_data is None:
                raise NoTournamentDataException(slug)

            return Tournament.parse(tournament_data)
        except AttributeError as e:
            raise NoTournamentDataException(slug)
示例#5
0
    def get_by_id(id: int):
        assert (id
                is not None), "Tournament.get_by_id must have an id parameter"
        data = NI.query(queries.get_tournament, {'id': id})
        validate_data(data)

        try:
            tournament_data = data['data']['tournament']
            if tournament_data is None:
                raise NoTournamentDataException(id)

            return Tournament.parse(tournament_data)
        except AttributeError as e:
            raise NoTournamentDataException(id)
示例#6
0
    def get_by_id(id: int):
        assert (
            id
            is not None), "Event.get_by_id cannot have None for id parameter"
        data = NI.query(queries.get_event_by_id, {'id': id})
        validate_data(data)

        try:
            event_data = data['data']['event']
            if event_data is None:
                raise NoEventDataException(id)

            return Event.parse(event_data)
        except AttributeError as e:
            raise NoEventDataException(id)
示例#7
0
    def get_events(self):
        assert (
            self.id
            is not None), "tournament id cannot be None if calling get_events"
        data = NI.query(queries.get_tournament_events, {'id': self.id})
        validate_data(data)

        tournament_data = data['data']['tournament']
        if tournament_data is None:
            raise NoTournamentDataException(self.slug)

        base_data = tournament_data['events']
        if base_data is None:
            raise NoEventDataException(self.slug)

        return [Event.parse(event_data) for event_data in base_data]
示例#8
0
    def get(tournament_slug: str, event_slug: str):
        assert (tournament_slug is not None
                ), 'Event.get cannot have None for tournament_slug parameter'
        assert (
            event_slug
            is not None), 'Event.get cannot have None for event_slug parameter'
        slug = "tournament/{0}/event/{1}".format(tournament_slug, event_slug)
        data = NI.query(queries.get_event_by_slugs, {"slug": slug})
        validate_data(data)

        try:
            event_data = data['data']['event']
            if event_data is None:
                raise NoEventDataException('{}:{}'.format(
                    tournament_slug, event_slug))

            return Event.parse(event_data)
        except AttributeError as e:
            raise NoEventDataException('{}:{}'.format(tournament_slug,
                                                      event_slug))
示例#9
0
    def get_phase_groups(self):
        assert (self.id is not None
                ), "phase id cannot be None when calling get_phase_groups"
        Logger.info('Getting Phase Groups for Phase: {0}:{1}'.format(
            self.id, self.name))
        data = NI.paginated_query(queries.phase_phase_groups, {'id': self.id})
        [validate_data(phase_data) for phase_data in data]

        # Schema Validation
        [Phase.validate_data(element['data'], self.id) for element in data]
        phase_data = [phase_data['data']['phase'] for phase_data in data]

        [PhaseGroup.validate_data(element, self.id) for element in phase_data]
        phase_group_data = flatten(
            [element['phaseGroups'] for element in phase_data])

        return [
            PhaseGroup.parse(phase_group) for phase_group in phase_group_data
        ]