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


Python award_manipulator.AwardManipulator类代码示例

本文整理汇总了Python中helpers.award_manipulator.AwardManipulator的典型用法代码示例。如果您正苦于以下问题:Python AwardManipulator类的具体用法?Python AwardManipulator怎么用?Python AwardManipulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: post

 def post(self):
     event_key = self.request.get('event_key')
     awards_json = self.request.get('awards_json')
     awards = json.loads(awards_json)
     
     event = Event.get_by_id(event_key)
     
     def _getTeamKey(award):
         team = Team.get_by_id('frc' + str(award.get('team_number', None)))
         if team is not None:
             return team.key
         else:
             return None
    
     awards = [Award(
         id = Award.renderKeyName(event.key_name, award.get('name')),
         name = award.get('name', None),
         team = _getTeamKey(award),
         awardee = award.get('awardee', None),
         year = event.year,
         official_name = award.get('official_name', None),
         event = event.key)
         for award in awards]
     
     AwardManipulator.createOrUpdate(awards)
     self.redirect('/admin/event/{}'.format(event_key))
开发者ID:dweitz,项目名称:the-blue-alliance,代码行数:26,代码来源:admin_award_controller.py

示例2: _process_request

    def _process_request(self, request, event_key):
        event = Event.get_by_id(event_key)

        awards = []
        for award in JSONAwardsParser.parse(request.body, event_key):
            awards.append(Award(
                id=Award.render_key_name(event.key_name, award['award_type_enum']),
                name_str=award['name_str'],
                award_type_enum=award['award_type_enum'],
                year=event.year,
                event=event.key,
                event_type_enum=event.event_type_enum,
                team_list=[ndb.Key(Team, team_key) for team_key in award['team_key_list']],
                recipient_json_list=award['recipient_json_list']
            ))

        # it's easier to clear all awards and add new ones than try to find the difference
        old_award_keys = Award.query(Award.event == event.key).fetch(None, keys_only=True)
        AwardManipulator.delete_keys(old_award_keys)

        if event.remap_teams:
            EventHelper.remapteams_awards(awards, event.remap_teams)
        AwardManipulator.createOrUpdate(awards)

        self.response.out.write(json.dumps({'Success': "Awards successfully updated"}))
开发者ID:legoktm,项目名称:the-blue-alliance,代码行数:25,代码来源:api_trusted_controller.py

示例3: get

    def get(self, event_key):
        event = Event.get_by_id(event_key)
        if not event:
            self.abort(404)

        if not event.remap_teams:
            return

        event.prepAwardsMatchesTeams()

        # Remap matches
        EventHelper.remapteams_matches(event.matches, event.remap_teams)
        MatchManipulator.createOrUpdate(event.matches)

        # Remap alliance selections
        if event.alliance_selections:
            EventHelper.remapteams_alliances(event.alliance_selections, event.remap_teams)
        # Remap rankings
        if event.rankings:
            EventHelper.remapteams_rankings(event.rankings, event.remap_teams)
        if event.details and event.details.rankings2:
            EventHelper.remapteams_rankings2(event.details.rankings2, event.remap_teams)
        EventDetailsManipulator.createOrUpdate(event.details)

        # Remap awards
        EventHelper.remapteams_awards(event.awards, event.remap_teams)
        AwardManipulator.createOrUpdate(event.awards, auto_union=False)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:27,代码来源:cron_controller.py

示例4: post

    def post(self):
        award_key = self.request.get('award_key')
        if not award_key:
            self.abort(400)
        award = Award.get_by_id(award_key)
        if not award:
            self.abort(404)

        AwardManipulator.delete(award)
        self.redirect('/admin/awards')
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:10,代码来源:admin_award_controller.py

示例5: add_awards_from_csv

    def add_awards_from_csv(cls, awards_csv):
        events = {}  # for reducing datastore fetches of events and teams
        awards = []
        for award in CSVAwardsParser.parse(awards_csv):
            event_key_name = '{}{}'.format(award['year'], award['event_short'])
            if event_key_name in events:
                event = events[event_key_name]
            else:
                event = Event.get_by_id(event_key_name)
                if event is None:
                    logging.warning("Event: {} doesn't exist!".format(event_key_name))
                    continue
                events[event_key_name] = event

            awards.append(Award(
                id=Award.render_key_name(event.key_name, award['award_type_enum']),
                name_str=award['name_str'],
                award_type_enum=award['award_type_enum'],
                year=event.year,
                event=event.key,
                event_type_enum=event.event_type_enum,
                team_list=[ndb.Key(Team, 'frc{}'.format(team_number)) for team_number in award['team_number_list']],
                recipient_json_list=award['recipient_json_list']
            ))

        new_awards = AwardManipulator.createOrUpdate(awards)
        if type(new_awards) != list:
            new_awards = [new_awards]
        return new_awards
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:29,代码来源:admin_award_controller.py

示例6: get

    def get(self, event_key):
        datafeed = DatafeedUsfirst()

        event = Event.get_by_id(event_key)
        new_awards = AwardManipulator.createOrUpdate(datafeed.getEventAwards(event))
        if type(new_awards) != list:
            new_awards = [new_awards]

        # create EventTeams
        team_ids = set()
        for award in new_awards:
            for team in award.team_list:
                team_ids.add(team.id())
        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])

        template_values = {
            'awards': new_awards,
        }

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

示例7: get

    def get(self, event_key):
        # Fetch for later
        event_future = Event.get_by_id_async(event_key)
        matches_future = match_query.EventMatchesQuery(event_key).fetch_async()

        # Rebuild event teams
        taskqueue.add(
            url='/tasks/math/do/eventteam_update/' + event_key,
            method='GET')

        # Create Winner/Finalist awards for offseason events
        awards = []
        event = event_future.get_result()
        if event.event_type_enum in {EventType.OFFSEASON, EventType.FOC}:
            matches = MatchHelper.organizeMatches(matches_future.get_result())
            bracket = MatchHelper.generateBracket(matches, event, event.alliance_selections)
            if 'f' in bracket:
                winning_alliance = '{}_alliance'.format(bracket['f'][1]['winning_alliance'])
                if winning_alliance == 'red_alliance':
                    losing_alliance = 'blue_alliance'
                else:
                    losing_alliance = 'red_alliance'

                awards.append(Award(
                    id=Award.render_key_name(event.key_name, AwardType.WINNER),
                    name_str="Winner",
                    award_type_enum=AwardType.WINNER,
                    year=event.year,
                    event=event.key,
                    event_type_enum=event.event_type_enum,
                    team_list=[ndb.Key(Team, 'frc{}'.format(team)) for team in bracket['f'][1][winning_alliance] if team.isdigit()],
                    recipient_json_list=[json.dumps({'team_number': team, 'awardee': None}) for team in bracket['f'][1][winning_alliance]],
                ))

                awards.append(Award(
                    id=Award.render_key_name(event.key_name, AwardType.FINALIST),
                    name_str="Finalist",
                    award_type_enum=AwardType.FINALIST,
                    year=event.year,
                    event=event.key,
                    event_type_enum=event.event_type_enum,
                    team_list=[ndb.Key(Team, 'frc{}'.format(team)) for team in bracket['f'][1][losing_alliance] if team.isdigit()],
                    recipient_json_list=[json.dumps({'team_number': team, 'awardee': None}) for team in bracket['f'][1][losing_alliance]],
                ))
                AwardManipulator.createOrUpdate(awards)

        self.response.out.write("Finished post-event tasks for {}. Created awards: {}".format(event_key, awards))
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:47,代码来源:admin_cron_controller.py

示例8: get

    def get(self, event_key):
        datafeed = DatafeedUsfirst()

        event = Event.get_by_id(event_key)
        new_awards = AwardManipulator.createOrUpdate(datafeed.getEventAwards(event))

        template_values = {
            'awards': new_awards,
        }

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

示例9: store_award

def store_award(data, event):
    award = Award(id=Award.render_key_name(data['event_key'], data['award_type']))
    award.event = ndb.Key(Event, data['event_key'])
    award.award_type_enum = data['award_type']
    award.year = data['year']
    award.name_str = data['name']
    award.event_type_enum = event.event_type_enum

    recipient_list_fixed = []
    team_keys = []
    for recipient in data['recipient_list']:
        if recipient['team_key']:
            team_keys.append(ndb.Key(Team, recipient['team_key']))
        recipient_list_fixed.append(json.dumps({
            'awardee': recipient['awardee'],
            'team_number': int(recipient['team_key'][3:]) if recipient['team_key'] else None,
        }))
    award.recipient_json_list = recipient_list_fixed
    return AwardManipulator.createOrUpdate(award)
开发者ID:fangeugene,项目名称:the-blue-alliance,代码行数:19,代码来源:bootstrap.py

示例10: get

    def get(self, event_key):
        datafeed = DatafeedFMSAPI('v2.0', save_response=True)

        event = Event.get_by_id(event_key)
        awards = datafeed.getAwards(event)

        if event and event.remap_teams:
            EventHelper.remapteams_awards(awards, event.remap_teams)

        new_awards = AwardManipulator.createOrUpdate(awards)

        if new_awards is None:
            new_awards = []
        elif type(new_awards) != list:
            new_awards = [new_awards]

        # create EventTeams
        team_ids = set()
        for award in new_awards:
            for team in award.team_list:
                team_ids.add(team.id())
        teams = TeamManipulator.createOrUpdate([Team(
            id=team_id,
            team_number=int(team_id[3:]))
            for team_id in team_ids])
        if teams:
            if type(teams) is not list:
                teams = [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])

        template_values = {
            'awards': new_awards,
        }

        if 'X-Appengine-Taskname' not in self.request.headers:  # Only write out if not in taskqueue
            path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_awards_get.html')
            self.response.out.write(template.render(path, template_values))
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:42,代码来源:datafeed_controller.py

示例11: post

    def post(self, award_key):
        self._require_admin()

        event_key_name = self.request.get('event_key_name')

        recipient_json_list = []
        team_list = []
        for recipient in json.loads(self.request.get('recipient_list_json')):
            recipient_json_list.append(json.dumps(recipient))
            if recipient['team_number'] is not None:
                team_list.append(ndb.Key(Team, 'frc{}'.format(recipient['team_number'])))

        award = Award(
            id=award_key,
            name_str=self.request.get('name_str'),
            award_type_enum=int(self.request.get('award_type_enum')),
            event=ndb.Key(Event, event_key_name),
            event_type_enum=int(self.request.get('event_type_enum')),
            team_list=team_list,
            recipient_json_list=recipient_json_list,
        )
        award = AwardManipulator.createOrUpdate(award, auto_union=False)
        self.redirect("/admin/event/" + event_key_name)
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:23,代码来源:admin_award_controller.py

示例12: test_updateMerge_no_auto_union

 def test_updateMerge_no_auto_union(self):
     self.assertMergedAward(AwardManipulator.updateMerge(self.new_award, self.old_award, auto_union=False), False)
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:2,代码来源:test_award_manipulator.py

示例13: post

    def post(self, event_key_id):
        self._require_admin()
        event = Event.get_by_id(event_key_id)
        event.prepAwardsMatchesTeams()

        remap_teams = {}
        for key, value in json.loads(self.request.get('remap_teams')).items():
            remap_teams['frc{}'.format(key)] = 'frc{}'.format(value)

        # Remap matches
        for match in event.matches:
            for old_team, new_team in remap_teams.items():
                # Update team key names
                for i, key in enumerate(match.team_key_names):
                    if key == old_team:
                        match.dirty = True
                        if new_team.isdigit():  # Only if non "B" teams
                            match.team_key_names[i] = new_team
                        else:
                            del match.team_key_names[i]
                # Update alliances
                for color in ['red', 'blue']:
                    for i, key in enumerate(match.alliances[color]['teams']):
                        if key == old_team:
                            match.dirty = True
                            match.alliances[color]['teams'][i] = new_team
                            match.alliances_json = json.dumps(match.alliances)
        MatchManipulator.createOrUpdate(event.matches)

        # Remap alliance selections
        if event.alliance_selections:
            for row in event.alliance_selections:
                for choice in ['picks', 'declines']:
                    for old_team, new_team in remap_teams.items():
                        for i, key in enumerate(row[choice]):
                            if key == old_team:
                                row[choice][i] = new_team

        # Remap rankings
        if event.rankings:
            for row in event.rankings:
                for old_team, new_team in remap_teams.items():
                    if row[1] == old_team[3:]:
                        row[1] = new_team[3:]

        EventDetailsManipulator.createOrUpdate(event.details)

        # Remap awards
        for award in event.awards:
            for old_team, new_team in remap_teams.items():
                # Update team keys
                for i, key in enumerate(award.team_list):
                    if key.id() == old_team:
                        award.dirty = True
                        if new_team.isdigit():  # Only if non "B" teams
                            award.team_list[i] = ndb.Key(Team, new_team)
                        else:
                            del award.team_list[i]
                # Update recipient list
                for recipient in award.recipient_list:
                    if str(recipient['team_number']) == old_team[3:]:
                        award.dirty = True
                        recipient['team_number'] = new_team[3:]
                        award.recipient_json_list = [json.dumps(r) for r in award.recipient_list]
        AwardManipulator.createOrUpdate(event.awards, auto_union=False)

        self.redirect("/admin/event/" + event.key_name)
开发者ID:technonerdz,项目名称:the-blue-alliance,代码行数:67,代码来源:admin_event_controller.py

示例14: test_createOrUpdate_no_auto_union

    def test_createOrUpdate_no_auto_union(self):
        AwardManipulator.createOrUpdate(self.old_award)
        self.assertOldAward(Award.get_by_id("2013casj_1"))

        AwardManipulator.createOrUpdate(self.new_award, auto_union=False)
        self.assertMergedAward(Award.get_by_id("2013casj_1"), False)
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:6,代码来源:test_award_manipulator.py

示例15: test_updateMerge

 def test_updateMerge(self):
     self.assertMergedAward(AwardManipulator.updateMerge(self.new_award, self.old_award), True)
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:2,代码来源:test_award_manipulator.py


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