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)
Example #2
0
    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)
 def test_remapteams_matches(self):
     matches = [
         Match(
             id="2019casj_qm1",
             alliances_json=
             """{"blue": {"score": 100, "teams": ["frc1", "frc2", "frc3"]}, "red": {"score": 200, "teams": ["frc4", "frc5", "frc9001"]}}""",
         )
     ]
     EventHelper.remapteams_matches(matches, self.remap_teams)
     self.assertEqual(matches[0].alliances['blue']['teams'],
                      ['frc1', 'frc200', 'frc3'])
     self.assertEqual(
         set(matches[0].team_key_names),
         set(['frc4', 'frc5', 'frc1B', 'frc1', 'frc200', 'frc3']))
Example #4
0
    def get(self, event_key):
        df = DatafeedFMSAPI('v2.0', save_response=True)
        event = Event.get_by_id(event_key)

        matches = MatchHelper.deleteInvalidMatches(df.getMatches(event_key),
                                                   Event.get_by_id(event_key))

        if event and event.remap_teams:
            EventHelper.remapteams_matches(matches, event.remap_teams)

        new_matches = MatchManipulator.createOrUpdate(matches)

        template_values = {
            'matches': new_matches,
        }

        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_matches_get.html')
            self.response.out.write(template.render(path, template_values))
    def get(self, event_key):
        df = DatafeedFMSAPI('v2.0', save_response=True)
        event = Event.get_by_id(event_key)

        matches = MatchHelper.deleteInvalidMatches(
            df.getMatches(event_key),
            Event.get_by_id(event_key)
        )

        if event and event.remap_teams:
            EventHelper.remapteams_matches(matches, event.remap_teams)

        new_matches = MatchManipulator.createOrUpdate(matches)

        template_values = {
            'matches': new_matches,
        }

        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_matches_get.html')
            self.response.out.write(template.render(path, template_values))
Example #6
0
class ApiTrustedEventMatchesUpdate(ApiTrustedBaseController):
    """
    Creates/updates matches
    """
    REQUIRED_AUTH_TYPES = {AuthType.EVENT_MATCHES}

    def _process_request(self, request, event_key):
        event = Event.get_by_id(event_key)
        year = int(event_key[:4])

        matches = []
        needs_time = []
        for match in JSONMatchesParser.parse(request.body, year):
            match = Match(
                id=Match.renderKeyName(event.key.id(),
                                       match.get("comp_level", None),
                                       match.get("set_number", 0),
                                       match.get("match_number", 0)),
                event=event.key,
                year=event.year,
                set_number=match.get("set_number", 0),
                match_number=match.get("match_number", 0),
                comp_level=match.get("comp_level", None),
                team_key_names=match.get("team_key_names", None),
                alliances_json=match.get("alliances_json", None),
                score_breakdown_json=match.get("score_breakdown_json", None),
                time_string=match.get("time_string", None),
                time=match.get("time", None),
            )

            if (not match.time or match.time == "") and match.time_string:
                # We can calculate the real time from the time string
                needs_time.append(match)
            matches.append(match)

        if needs_time:
            try:
                logging.debug("Calculating time!")
                MatchHelper.add_match_times(event, needs_time)
            except Exception, e:
                logging.error("Failed to calculate match times")

        if event.remap_teams:
            EventHelper.remapteams_matches(matches, event.remap_teams)
        MatchManipulator.createOrUpdate(matches)

        self.response.out.write(
            json.dumps({'Success': "Matches successfully updated"}))