def get(self, key_name):
        # Combines data from three datafeeds with priorities:
        # 1) DatafeedFMSAPI
        # 2) DatafeedUsfirst (missing rookie year)
        # 3) DatafeedUsfirstLegacy (has all info)

        legacy_df = DatafeedUsfirstLegacy()
        usfirst_df = DatafeedUsfirst()
        fms_df = DatafeedFMSAPI('v2.0')

        # Start with lowest priority
        legacy_team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
        usfirst_team = usfirst_df.getTeamDetails(Team.get_by_id(key_name))
        fms_details = fms_df.getTeamDetails(tba_config.MAX_YEAR, key_name)

        # Separate out the multiple models returned from FMSAPI call
        # Since we're only hitting one team at a time, the response won't
        # ever be paginated so we can ignore the possibility
        if fms_details and fms_details[0]:
            models, more_pages = fms_details
            fms_team, district_team, robot = models[0]
        else:
            fms_team = None
            district_team = None
            robot = None

        team = None
        if usfirst_team:
            team = TeamManipulator.updateMergeBase(usfirst_team, legacy_team)
        if fms_team:
            team = TeamManipulator.updateMergeBase(fms_team, team)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(
                district_team)
        if robot:
            robot = RobotManipulator.createOrUpdate(robot)
        if team:
            team = TeamManipulator.createOrUpdate(team)
            success = True
        else:
            success = False
            logging.warning(
                "getTeamDetails failed for team: {}".format(key_name))

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': success,
            'district': district_team,
            'robot': robot,
        }

        path = os.path.join(
            os.path.dirname(__file__),
            '../templates/datafeeds/usfirst_team_details_get.html')
        self.response.out.write(template.render(path, template_values))
    def get(self):
        df = DatafeedFms()
        teams = df.getFmsTeamList()
        TeamManipulator.createOrUpdate(teams)

        template_values = {"teams": teams}

        path = os.path.join(os.path.dirname(__file__),
                            '../templates/datafeeds/fms_team_list_get.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 3
0
    def get(self, key_name):
        existing_team = Team.get_by_id(key_name)

        fms_df = DatafeedFMSAPI('v2.0')
        df2 = DatafeedFIRSTElasticSearch()
        year = datetime.date.today().year
        fms_details = fms_df.getTeamDetails(year, key_name)

        if fms_details:
            team, district_team, robot = fms_details[0]
        else:
            team = None
            district_team = None
            robot = None

        if team:
            team = TeamManipulator.mergeModels(
                team, df2.getTeamDetails(existing_team))
        else:
            team = df2.getTeamDetails(existing_team)

        if team:
            team = TeamManipulator.createOrUpdate(team)

        # Clean up junk district teams
        # https://www.facebook.com/groups/moardata/permalink/1310068625680096/
        dt_keys = DistrictTeam.query(
            DistrictTeam.team == existing_team.key,
            DistrictTeam.year == year).fetch(keys_only=True)
        keys_to_delete = set()
        for dt_key in dt_keys:
            if not district_team or dt_key.id() != district_team.key.id():
                keys_to_delete.add(dt_key)
        DistrictTeamManipulator.delete_keys(keys_to_delete)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(
                district_team)

        if robot:
            robot = RobotManipulator.createOrUpdate(robot)

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': team is not None,
            'district': district_team,
            'robot': robot,
        }

        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_team_details_get.html')
            self.response.out.write(template.render(path, template_values))
    def get(self):
        df = DatafeedFms()
        teams = df.getFmsTeamList()
        TeamManipulator.createOrUpdate(teams)

        template_values = {
            "teams": teams
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/fms_team_list_get.html')
        self.response.out.write(template.render(path, template_values))
    def get(self, key_name):
        # Combines data from three datafeeds with priorities:
        # 1) DatafeedFMSAPI
        # 2) DatafeedUsfirst (missing rookie year)
        # 3) DatafeedUsfirstLegacy (has all info)

        legacy_df = DatafeedUsfirstLegacy()
        usfirst_df = DatafeedUsfirst()
        fms_df = DatafeedFMSAPI('v2.0')

        # Start with lowest priority
        legacy_team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
        usfirst_team = usfirst_df.getTeamDetails(Team.get_by_id(key_name))
        fms_details = fms_df.getTeamDetails(tba_config.MAX_YEAR, key_name)

        # Separate out the multiple models returned from FMSAPI call
        # Since we're only hitting one team at a time, the response won't
        # ever be paginated so we can ignore the possibility
        if fms_details and fms_details[0]:
            models, more_pages = fms_details
            fms_team, district_team, robot = models[0]
        else:
            fms_team = None
            district_team = None
            robot = None

        team = None
        if usfirst_team:
            team = TeamManipulator.updateMergeBase(usfirst_team, legacy_team)
        if fms_team:
            team = TeamManipulator.updateMergeBase(fms_team, team)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(district_team)
        if robot:
            robot = RobotManipulator.createOrUpdate(robot)
        if team:
            team = TeamManipulator.createOrUpdate(team)
            success = True
        else:
            success = False
            logging.warning("getTeamDetails failed for team: {}".format(key_name))

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': success,
            'district': district_team,
            'robot': robot,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 6
0
    def get(self, key_name):
        existing_team = Team.get_by_id(key_name)

        fms_df = DatafeedFMSAPI('v2.0')
        df2 = DatafeedFIRSTElasticSearch()
        year = datetime.date.today().year
        fms_details = fms_df.getTeamDetails(year, key_name)

        if fms_details:
            team, district_team, robot = fms_details[0]
        else:
            team = None
            district_team = None
            robot = None

        if team:
            team = TeamManipulator.mergeModels(team, df2.getTeamDetails(existing_team))
        else:
            team = df2.getTeamDetails(existing_team)

        if team:
            team = TeamManipulator.createOrUpdate(team)

        # Clean up junk district teams
        # https://www.facebook.com/groups/moardata/permalink/1310068625680096/
        dt_keys = DistrictTeam.query(
            DistrictTeam.team == existing_team.key,
            DistrictTeam.year == year).fetch(keys_only=True)
        keys_to_delete = set()
        for dt_key in dt_keys:
            if not district_team or dt_key.id() != district_team.key.id():
                keys_to_delete.add(dt_key)
        DistrictTeamManipulator.delete_keys(keys_to_delete)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(district_team)

        if robot:
            robot = RobotManipulator.createOrUpdate(robot)

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': team is not None,
            'district': district_team,
            'robot': robot,
        }

        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_team_details_get.html')
            self.response.out.write(template.render(path, template_values))
Exemplo n.º 7
0
def store_team(data):
    team = Team(id=data['key'])
    team.team_number = data['team_number']
    team.nickname = data['nickname']
    team.name = data['name']
    team.website = data['website']
    team.rookie_year = data['rookie_year']
    team.motto = data['motto']
    team.city = data['city']
    team.state_prov = data['state_prov']
    team.country = data['country']

    TeamManipulator.createOrUpdate(team)
    return team
Exemplo n.º 8
0
def store_team(data):
    team = Team(id=data['key'])
    team.team_number = data['team_number']
    team.nickname = data['nickname']
    team.name = data['name']
    team.website = data['website']
    team.rookie_year = data['rookie_year']
    team.motto = data['motto']
    team.city = data['city']
    team.state_prov = data['state_prov']
    team.country = data['country']

    TeamManipulator.createOrUpdate(team)
    return team
    def get(self, key_name):
        # Combines data from three datafeeds with priorities:
        # 1) DatafeedFMSAPI (missing website)
        # 2) DatafeedUsfirst (missing rookie year)
        # 3) DatafeedUsfirstLegacy (has all info)

        legacy_df = DatafeedUsfirstLegacy()
        usfirst_df = DatafeedUsfirst()
        fms_df = DatafeedFMSAPI('v2.0')

        # Start with lowest priority
        legacy_team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
        usfirst_team = usfirst_df.getTeamDetails(Team.get_by_id(key_name))
        fms_details = fms_df.getTeamDetails(date.today().year, key_name)

        if fms_details:
            fms_team, district_team, robot = fms_details
        else:
            fms_team = None
            district_team = None
            robot = None

        team = None
        if usfirst_team:
            team = TeamManipulator.updateMergeBase(usfirst_team, legacy_team)
        if fms_team:
            team = TeamManipulator.updateMergeBase(fms_team, team)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(district_team)
        if robot:
            robot = RobotManipulator.createOrUpdate(robot)
        if team:
            team = TeamManipulator.createOrUpdate(team)
            success = True
        else:
            success = False
            logging.warning("getTeamDetails failed for team: {}".format(key_name))

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': success,
            'district': district_team,
            'robot': robot,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
        self.response.out.write(template.render(path, template_values))
    def test_create_lots_of_teams(self):
        number = 500
        teams = [Team(
            id = "frc%s" % team_number,
            team_number = team_number)
            for team_number in range(number)]
        TeamManipulator.createOrUpdate(teams)

        team = Team.get_by_id("frc177")
        self.assertEqual(team.key_name, "frc177")
        self.assertEqual(team.team_number, 177)

        team = Team.get_by_id("frc%s" % (number - 1))
        self.assertEqual(team.key_name, "frc%s" % (number - 1))
        self.assertEqual(team.team_number, number - 1)
    def test_create_lots_of_teams(self):
        number = 500
        teams = [
            Team(id="frc%s" % team_number, team_number=team_number)
            for team_number in range(number)
        ]
        TeamManipulator.createOrUpdate(teams)

        team = Team.get_by_id("frc177")
        self.assertEqual(team.key_name, "frc177")
        self.assertEqual(team.team_number, 177)

        team = Team.get_by_id("frc%s" % (number - 1))
        self.assertEqual(team.key_name, "frc%s" % (number - 1))
        self.assertEqual(team.team_number, number - 1)
    def get(self, key_name):
        fms_df = DatafeedFMSAPI('v2.0')
        fms_details = fms_df.getTeamDetails(date.today().year, key_name)

        if fms_details:
            team, district_team, robot = fms_details
        else:
            fms_team = None
            district_team = None
            robot = None

        if team:
            team = TeamManipulator.createorUpdate(team)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(
                district_team)

        if robot:
            robot = RobotManipulator.createOrUpdate(robot)

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': success,
            'district': district_team,
            'robot': robot,
        }

        path = os.path.join(
            os.path.dirname(__file__),
            '../templates/datafeeds/usfirst_team_details_get.html')
        self.response.out.write(template.render(path, template_values))
    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))
Exemplo n.º 14
0
    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))
Exemplo n.º 15
0
    def get(self, year, first_eid):
        datafeed = DatafeedUsfirst()

        event = datafeed.getEventDetails(int(year), first_eid)
        event = EventManipulator.createOrUpdate(event)
        
        teams = datafeed.getEventTeams(int(year), first_eid)
        teams = TeamManipulator.createOrUpdate(teams)

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

        template_values = {
            'event': event,
            'event_teams': event_teams,
        }
        
        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_details_get.html')
        self.response.out.write(template.render(path, template_values))
    def get(self, key_name):
        fms_df = DatafeedFMSAPI('v2.0')
        fms_details = fms_df.getTeamDetails(date.today().year, key_name)

        if fms_details:
            team, district_team, robot = fms_details
        else:
            fms_team = None
            district_team = None
            robot = None

        if team:
            team = TeamManipulator.createorUpdate(team)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(district_team)

        if robot:
            robot = RobotManipulator.createOrUpdate(robot)

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': success,
            'district': district_team,
            'robot': robot,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
        self.response.out.write(template.render(path, template_values))
    def get(self, event_key):
        datafeed = DatafeedUsfirst()

        event = Event.get_by_id(event_key)
        new_awards = AwardManipulator.createOrUpdate(datafeed.getEventAwards(event))
        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,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_awards_get.html')
        self.response.out.write(template.render(path, template_values))
    def get(self, key_name):
        df = DatafeedUsfirst()
        legacy_df = DatafeedUsfirstLegacy()

        team = df.getTeamDetails(Team.get_by_id(key_name))
        if not team:
            logging.warning("getTeamDetails with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(key_name))
            team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
        else:
            legacy_team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
            if legacy_team is not None:
                team.rookie_year = legacy_team.rookie_year  # only available on legacy df

        if team:
            team = TeamManipulator.createOrUpdate(team)
            success = True
        else:
            success = False

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': success,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 19
0
    def scrapeTpids(self, skip, year):
        """
      Searches the FIRST list of all teams for tpids, writing in the datastore.
      Also creates new Team objects.

      This code is modified from Pat Fairbank's frclinks source and modified
      to fit in the TBA framework. He has given us permission to borrow
      his code.
      """
        while 1:
            logging.info("Fetching 250 teams based on %s data, skipping %s" %
                         (year, skip))

            tpids_dict = dict()

            # FIRST is now checking the 'Referer' header for the string 'usfirst.org'.
            # See https://github.com/patfair/frclinks/commit/051bf91d23ca0242dad5b1e471f78468173f597f
            teamList = urlfetch.fetch(self.TPID_URL_PATTERN % (year, skip),
                                      headers={'Referrer': 'usfirst.org'},
                                      deadline=10)
            teamResults = self.teamRe.findall(teamList.content)

            for teamResult in teamResults:
                teamNumber = self.teamNumberRe.findall(teamResult)[0]
                teamTpid = self.tpidRe.findall(teamResult)[0]

                logging.info("Team %s TPID was %s in year %s." %
                             (teamNumber, teamTpid, year))
                tpids_dict[teamNumber] = teamTpid

            teams = [
                Team(team_number=int(team_number),
                     first_tpid=int(tpids_dict[team_number]),
                     first_tpid_year=int(year),
                     id="frc" + str(team_number)) for team_number in tpids_dict
            ]

            TeamManipulator.createOrUpdate(teams)
            skip = int(skip) + 250

            # Handle degenerate cases.
            if skip > 10000:
                return None

            if len(self.lastPageRe.findall(teamList.content)) == 0:
                return None
    def get(self, event_key):
        df = DatafeedFMSAPI('v2.0')
        event = Event.get_by_id(event_key)

        models = df.getEventTeams(event_key)
        teams = []
        district_teams = []
        robots = []
        for group in models:
            # models is a list of tuples (team, districtTeam, robot)
            if isinstance(group[0], Team):
                teams.append(group[0])
            if isinstance(group[1], DistrictTeam):
                district_teams.append(group[1])
            if isinstance(group[2], Robot):
                robots.append(group[2])

        # Write new models
        teams = TeamManipulator.createOrUpdate(teams)
        district_teams = DistrictTeamManipulator.createOrUpdate(district_teams)
        robots = RobotManipulator.createOrUpdate(robots)

        if not teams:
            # No teams found registered for this event
            teams = []

        # Build EventTeams
        event_teams = [
            EventTeam(id=event.key_name + "_" + team.key_name,
                      event=event.key,
                      team=team.key,
                      year=event.year) for team in teams
        ]

        # Delete eventteams of teams that are no longer registered
        if event.future:
            existing_event_team_keys = set(
                EventTeam.query(EventTeam.event == event.key).fetch(
                    1000, keys_only=True))
            event_team_keys = set([et.key for et in event_teams])
            et_keys_to_delete = existing_event_team_keys.difference(
                event_team_keys)
            EventTeamManipulator.delete_keys(et_keys_to_delete)

        event_teams = EventTeamManipulator.createOrUpdate(event_teams)
        if type(event_teams) is not list:
            event_teams = [event_teams]

        template_values = {
            'event': event,
            'event_teams': event_teams,
        }

        path = os.path.join(
            os.path.dirname(__file__),
            '../templates/datafeeds/usfirst_event_details_get.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 21
0
 def createTeam(cls, number, name=None):
     team = Team(
         id="frc{}".format(number),
         team_number=number,
         name=name,
         nickname=name,
     )
     team = TeamManipulator.createOrUpdate(team)
     return team
Exemplo n.º 22
0
    def get(self, key_name):
        existing_team = Team.get_by_id(key_name)

        fms_df = DatafeedFMSAPI('v2.0')
        df2 = DatafeedFIRSTElasticSearch()
        fms_details = fms_df.getTeamDetails(datetime.date.today().year,
                                            key_name)

        if fms_details:
            team, district_team, robot = fms_details[0]
        else:
            team = None
            district_team = None
            robot = None

        if team:
            team = TeamManipulator.mergeModels(
                team, df2.getTeamDetails(existing_team))
        else:
            team = df2.getTeamDetails(existing_team)

        if team:
            team = TeamManipulator.createOrUpdate(team)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(
                district_team)

        if robot:
            robot = RobotManipulator.createOrUpdate(robot)

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': team is not None,
            'district': district_team,
            'robot': robot,
        }

        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_team_details_get.html')
            self.response.out.write(template.render(path, template_values))
Exemplo n.º 23
0
    def scrapeTpids(self, skip, year):
      """
      Searches the FIRST list of all teams for tpids, writing in the datastore.
      Also creates new Team objects.

      This code is modified from Pat Fairbank's frclinks source and modified
      to fit in the TBA framework. He has given us permission to borrow
      his code.
      """
      while 1:
        logging.info("Fetching 250 teams based on %s data, skipping %s" % (year, skip))

        tpids_dict = dict()

        # FIRST is now checking the 'Referer' header for the string 'usfirst.org'.
        # See https://github.com/patfair/frclinks/commit/051bf91d23ca0242dad5b1e471f78468173f597f
        teamList = urlfetch.fetch(self.TPID_URL_PATTERN % (year, skip), headers={'Referrer': 'usfirst.org'}, deadline=10)
        teamResults = self.teamRe.findall(teamList.content)

        for teamResult in teamResults:
          teamNumber = self.teamNumberRe.findall(teamResult)[0]
          teamTpid = self.tpidRe.findall(teamResult)[0]

          logging.info("Team %s TPID was %s in year %s." % (teamNumber, teamTpid, year))
          tpids_dict[teamNumber] = teamTpid

        teams = [Team(
              team_number=int(team_number),
              first_tpid=int(tpids_dict[team_number]),
              first_tpid_year=int(year),
              id="frc" + str(team_number)
            )
        for team_number in tpids_dict]

        TeamManipulator.createOrUpdate(teams)
        skip = int(skip) + 250

        # Handle degenerate cases.
        if skip > 10000:
          return None

        if len(self.lastPageRe.findall(teamList.content)) == 0:
          return None
    def get(self, year, first_eid):
        df = DatafeedUsfirst()
        df_legacy = DatafeedUsfirstLegacy()

        event = df.getEventDetails(first_eid)
        if not event:
            logging.warning("getEventDetails with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
            event = df_legacy.getEventDetails(int(year), first_eid)

        if self.request.get('event_district_enum'):
            event.event_district_enum = int(self.request.get('event_district_enum'))
        event = EventManipulator.createOrUpdate(event)

        teams = df.getEventTeams(int(year), first_eid)
        if not teams:
            logging.warning("getEventTeams with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
            teams = df_legacy.getEventTeams(int(year), first_eid)
            if not teams:
                logging.warning("getEventTeams with DatafeedUsfirstLegacy for event id {} failed.".format(first_eid))
                teams = []

        teams = TeamManipulator.createOrUpdate(teams)

        if teams:
            if type(teams) is not list:
                teams = [teams]

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

            # Delete eventteams of teams that unregister from an event
            if event.future:
                existing_event_team_keys = set(EventTeam.query(EventTeam.event == event.key).fetch(1000, keys_only=True))
                event_team_keys = set([et.key for et in event_teams])
                et_keys_to_delete = existing_event_team_keys.difference(event_team_keys)
                EventTeamManipulator.delete_keys(et_keys_to_delete)

            event_teams = EventTeamManipulator.createOrUpdate(event_teams)
            if type(event_teams) is not list:
                event_teams = [event_teams]
        else:
            event_teams = []

        template_values = {
            'event': event,
            'event_teams': event_teams,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_details_get.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 25
0
    def post(self, event_key_id):
        self._require_admin()
        event = Event.get_by_id(event_key_id)

        teams_csv = self.request.get('teams_csv')
        team_numbers = CSVTeamsParser.parse(teams_csv)

        event_teams = []
        teams = []
        for team_number in team_numbers:
            event_teams.append(EventTeam(id=event.key.id() + '_frc{}'.format(team_number),
                                         event=event.key,
                                         team=ndb.Key(Team, 'frc{}'.format(team_number)),
                                         year=event.year))
            teams.append(Team(id='frc{}'.format(team_number),
                              team_number=int(team_number)))

        EventTeamManipulator.createOrUpdate(event_teams)
        TeamManipulator.createOrUpdate(teams)

        self.redirect("/admin/event/" + event.key_name)
    def get(self, event_key):
        df = DatafeedFMSAPI('v2.0')
        event = Event.get_by_id(event_key)

        models = df.getEventTeams(event_key)
        teams = []
        district_teams = []
        robots = []
        for group in models:
            # models is a list of tuples (team, districtTeam, robot)
            if isinstance(group[0], Team):
                teams.append(group[0])
            if isinstance(group[1], DistrictTeam):
                district_teams.append(group[1])
            if isinstance(group[2], Robot):
                robots.append(group[2])

        # Write new models
        teams = TeamManipulator.createOrUpdate(teams)
        district_teams = DistrictTeamManipulator.createOrUpdate(district_teams)
        robots = RobotManipulator.createOrUpdate(robots)

        if not teams:
            # No teams found registered for this event
            teams = []

        # Build EventTeams
        event_teams = [EventTeam(
            id=event.key_name + "_" + team.key_name,
            event=event.key,
            team=team.key,
            year=event.year)
            for team in teams]

        # Delete eventteams of teams that are no longer registered
        if event.future:
            existing_event_team_keys = set(EventTeam.query(EventTeam.event == event.key).fetch(1000, keys_only=True))
            event_team_keys = set([et.key for et in event_teams])
            et_keys_to_delete = existing_event_team_keys.difference(event_team_keys)
            EventTeamManipulator.delete_keys(et_keys_to_delete)

        event_teams = EventTeamManipulator.createOrUpdate(event_teams)
        if type(event_teams) is not list:
            event_teams = [event_teams]

        template_values = {
            'event': event,
            'event_teams': event_teams,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_details_get.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 27
0
    def get(self, key_name):
        existing_team = Team.get_by_id(key_name)

        fms_df = DatafeedFMSAPI('v2.0')
        df2 = DatafeedFIRSTElasticSearch()
        fms_details = fms_df.getTeamDetails(datetime.date.today().year, key_name)

        if fms_details:
            team, district_team, robot = fms_details[0]
        else:
            team = None
            district_team = None
            robot = None

        if team:
            team = TeamManipulator.mergeModels(team, df2.getTeamDetails(existing_team))
        else:
            team = df2.getTeamDetails(existing_team)

        if team:
            team = TeamManipulator.createOrUpdate(team)

        if district_team:
            district_team = DistrictTeamManipulator.createOrUpdate(district_team)

        if robot:
            robot = RobotManipulator.createOrUpdate(robot)

        template_values = {
            'key_name': key_name,
            'team': team,
            'success': team is not None,
            'district': district_team,
            'robot': robot,
        }

        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_team_details_get.html')
            self.response.out.write(template.render(path, template_values))
    def get(self, event_key):
        teams, event_teams, et_keys_to_del = EventTeamUpdater.update(event_key)

        teams = TeamManipulator.createOrUpdate(teams)

        if teams:
            event_teams = EventTeamManipulator.createOrUpdate(event_teams)

        if et_keys_to_del:
            EventTeamManipulator.delete_keys(et_keys_to_del)

        template_values = {"event_teams": event_teams, "deleted_event_teams_keys": et_keys_to_del}

        path = os.path.join(os.path.dirname(__file__), "../templates/math/eventteam_update_do.html")
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 29
0
 def get(self, key_name):
     df = DatafeedUsfirst()
     team = df.getTeamDetails(Team.get_by_id(key_name))
     if team:
         team = TeamManipulator.createOrUpdate(team)
         success = True
     else:
         success = False
     
     template_values = {
         'team': team,
         'success': success,
     }
     
     path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
     self.response.out.write(template.render(path, template_values))
Exemplo n.º 30
0
    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))
Exemplo n.º 31
0
    def get(self, event_key):
        teams, event_teams, et_keys_to_del = EventTeamUpdater.update(event_key)

        teams = TeamManipulator.createOrUpdate(teams)

        if teams:
            event_teams = EventTeamManipulator.createOrUpdate(event_teams)

        if et_keys_to_del:
            ndb.delete_multi(et_keys_to_del)

        template_values = {
            'event_teams': event_teams,
            'deleted_event_teams_keys': et_keys_to_del
        }

        path = os.path.join(os.path.dirname(__file__),
                            '../templates/math/eventteam_update_do.html')
        self.response.out.write(template.render(path, template_values))
    def get(self, year, first_eid):
        df = DatafeedUsfirst()
        df_legacy = DatafeedUsfirstLegacy()

        event = df.getEventDetails(first_eid)
        if not event:
            logging.warning("getEventDetails with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
            event = df_legacy.getEventDetails(int(year), first_eid)
        event = EventManipulator.createOrUpdate(event)

        teams = df.getEventTeams(int(year), first_eid)
        if not teams:
            logging.warning("getEventTeams with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
            teams = df_legacy.getEventTeams(int(year), first_eid)
            if not teams:
                logging.warning("getEventTeams with DatafeedUsfirstLegacy for event id {} failed.".format(first_eid))
                teams = []

        teams = TeamManipulator.createOrUpdate(teams)

        if teams:
            if type(teams) is not list:
                teams = [teams]

            event_teams = [EventTeam(
                id=event.key.id() + "_" + team.key.id(),
                event=event.key,
                team=team.key,
                year=event.year)
                for team in teams]
            event_teams = EventTeamManipulator.createOrUpdate(event_teams)
            if type(event_teams) is not list:
                event_teams = [event_teams]
        else:
            event_teams = []

        template_values = {
            'event': event,
            'event_teams': event_teams,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_details_get.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 33
0
    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))
Exemplo n.º 34
0
    def get(self, event_key):
        df = DatafeedFMSAPI('v2.0')
        df2 = DatafeedFIRSTElasticSearch()

        event = Event.get_by_id(event_key)

        # Update event
        fmsapi_events, fmsapi_districts = df.getEventDetails(event_key)
        elasticsearch_events = df2.getEventDetails(event)
        updated_event = EventManipulator.mergeModels(fmsapi_events,
                                                     elasticsearch_events)
        if updated_event:
            event = EventManipulator.createOrUpdate(updated_event)
        DistrictManipulator.createOrUpdate(fmsapi_districts)

        models = df.getEventTeams(event_key)
        teams = []
        district_teams = []
        robots = []
        for group in models:
            # models is a list of tuples (team, districtTeam, robot)
            if isinstance(group[0], Team):
                teams.append(group[0])
            if isinstance(group[1], DistrictTeam):
                district_teams.append(group[1])
            if isinstance(group[2], Robot):
                robots.append(group[2])

        # Merge teams
        teams = TeamManipulator.mergeModels(teams, df2.getEventTeams(event))

        # Write new models
        if teams and event.year == tba_config.MAX_YEAR:  # Only update from latest year
            teams = TeamManipulator.createOrUpdate(teams)
        district_teams = DistrictTeamManipulator.createOrUpdate(district_teams)
        robots = RobotManipulator.createOrUpdate(robots)

        if not teams:
            # No teams found registered for this event
            teams = []
        if type(teams) is not list:
            teams = [teams]

        # Build EventTeams
        cmp_hack_sitevar = Sitevar.get_or_insert('cmp_registration_hacks')
        events_without_eventteams = cmp_hack_sitevar.contents.get('skip_eventteams', []) \
            if cmp_hack_sitevar else []
        skip_eventteams = event_key in events_without_eventteams
        event_teams = [
            EventTeam(id=event.key_name + "_" + team.key_name,
                      event=event.key,
                      team=team.key,
                      year=event.year) for team in teams
        ] if not skip_eventteams else []

        # Delete eventteams of teams that are no longer registered
        if event_teams and not skip_eventteams:
            existing_event_team_keys = set(
                EventTeam.query(EventTeam.event == event.key).fetch(
                    1000, keys_only=True))
            event_team_keys = set([et.key for et in event_teams])
            et_keys_to_delete = existing_event_team_keys.difference(
                event_team_keys)
            EventTeamManipulator.delete_keys(et_keys_to_delete)

            event_teams = EventTeamManipulator.createOrUpdate(event_teams)
        if type(event_teams) is not list:
            event_teams = [event_teams]

        if event.year in {2018, 2019, 2020}:
            avatars, keys_to_delete = df.getEventTeamAvatars(event.key_name)
            if avatars:
                MediaManipulator.createOrUpdate(avatars)
            MediaManipulator.delete_keys(keys_to_delete)

        template_values = {
            'event': event,
            'event_teams': event_teams,
        }

        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_event_details_get.html')
            self.response.out.write(template.render(path, template_values))
Exemplo n.º 35
0
    def testApiCacheClear(self):
        self.assertEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll(flushed=True)

        # this shouldn't evict any caches
        EventManipulator.createOrUpdate(self.event_2010sc_1)
        EventTeamManipulator.createOrUpdate(self.eventteam_2010sc_frc1)
        EventTeamManipulator.createOrUpdate(self.eventteam_2010sc_frc2)
        AwardManipulator.createOrUpdate(self.award1_1)
        MatchManipulator.createOrUpdate(self.match1_1)
        TeamManipulator.createOrUpdate(self.team_frc1_1)
        TeamManipulator.createOrUpdate(self.team_frc2_1)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc2_cache_key), None)

        # updating an event
        EventManipulator.createOrUpdate(self.event_2010sc_2)
        self.assertEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # updating a team
        TeamManipulator.createOrUpdate(self.team_frc1_2)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # updating a match
        MatchManipulator.createOrUpdate(self.match1_2)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # updating an award
        AwardManipulator.createOrUpdate(self.award1_2)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # deleting an award
        AwardManipulator.delete(self.award1_2)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # deleting a match
        MatchManipulator.delete(self.match1_2)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # deleting a team
        TeamManipulator.delete(self.team_frc2_2)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # deleting an event
        EventManipulator.delete(self.event_2010sc_2)
        self.assertEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        self.resetAll()

        # deleting an eventteam
        EventTeamManipulator.delete(self.eventteam_2010sc_frc1)
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc2_cache_key), None)
 def test_updateMerge(self):
     self.assertMergedTeam(
         TeamManipulator.updateMerge(self.new_team, self.old_team))
 def test_findOrSpawn(self):
     self.old_team.put()
     self.assertMergedTeam(TeamManipulator.findOrSpawn(self.new_team))
 def test_updateMerge(self):
     self.assertMergedTeam(TeamManipulator.updateMerge(self.new_team, self.old_team))
 def test_createOrUpdate(self):
     TeamManipulator.createOrUpdate(self.old_team)
     self.assertOldTeam(Team.get_by_id("frc177"))
     TeamManipulator.createOrUpdate(self.new_team)
     self.assertMergedTeam(Team.get_by_id("frc177"))
Exemplo n.º 40
0
 def createTeam(cls, number, name=None):
     team = Team(id="frc{}".format(number), team_number=number, name=name, nickname=name)
     team = TeamManipulator.createOrUpdate(team)
     return team
Exemplo n.º 41
0
 def get(self, team_key):
     team = Team.get_by_id(team_key)
     TeamManipulator.runPostUpdateHook([team])
    def get(self, event_key):
        df = DatafeedFMSAPI('v2.0')
        df2 = DatafeedFIRSTElasticSearch()

        event = Event.get_by_id(event_key)

        # Update event
        fmsapi_events, fmsapi_districts = df.getEventDetails(event_key)
        elasticsearch_events = df2.getEventDetails(event)
        updated_event = EventManipulator.mergeModels(
            fmsapi_events,
            elasticsearch_events)
        if updated_event:
            event = EventManipulator.createOrUpdate(updated_event)
        DistrictManipulator.createOrUpdate(fmsapi_districts)

        models = df.getEventTeams(event_key)
        teams = []
        district_teams = []
        robots = []
        for group in models:
            # models is a list of tuples (team, districtTeam, robot)
            if isinstance(group[0], Team):
                teams.append(group[0])
            if isinstance(group[1], DistrictTeam):
                district_teams.append(group[1])
            if isinstance(group[2], Robot):
                robots.append(group[2])

        # Merge teams
        teams = TeamManipulator.mergeModels(teams, df2.getEventTeams(event))

        # Write new models
        if teams:
            teams = TeamManipulator.createOrUpdate(teams)
        district_teams = DistrictTeamManipulator.createOrUpdate(district_teams)
        robots = RobotManipulator.createOrUpdate(robots)

        if not teams:
            # No teams found registered for this event
            teams = []
        if type(teams) is not list:
            teams = [teams]

        # Build EventTeams
        cmp_hack_sitevar = Sitevar.get_or_insert('cmp_registration_hacks')
        events_without_eventteams = cmp_hack_sitevar.contents.get('skip_eventteams', []) \
            if cmp_hack_sitevar else []
        skip_eventteams = event_key in events_without_eventteams
        event_teams = [EventTeam(
            id=event.key_name + "_" + team.key_name,
            event=event.key,
            team=team.key,
            year=event.year)
            for team in teams] if not skip_eventteams else []

        # Delete eventteams of teams that are no longer registered
        if event_teams != [] or skip_eventteams:
            existing_event_team_keys = set(EventTeam.query(EventTeam.event == event.key).fetch(1000, keys_only=True))
            event_team_keys = set([et.key for et in event_teams])
            et_keys_to_delete = existing_event_team_keys.difference(event_team_keys)
            EventTeamManipulator.delete_keys(et_keys_to_delete)

            event_teams = EventTeamManipulator.createOrUpdate(event_teams)
        if type(event_teams) is not list:
            event_teams = [event_teams]

        template_values = {
            'event': event,
            'event_teams': event_teams,
        }

        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_event_details_get.html')
            self.response.out.write(template.render(path, template_values))
 def test_findOrSpawn(self):
     self.old_team.put()
     self.assertMergedTeam(TeamManipulator.findOrSpawn(self.new_team))
Exemplo n.º 44
0
    def resetAll(self, flushed=False):
        response = self.testapp.get('/api/v2/events/2010', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)

        EventManipulator.createOrUpdate(self.event_2010sc_1)
        if flushed:
            self.assertEqual(memcache.get(self.eventlist_2010_cache_key), None)
        TeamManipulator.createOrUpdate(self.team_frc1_1)
        TeamManipulator.createOrUpdate(self.team_frc2_1)
        EventTeamManipulator.createOrUpdate(self.eventteam_2010sc_frc1)
        EventTeamManipulator.createOrUpdate(self.eventteam_2010sc_frc2)
        MatchManipulator.createOrUpdate(self.match1_1)
        AwardManipulator.createOrUpdate(self.award1_1)

        response = self.testapp.get('/api/v2/events/2010', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.event_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/event/2010sc', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/event/2010sc/teams', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/event/2010sc/matches', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/event/2010sc/stats', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/event/2010sc/rankings', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/event/2010sc/awards', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.team_frc1_cache_key), None)
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/team/frc1/2010', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc1_cache_key), None)
        if flushed:
            self.assertEqual(memcache.get(self.team_frc2_cache_key), None)

        response = self.testapp.get('/api/v2/team/frc2/2010', headers={'X-TBA-App-Id': 'tba-tests:api-cache-clear-test:v01'})
        self.assertNotEqual(memcache.get(self.eventlist_2010_cache_key), None)
        self.assertNotEqual(memcache.get(self.event_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventteams_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventmatches_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventstats_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventrankings_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.eventawards_2010sc_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc1_cache_key), None)
        self.assertNotEqual(memcache.get(self.team_frc2_cache_key), None)
 def test_createOrUpdate(self):
     TeamManipulator.createOrUpdate(self.old_team)
     self.assertOldTeam(Team.get_by_id("frc177"))
     TeamManipulator.createOrUpdate(self.new_team)
     self.assertMergedTeam(Team.get_by_id("frc177"))