当前位置: 首页>>代码示例>>Python>>正文


Python EventTeam.query方法代码示例

本文整理汇总了Python中models.event_team.EventTeam.query方法的典型用法代码示例。如果您正苦于以下问题:Python EventTeam.query方法的具体用法?Python EventTeam.query怎么用?Python EventTeam.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.event_team.EventTeam的用法示例。


在下文中一共展示了EventTeam.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_eventteams_update

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def test_eventteams_update(self):
        self.teams_auth.put()

        team_list = ['frc254', 'frc971', 'frc604']
        request_body = json.dumps(team_list)

        request_path = '/api/trusted/v1/event/2014casj/team_list/update'
        sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
        response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'tEsT_id_0', 'X-TBA-Auth-Sig': sig}, expect_errors=True)

        self.assertEqual(response.status_code, 200)

        db_eventteams = EventTeam.query(EventTeam.event == self.event.key).fetch(None)
        self.assertEqual(len(db_eventteams), 3)
        self.assertTrue('2014casj_frc254' in [et.key.id() for et in db_eventteams])
        self.assertTrue('2014casj_frc971' in [et.key.id() for et in db_eventteams])
        self.assertTrue('2014casj_frc604' in [et.key.id() for et in db_eventteams])

        team_list = ['frc254', 'frc100']
        request_body = json.dumps(team_list)

        sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
        response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'tEsT_id_0', 'X-TBA-Auth-Sig': sig}, expect_errors=True)

        self.assertEqual(response.status_code, 200)

        db_eventteams = EventTeam.query(EventTeam.event == self.event.key).fetch(None)
        self.assertEqual(len(db_eventteams), 2)
        self.assertTrue('2014casj_frc254' in [et.key.id() for et in db_eventteams])
        self.assertTrue('2014casj_frc100' in [et.key.id() for et in db_eventteams])
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:32,代码来源:test_api_trusted.py

示例2: get_events_and_matches_async

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
 def get_events_and_matches_async():
     if return_valid_years:
         event_team_keys_query = EventTeam.query(EventTeam.team == team.key)
     else:
         event_team_keys_query = EventTeam.query(EventTeam.team == team.key, EventTeam.year == year)
     event_team_keys = yield event_team_keys_query.fetch_async(1000, keys_only=True)
     event_teams = yield ndb.get_multi_async(event_team_keys)
     event_keys = []
     for event_team in event_teams:
         if return_valid_years:
             valid_years.add(event_team.year)  # valid_years is a "global" variable (defined below). Doing this removes the complexity of having to propagate the years up through the tasklet call chain.
         if not return_valid_years or event_team.year == year:
             event_keys.append(event_team.event)
     events, matches = yield ndb.get_multi_async(event_keys), get_matches_async(event_keys)
     raise ndb.Return((events, matches))
开发者ID:Captain-Dude,项目名称:the-blue-alliance,代码行数:17,代码来源:team_details_data_fetcher.py

示例3: addTeamDetails

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def addTeamDetails(self, team_dict, year):
        """
        Consume a Team dict, and return it with a year's Events filtered and Matches added
        """
        
        # TODO Matches should live under Events - gregmarra 1 feb 2011
        # TODO Filter Events by year - gregmarra 1 feb 2011
        
        memcache_key = "api_team_details_%s_%s" % (team_dict["key"], year)
        matches_list = memcache.get(memcache_key)
        if matches_list is None:
            matches = list()
            team = Team.get_by_id(team_dict["key"])
            for e in [a.event.get() for a in EventTeam.query(EventTeam.team == team.key).fetch(1000) if a.year == year]:
                match_list = Match.query(Match.event == event.key, Match.team_key_names == team.key_name).fetch(500)
                matches.extend(match_list)
            matches_list = list()
            for match in matches:
                match_dict = dict()
                match_dict["key"] = match.key_name
                match_dict["event"] = match.event
                match_dict["comp_level"] = match.comp_level
                match_dict["set_number"] = match.set_number
                match_dict["match_number"] = match.match_number
                match_dict["team_keys"] = match.team_key_names
                match_dict["alliances"] = json.loads(match.alliances_json)
                matches_list.append(match_dict)

            #TODO: Reduce caching time before 2013 season. 2592000 is one month -gregmarra
            if tba_config.CONFIG["memcache"]: memcache.set(memcache_key, matches_list, 2592000)

        team_dict["matches"] = matches_list
        return team_dict
开发者ID:germy,项目名称:the-blue-alliance,代码行数:35,代码来源:api_helper.py

示例4: getTeamInfo

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def getTeamInfo(self, team_key):
        """
        Return a Team dict with basic information.
        """
        memcache_key = "api_team_info_%s" % team_key
        team_dict = memcache.get(memcache_key)
        if team_dict is None:
            team = Team.get_by_id(team_key)
            if team is not None:
                team_dict = dict()
                team_dict["key"] = team.key_name
                team_dict["team_number"] = team.team_number
                team_dict["name"] = team.name
                team_dict["nickname"] = team.nickname
                team_dict["website"] = team.website
                team_dict["location"] = team.location

                event_teams = EventTeam.query(EventTeam.team == team.key,\
                                              EventTeam.year == datetime.now().year)\
                                              .fetch(1000, projection=[EventTeam.event])
                team_dict["events"] = [event_team.event.id() for event_team in event_teams]

                try:
                    team_dict["location"] = team.location
                    team_dict["locality"] = team.locality
                    team_dict["region"] = team.region
                    team_dict["country_name"] = team.country_name
                except Exception, e:
                    logging.warning("Failed to include Address for api_team_info_%s: %s" % (team_key, e))
                
                #TODO: Reduce caching time before 2013 season. 2592000 is one month -gregmarra 
                if tba_config.CONFIG["memcache"]: memcache.set(memcache_key, team_dict, 2592000)
            else:
                raise IndexError
开发者ID:germy,项目名称:the-blue-alliance,代码行数:36,代码来源:api_helper.py

示例5: get_event_cache_keys_and_controllers

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def get_event_cache_keys_and_controllers(cls, affected_refs):
        """
        Gets cache keys and controllers that references this event
        """
        event_keys = affected_refs["key"]
        years = affected_refs["year"]
        event_district_abbrevs = affected_refs["event_district_abbrev"]

        event_team_keys_future = EventTeam.query(
            EventTeam.event.IN([event_key for event_key in event_keys])
        ).fetch_async(None, keys_only=True)

        team_keys = set()
        for et_key in event_team_keys_future.get_result():
            team_key_name = et_key.id().split("_")[1]
            team_keys.add(ndb.Key(Team, team_key_name))

        return (
            cls._get_events_cache_keys_and_controllers(event_keys)
            + cls._get_event_district_points_cache_keys_and_controllers(event_keys)
            + cls._get_eventlist_cache_keys_and_controllers(years)
            + cls._get_team_events_cache_keys_and_controllers(team_keys, years)
            + cls._get_districtlist_cache_keys_and_controllers(years)
            + cls._get_district_events_cache_keys_and_controllers(event_district_abbrevs, years)
            + cls._get_district_rankings_cache_keys_and_controllers(event_district_abbrevs, years)
        )
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:28,代码来源:cache_clearer.py

示例6: team_updated

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
def team_updated(affected_refs):
    team_keys = _filter(affected_refs['key'])

    event_team_keys_future = EventTeam.query(EventTeam.team.IN([team_key for team_key in team_keys])).fetch_async(None, keys_only=True)
    district_team_keys_future = DistrictTeam.query(DistrictTeam.team.IN([team_key for team_key in team_keys])).fetch_async(None, keys_only=True)

    queries_and_keys = []
    for team_key in team_keys:
        queries_and_keys.append((TeamQuery(team_key.id())))
        page_num = _get_team_page_num(team_key.id())
        queries_and_keys.append((TeamListQuery(page_num)))

    for et_key in event_team_keys_future.get_result():
        year = int(et_key.id()[:4])
        event_key = et_key.id().split('_')[0]
        page_num = _get_team_page_num(et_key.id().split('_')[1])
        queries_and_keys.append((TeamListYearQuery(year, page_num)))
        queries_and_keys.append((EventTeamsQuery(event_key)))
        queries_and_keys.append((EventEventTeamsQuery(event_key)))

    for dt_key in district_team_keys_future.get_result():
        district_key = dt_key.id().split('_')[0]
        queries_and_keys.append((DistrictTeamsQuery(district_key)))

    return queries_and_keys
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:27,代码来源:get_affected_queries.py

示例7: get

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def get(self, team_number):
        self._require_admin()

        team = Team.get_by_id("frc" + team_number)
        event_teams = EventTeam.query(EventTeam.team == team.key).fetch(500)
        team_medias = Media.query(Media.references == team.key).fetch(500)
        robots = Robot.query(Robot.team == team.key).fetch()
        district_teams = DistrictTeam.query(DistrictTeam.team == team.key).fetch()

        team_medias_by_year = {}
        for media in team_medias:
            if media.year in team_medias_by_year:
                team_medias_by_year[media.year].append(media)
            else:
                team_medias_by_year[media.year] = [media]

        self.template_values.update({
            'event_teams': event_teams,
            'team': team,
            'team_medias_by_year': team_medias_by_year,
            'robots': robots,
            'district_teams': district_teams,
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/team_details.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:28,代码来源:admin_team_controller.py

示例8: event_updated

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
def event_updated(affected_refs):
    event_keys = _filter(affected_refs['key'])
    years = _filter(affected_refs['year'])
    event_district_keys = _filter(affected_refs['district_key'])

    event_team_keys_future = EventTeam.query(EventTeam.event.IN([event_key for event_key in event_keys])).fetch_async(None, keys_only=True)
    events_future = ndb.get_multi_async(event_keys)

    queries_and_keys = []
    for event_key in event_keys:
        queries_and_keys.append((EventQuery(event_key.id())))
        queries_and_keys.append(EventDivisionsQuery(event_key.id()))

    for year in years:
        queries_and_keys.append((EventListQuery(year)))

    for event_district_key in event_district_keys:
        queries_and_keys.append((DistrictEventsQuery(event_district_key.id())))

    if event_keys:
        for et_key in event_team_keys_future.get_result():
            team_key = et_key.id().split('_')[1]
            year = int(et_key.id()[:4])
            queries_and_keys.append((TeamEventsQuery(team_key)))
            queries_and_keys.append((TeamYearEventsQuery(team_key, year)))
            queries_and_keys.append((TeamYearEventTeamsQuery(team_key, year)))

    events_with_parents = filter(lambda e: e.get_result() is not None and e.get_result().parent_event is not None, events_future)
    parent_keys = set([e.get_result().parent_event for e in events_with_parents])
    for parent_key in parent_keys:
        queries_and_keys.append((EventDivisionsQuery(parent_key.id())))

    return queries_and_keys
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:35,代码来源:get_affected_queries.py

示例9: get

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def get(self, team_number):
        self._require_admin()

        team = Team.get_by_id("frc" + team_number)
        if not team:
            self.abort(404)
        event_teams = EventTeam.query(EventTeam.team == team.key).fetch(500)
        team_medias = Media.query(Media.references == team.key).fetch(500)
        robots = Robot.query(Robot.team == team.key).fetch()
        district_teams = DistrictTeam.query(DistrictTeam.team == team.key).fetch()
        years_participated = sorted(TeamParticipationQuery(team.key_name).fetch())

        team_medias_by_year = {}
        for media in team_medias:
            if media.year in team_medias_by_year:
                team_medias_by_year[media.year].append(media)
            else:
                team_medias_by_year[media.year] = [media]
        media_years = sorted(team_medias_by_year.keys(), reverse=True)

        self.template_values.update({
            'event_teams': event_teams,
            'team': team,
            'team_media_years': media_years,
            'team_medias_by_year': team_medias_by_year,
            'robots': robots,
            'district_teams': district_teams,
            'years_participated': years_participated,
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/team_details.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:34,代码来源:admin_team_controller.py

示例10: media_updated

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
def media_updated(affected_refs):
    reference_keys = _filter(affected_refs['references'])
    years = _filter(affected_refs['year'])
    media_tags = _filter(affected_refs['media_tag_enum'])

    team_keys = filter(lambda x: x.kind() == 'Team', reference_keys)
    event_team_keys_future = EventTeam.query(EventTeam.team.IN(team_keys)).fetch_async(None, keys_only=True) if team_keys else None

    queries_and_keys = []
    for reference_key in reference_keys:
        if reference_key.kind() == 'Team':
            for year in years:
                queries_and_keys.append((TeamYearMediaQuery(reference_key.id(), year)))
                for media_tag in media_tags:
                    queries_and_keys.append((TeamYearTagMediasQuery(reference_key.id(), media_tag, year)))
            for media_tag in media_tags:
                queries_and_keys.append((TeamTagMediasQuery(reference_key.id(), media_tag)))
            queries_and_keys.append((TeamSocialMediaQuery(reference_key.id())))
        if reference_key.kind() == 'Event':
            queries_and_keys.append((EventMediasQuery(reference_key.id())))

    if event_team_keys_future:
        for event_team_key in event_team_keys_future.get_result():
            event_key = event_team_key.id().split('_')[0]
            year = int(event_key[:4])
            if year in years:
                queries_and_keys.append(EventTeamsMediasQuery(event_key))
                queries_and_keys.append(EventTeamsPreferredMediasQuery(event_key))

    return queries_and_keys
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:32,代码来源:get_affected_queries.py

示例11: update

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def update(self, event_key):
        """
        Updates EventTeams for an event.
        Returns a tuple of (teams, event_teams, event_team_keys_to_delete)
        An EventTeam is valid iff the team:
        a) played a match at the event,
        b) the team received an award at the event,
        c) or the event has not yet occurred.
        """
        event = Event.get_by_id(event_key)

        # Add teams from Matches and Awards
        team_ids = set()
        match_key_futures = Match.query(
            Match.event == event.key).fetch_async(1000, keys_only=True)
        award_key_futures = Award.query(
            Award.event == event.key).fetch_async(1000, keys_only=True)
        match_futures = ndb.get_multi_async(match_key_futures.get_result())
        award_futures = ndb.get_multi_async(award_key_futures.get_result())

        for match_future in match_futures:
            match = match_future.get_result()
            for team in match.team_key_names:
                team_ids.add(team)
        for award_future in award_futures:
            award = award_future.get_result()
            for team_key in award.team_list:
                team_ids.add(team_key.id())

        # Create or update EventTeams
        teams = [Team(id=team_id,
                      team_number=int(team_id[3:]))
                      for team_id in team_ids]

        if teams:
            event_teams = [EventTeam(id=event_key + "_" + team.key.id(),
                                     event=event.key,
                                     team=team.key,
                                     year=event.year)
                                     for team in teams]
        else:
            event_teams = None

        # Delete EventTeams for teams who did not participate in the event
        # Only runs if event is over
        existing_event_teams_keys = EventTeam.query(
            EventTeam.event == event.key).fetch(1000, keys_only=True)
        existing_event_teams = ndb.get_multi(existing_event_teams_keys)
        existing_team_ids = set()
        for et in existing_event_teams:
            existing_team_ids.add(et.team.id())

        et_keys_to_delete = set()
        if event.end_date is not None and event.end_date < datetime.datetime.now():
            for team_id in existing_team_ids.difference(team_ids):
                et_key_name = "{}_{}".format(event.key_name, team_id)
                et_keys_to_delete.add(ndb.Key(EventTeam, et_key_name))
            ndb.delete_multi(et_keys_to_delete)

        return teams, event_teams, et_keys_to_delete
开发者ID:linuxuser0,项目名称:the-blue-alliance,代码行数:62,代码来源:event_team_updater.py

示例12: get_event_details_cache_keys_and_controllers

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def get_event_details_cache_keys_and_controllers(cls, affected_refs):
        """
        Gets cache keys and controllers that references this EventDetails

        TODO: Currently inefficient and also clears event APIv2 endpoints,
        since alliances are served under the event.
        APIv3 will break alliances out.
        """
        event_details_keys = affected_refs['key']
        event_keys = set()
        years = set()
        event_district_abbrevs = set()
        for event_details_key in event_details_keys:
            event_key = ndb.Key(Event, event_details_key.id())
            event_keys.add(event_key)

            event = event_key.get()
            years.add(event.year)
            event_district_abbrevs.add(event.event_district_abbrev)

        event_team_keys_future = EventTeam.query(EventTeam.event.IN([event_key for event_key in event_keys])).fetch_async(None, keys_only=True)

        team_keys = set()
        for et_key in event_team_keys_future.get_result():
            team_key_name = et_key.id().split('_')[1]
            team_keys.add(ndb.Key(Team, team_key_name))

        return cls._get_events_cache_keys_and_controllers(event_keys) + \
            cls._get_event_district_points_cache_keys_and_controllers(event_keys) + \
            cls._get_eventlist_cache_keys_and_controllers(years) + \
            cls._get_team_events_cache_keys_and_controllers(team_keys, years) + \
            cls._get_districtlist_cache_keys_and_controllers(years) + \
            cls._get_district_events_cache_keys_and_controllers(event_district_abbrevs, years) + \
            cls._get_district_rankings_cache_keys_and_controllers(event_district_abbrevs, years)
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:36,代码来源:cache_clearer.py

示例13: event_updated

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
def event_updated(affected_refs):
    event_keys = filter(None, affected_refs["key"])
    years = filter(None, affected_refs["year"])
    event_district_keys = filter(None, affected_refs["event_district_key"])

    event_team_keys_future = EventTeam.query(EventTeam.event.IN([event_key for event_key in event_keys])).fetch_async(
        None, keys_only=True
    )

    queries_and_keys = []
    for event_key in event_keys:
        queries_and_keys.append((EventQuery(event_key.id())))

    for year in years:
        queries_and_keys.append((EventListQuery(year)))

    for event_district_key in event_district_keys:
        queries_and_keys.append((DistrictEventsQuery(event_district_key)))

    for et_key in event_team_keys_future.get_result():
        team_key = et_key.id().split("_")[1]
        year = int(et_key.id()[:4])
        queries_and_keys.append((TeamEventsQuery(team_key)))
        queries_and_keys.append((TeamYearEventsQuery(team_key, year)))

    return queries_and_keys
开发者ID:nwalters512,项目名称:the-blue-alliance,代码行数:28,代码来源:get_affected_queries.py

示例14: _render

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
    def _render(self, team_number):
        team = Team.get_by_id("frc" + team_number)

        if not team:
            return self.redirect("/error/404")

        event_team_keys_future = EventTeam.query(EventTeam.team == team.key).fetch_async(1000, keys_only=True)
        award_keys_future = Award.query(Award.team == team.key).fetch_async(1000, keys_only=True)

        event_teams_futures = ndb.get_multi_async(event_team_keys_future.get_result())
        awards_futures = ndb.get_multi_async(award_keys_future.get_result())

        event_keys = [event_team_future.get_result().event for event_team_future in event_teams_futures]
        events_futures = ndb.get_multi_async(event_keys)

        awards_by_event = {}
        for award_future in awards_futures:
            award = award_future.get_result()
            if award.event.id() not in awards_by_event:
                awards_by_event[award.event.id()] = [award]
            else:
                awards_by_event[award.event.id()].append(award)

        event_awards = []
        current_event = None
        matches_upcoming = None
        short_cache = False
        for event_future in events_futures:
            event = event_future.get_result()
            if event.now:
                current_event = event

                team_matches_future = Match.query(Match.event == event.key, Match.team_key_names == team.key_name)\
                  .fetch_async(500, keys_only=True)
                matches = ndb.get_multi(team_matches_future.get_result())
                matches_upcoming = MatchHelper.upcomingMatches(matches)

            if event.within_a_day:
                short_cache = True

            if event.key_name in awards_by_event:
                sorted_awards = AwardHelper.organizeAwards(awards_by_event[event.key_name])['list']
            else:
                sorted_awards = []
            event_awards.append((event, sorted_awards))
        event_awards = sorted(event_awards, key=lambda (e, _): e.start_date if e.start_date else datetime.datetime(e.year, 12, 31))

        years = sorted(set([et.get_result().year for et in event_teams_futures if et.get_result().year != None]))

        template_values = {'team': team,
                           'event_awards': event_awards,
                           'years': years,
                           'current_event': current_event,
                           'matches_upcoming': matches_upcoming}

        if short_cache:
            self._cache_expiration = self.SHORT_CACHE_EXPIRATION

        path = os.path.join(os.path.dirname(__file__), '../templates/team_history.html')
        return template.render(path, template_values)
开发者ID:chrismarra,项目名称:the-blue-alliance,代码行数:62,代码来源:team_controller.py

示例15: prepTeams

# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import query [as 别名]
 def prepTeams(self):
     # TODO there is a way to do this with yields such that this would be a
     # generator function that would yield, and if two sets of ndb fetches
     # went by would cleanly do itself without forcing a fetch.
     # -gregmarra 20121007
     from models.event_team import EventTeam
     if self._teams_future is None:
         self._event_teams_future = EventTeam.query(EventTeam.event == self.key).fetch_async(500)
开发者ID:dweitz,项目名称:the-blue-alliance,代码行数:10,代码来源:event.py


注:本文中的models.event_team.EventTeam.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。