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


Python Match.query方法代码示例

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


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

示例1: getMatches

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
    def getMatches(self, event):
        matches_url = self.YEAR_MATCH_RESULTS_URL_PATTERN.get(
            event.year, self.DEFAULT_MATCH_RESULTS_URL_PATTERN) % (
                event.year, self.EVENT_SHORT_EXCEPTIONS.get(event.event_short,
                                                            event.event_short))

        match_dicts, _ = self.parse(matches_url, self.YEAR_MATCH_PARSER.get(event.year, self.DEFAULT_MATCH_PARSER))
        if not match_dicts:  # Matches have not been played, but qual match schedule may be out
            # If this is run when there are already matches in the DB, it will overwrite scores!
            # Check to make sure event has no existing matches
            if len(Match.query(Match.event == event.key).fetch(1, keys_only=True)) == 0:
                logging.warning("No matches found for {}. Trying to parse qual match schedule.".format(event.key.id()))

                qual_match_sched_url = self.MATCH_SCHEDULE_QUAL_URL_PATTERN % (
                    event.year, self.EVENT_SHORT_EXCEPTIONS.get(event.event_short,
                                                                event.event_short))
                match_dicts, _ = self.parse(qual_match_sched_url, self.MATCH_SCHEDULE_PARSER)

        for match_dict in match_dicts:
            alliances = json.loads(match_dict['alliances_json'])
            if (alliances['red']['score'] == -1 or alliances['blue']['score'] == -1 or
                match_dict['comp_level'] in Match.ELIM_LEVELS):
                break
        else:  # Only qual matches have been played and they have all been played
            # If this is run when there are already elim matches in the DB, it will overwrite scores!
            # Check to make sure event has no existing elim matches
            if len(Match.query(Match.event == event.key, Match.comp_level.IN(Match.ELIM_LEVELS)).fetch(1, keys_only=True)) == 0:
                logging.warning("No elim matches found for {}. Trying to parse elim match schedule.".format(event.key.id()))

                elim_match_sched_url = self.MATCH_SCHEDULE_ELIMS_URL_PATTERN % (
                    event.year, self.EVENT_SHORT_EXCEPTIONS.get(event.event_short,
                                                                event.event_short))
                elim_match_dicts, _ = self.parse(elim_match_sched_url, self.MATCH_SCHEDULE_PARSER)
                match_dicts += elim_match_dicts

        matches = [Match(
            id=Match.renderKeyName(
                event.key.id(),
                match_dict.get("comp_level", None),
                match_dict.get("set_number", 0),
                match_dict.get("match_number", 0)),
            event=event.key,
            game=Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
            set_number=match_dict.get("set_number", 0),
            match_number=match_dict.get("match_number", 0),
            comp_level=match_dict.get("comp_level", None),
            team_key_names=match_dict.get("team_key_names", None),
            time_string=match_dict.get("time_string", None),
            alliances_json=match_dict.get("alliances_json", None)
            )
            for match_dict in match_dicts]

        MatchHelper.add_match_times(event, matches)
        return matches
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:56,代码来源:datafeed_usfirst.py

示例2: test_2017scmb_sequence

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
    def test_2017scmb_sequence(self):
        event = Event(
            id='2017scmb',
            event_short='scmb',
            year=2017,
            event_type_enum=0,
            timezone_id='America/New_York'
        )
        event.put()

        event_code = 'scmb'

        file_prefix = 'frc-api-response/v2.0/2017/schedule/{}/playoff/hybrid/'.format(event_code)
        context = ndb.get_context()
        result = context.urlfetch('https://www.googleapis.com/storage/v1/b/bucket/o?bucket=tbatv-prod-hrd.appspot.com&prefix={}'.format(file_prefix)).get_result()

        for item in json.loads(result.content)['items']:
            filename = item['name']
            time_str = filename.replace(file_prefix, '').replace('.json', '').strip()
            file_time = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S.%f")
            query_time = file_time + datetime.timedelta(seconds=30)
            MatchManipulator.createOrUpdate(DatafeedFMSAPI('v2.0', sim_time=query_time).getMatches('2017{}'.format(event_code)), run_post_update_hook=False)
        MatchHelper.deleteInvalidMatches(event.matches, event)

        qf_matches = Match.query(Match.event == ndb.Key(Event, '2017scmb'), Match.comp_level == 'qf').fetch()
        self.assertEqual(len(qf_matches), 11)

        sf_matches = Match.query(Match.event == ndb.Key(Event, '2017scmb'), Match.comp_level == 'sf').fetch()
        self.assertEqual(len(sf_matches), 4)

        f_matches = Match.query(Match.event == ndb.Key(Event, '2017scmb'), Match.comp_level == 'f').fetch()
        self.assertEqual(len(f_matches), 3)

        self.assertEqual(Match.get_by_id('2017scmb_qf4m1').alliances['red']['score'], 305)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m1').alliances['blue']['score'], 305)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m1').score_breakdown['red']['totalPoints'], 305)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m1').score_breakdown['blue']['totalPoints'], 305)

        self.assertEqual(Match.get_by_id('2017scmb_qf4m2').alliances['red']['score'], 213)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m2').alliances['blue']['score'], 305)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m2').score_breakdown['red']['totalPoints'], 213)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m2').score_breakdown['blue']['totalPoints'], 305)

        self.assertEqual(Match.get_by_id('2017scmb_qf4m3').alliances['red']['score'], 312)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m3').alliances['blue']['score'], 255)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m3').score_breakdown['red']['totalPoints'], 312)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m3').score_breakdown['blue']['totalPoints'], 255)

        self.assertEqual(Match.get_by_id('2017scmb_qf4m4').alliances['red']['score'], 310)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m4').alliances['blue']['score'], 306)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m4').score_breakdown['red']['totalPoints'], 310)
        self.assertEqual(Match.get_by_id('2017scmb_qf4m4').score_breakdown['blue']['totalPoints'], 306)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:54,代码来源:test_fms_api_match_tiebreaker.py

示例3: update

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match 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

示例4: get_matches_async

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
 def get_matches_async(event_keys):
     if event_keys == []:
         raise ndb.Return([])
     match_keys = yield Match.query(
         Match.event.IN(event_keys), Match.team_key_names == team.key_name).fetch_async(500, keys_only=True)
     matches = yield ndb.get_multi_async(match_keys)
     raise ndb.Return(matches)
开发者ID:Captain-Dude,项目名称:the-blue-alliance,代码行数:9,代码来源:team_details_data_fetcher.py

示例5: get

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
    def get(self, event_key):
        event = Event.get_by_id(event_key)
        team_ids = set()
        
        # Add teams from Matches
        for match in Match.query(Match.event == event.key).fetch(1000):
            for team in match.team_key_names:
                team_ids.add(team)
        
        teams = TeamManipulator.createOrUpdate([Team(
            id = team_id,
            team_number = int(team_id[3:]))
            for team_id in team_ids])

        if teams:
            event_teams = EventTeamManipulator.createOrUpdate([EventTeam(
                id = event_key + "_" + team.key.id(),
                event = event.key,
                team = team.key,
                year = event.year)
                for team in teams])
        else:
            event_teams = None
        
        template_values = {
            'event_teams': event_teams,
        }
        
        path = os.path.join(os.path.dirname(__file__), '../templates/math/eventteam_update_do.html')
        self.response.out.write(template.render(path, template_values))
开发者ID:germy,项目名称:the-blue-alliance,代码行数:32,代码来源:cron_controller.py

示例6: addTeamDetails

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match 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

示例7: _render

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match 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

示例8: _query_async

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
 def _query_async(self):
     team_key = self._query_args[0]
     year = self._query_args[1]
     matches = yield Match.query(
         Match.team_key_names == team_key,
         Match.year == year).fetch_async()
     raise ndb.Return(matches)
开发者ID:cmlicata,项目名称:the-blue-alliance,代码行数:9,代码来源:match_query.py

示例9: _render

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
    def _render(self, team_key, event_key):
        match_keys_future = Match.query(Match.event == ndb.Key(Event, self.event_key), Match.team_key_names == self.team_key).fetch_async(None, keys_only=True)
        match_futures = ndb.get_multi_async(match_keys_future.get_result())

        matches = [ModelToDict.matchConverter(match_future.get_result()) for match_future in match_futures]

        return json.dumps(matches, ensure_ascii=True)
开发者ID:Captain-Dude,项目名称:the-blue-alliance,代码行数:9,代码来源:api_team_controller.py

示例10: get

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
    def get(self, year):
        year_event_keys = Event.query(Event.year == int(year)).fetch(1000, keys_only=True)

        final_match_keys = []
        for event_key in year_event_keys:
            final_match_keys.extend(Match.query(Match.event == event_key, Match.comp_level == 'f').fetch(100, keys_only=True))

        match_keys_to_repair = []
        for match_key in final_match_keys:
            key_name = match_key.id()
            if '_f0m' in key_name:
                match_keys_to_repair.append(match_key)

        deleted_keys = []
        matches_to_repair = ndb.get_multi(match_keys_to_repair)
        for match in matches_to_repair:
            deleted_keys.append(match.key)

            event = ndb.get_multi([match.event])[0]
            match.set_number = 1
            match.key = ndb.Key(Match, Match.renderKeyName(
                event.key.id(),
                match.comp_level,
                match.set_number,
                match.match_number))

        MatchManipulator.createOrUpdate(matches_to_repair)
        MatchManipulator.delete_keys(deleted_keys)

        template_values = {'deleted_keys': deleted_keys,
                           'new_matches': matches_to_repair}

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

示例11: post

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
    def post(self):
        self._require_registration()

        event_key = self.request.get("event_key")
        if not event_key:
            self.response.out.write("No event key found")
            return
        event_future = Event.get_by_id_async(event_key)
        event = event_future.get_result()
        if not event:
            self.response.out.write("Invalid event key {}".format(event_key))
            return

        match_futures = Match.query(Match.event == event.key).fetch_async(keys_only=True)
        valid_match_keys = [match.id() for match in match_futures.get_result()]

        num_videos = int(self.request.get("num_videos", 0))
        suggestions_added = 0
        for i in range(0, num_videos):
            yt_id = self.request.get("video_id_{}".format(i))
            match_partial = self.request.get("match_partial_{}".format(i))
            if not yt_id or not match_partial:
                continue

            match_key = "{}_{}".format(event_key, match_partial)
            if match_key not in valid_match_keys:
                continue

            status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.user_bundle.account.key, yt_id, match_key)
            if status == 'success':
                suggestions_added += 1

        self.redirect('/suggest/event/video?event_key={}&num_added={}'.format(event_key, suggestions_added))
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:35,代码来源:suggest_match_video_controller.py

示例12: _query_async

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
 def _query_async(self):
     team_key = self._query_args[0]
     event_key = self._query_args[1]
     match_keys = yield Match.query(
         Match.team_key_names == team_key,
         Match.event == ndb.Key(Event, event_key)).fetch_async(keys_only=True)
     matches = yield ndb.get_multi_async(match_keys)
     raise ndb.Return(matches)
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:10,代码来源:match_query.py

示例13: get

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
 def get(self):
     match_count = Match.query().count()
     
     template_values = {
         "match_count": match_count
     }
     
     path = os.path.join(os.path.dirname(__file__), '../../templates/admin/match_dashboard.html')
     self.response.out.write(template.render(path, template_values))
开发者ID:dweitz,项目名称:the-blue-alliance,代码行数:11,代码来源:admin_match_controller.py

示例14: _process_request

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
    def _process_request(self, request, event_key):
        if request.body != event_key:
            self._errors = json.dumps({"Error": "To delete all matches for this event, the body of the request must be the event key."})
            self.abort(400)

        keys_to_delete = Match.query(Match.event == ndb.Key(Event, event_key)).fetch(keys_only=True)
        MatchManipulator.delete_keys(keys_to_delete)

        self.response.out.write(json.dumps({'Success': "All matches for {} deleted".format(event_key)}))
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:11,代码来源:api_trusted_controller.py

示例15: get

# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import query [as 别名]
 def get(self):
     self._require_admin()
     match_count = Match.query().count()
     
     self.template_values.update({
         "match_count": match_count
     })
     
     path = os.path.join(os.path.dirname(__file__), '../../templates/admin/match_dashboard.html')
     self.response.out.write(template.render(path, self.template_values))
开发者ID:lyncas,项目名称:the-blue-alliance,代码行数:12,代码来源:admin_match_controller.py


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