Exemplo n.º 1
0
def get_team_list_per_event(event_id):
    """Accesses the datastore to return a team list for an event"""
    team_list = RootTeam.query().filter(RootTeam.events == event_id).fetch()
    team_numbers = []
    for team in team_list:
        team_numbers.append(team.key.id())
    return team_numbers
Exemplo n.º 2
0
def get_team_list():
    """Accesses the datastore to return a team list"""
    team_list = RootTeam.query().fetch(overestimate_of_frc_teams)
    team_numbers = []
    for team in team_list:
        team_numbers.append(team.key.id())
    return team_numbers
Exemplo n.º 3
0
def get_free_agent_list(league_id, page):
    """
        Return the list of free agents for a given league. Only return those on a certain page

        :param league_id: The league to generate the list for
        :param page: The number of the page to get
        :return: A list of dictionaries with the following information for each team:
            - rank: Rank in the free agent list
            - name: The name of the team
            - number: The team numer
            - total points: The total number of points(our system) that this team has accumulated
    """
    taken_teams = get_taken_teams(league_id)
    query = RootTeam.query().order(-RootTeam.total_points)
    extra_teams = query.fetch(globals.free_agent_pagination * page * 4)

    free_agent_teams = []
    #Get rid of the taken teams from the list
    for team in extra_teams:
        if not (team.key.id() in taken_teams):  # If this team has not been taken
            free_agent_teams.append(team)
        else:  # This team has been taken
            taken_teams.remove(team.key.id())  # Not necessary, but improves efficiency

    free_agent_list = []
    for i, team in enumerate(free_agent_teams[(page - 1) * globals.free_agent_pagination: page
            * globals.free_agent_pagination]):
        free_agent_list.append({
            'rank': i + ((page - 1) * globals.free_agent_pagination) + 1,
            'name': team.name,
            'number': team.key.id(),
            'total_points': team.total_points
        })

    return free_agent_list
Exemplo n.º 4
0
def get_team_list():
    """Accesses the datastore to return a team list"""
    team_list = RootTeam.query().fetch(overestimate_of_frc_teams)
    team_numbers = []
    for team in team_list:
        team_numbers.append(team.key.id())
    return team_numbers
Exemplo n.º 5
0
def get_lat_lng_json(league_id):
    """
        Return the latitude and longitude data for all available teams in a league

        :parameter league_id: The league used to determine which teams are available
        :type: string
        :return: A json object containing all of the information.
                This is intended to be read by the javascript on the browser side
    """
    team_data = []
    teams = RootTeam.query().fetch()
    taken_teams = get_taken_teams(league_id)
    for team in teams:
        if team.key.id() in taken_teams:
            teams.remove(team)

    for team in teams:
        team_data.append({
            "number": team.key.id(),
            "name": team.name,
            "lat": float(team.latlon.split(',')[0]),
            "lon": float(team.latlon.split(',')[1])
        })
    extra_stupid_layer = {'data': team_data}
    return json.dumps(extra_stupid_layer)
Exemplo n.º 6
0
def get_team_list_per_event(event_id):
    """Accesses the datastore to return a team list for an event"""
    team_list = RootTeam.query().filter(RootTeam.events == event_id).fetch()
    team_numbers = []
    for team in team_list:
        team_numbers.append(team.key.id())
    return team_numbers
Exemplo n.º 7
0
def get_top_teams(number):
    """Return a list of the top teams"""
    query = RootTeam.query().order(-RootTeam.total_points)
    teams = query.fetch(number)
    teamlist = []
    for team in teams:
        teamlist.append(team.key.id())
    return teamlist
def get_top_teams(number):
    """Return a list of the top teams"""
    query = RootTeam.query().order(-RootTeam.total_points)
    teams = query.fetch(number)
    teamlist = []
    for team in teams:
        teamlist.append(team.key.id())
    return teamlist
Exemplo n.º 9
0
def geocode_within_limit():
    teams = RootTeam.query().fetch()
    num_this_second = 0
    this_second = time.gmtime()

    for team in teams:
        if num_this_second < 5:
            team.latlon = geocode(team.address)
            team.put()
            num_this_second += 1
        else:
            while this_second >= time.gmtime():
                time.sleep(0.1)
            num_this_second = 0
            this_second = time.gmtime()
            team.latlon = geocode(team.address)
            team.put()
Exemplo n.º 10
0
def geocode_within_limit():
    teams = RootTeam.query().fetch()
    num_this_second = 0
    this_second = time.gmtime()

    for team in teams:
        if num_this_second < 5:
            team.latlon = geocode(team.address)
            team.put()
            num_this_second += 1
        else:
            while this_second >= time.gmtime():
                time.sleep(0.1)
            num_this_second = 0
            this_second = time.gmtime()
            team.latlon = geocode(team.address)
            team.put()
Exemplo n.º 11
0
def get_free_agent_list(league_id, page):
    """
        Return the list of free agents for a given league. Only return those on a certain page

        :param league_id: The league to generate the list for
        :param page: The number of the page to get
        :return: A list of dictionaries with the following information for each team:
            - rank: Rank in the free agent list
            - name: The name of the team
            - number: The team numer
            - total points: The total number of points(our system) that this team has accumulated
    """
    taken_teams = get_taken_teams(league_id)
    query = RootTeam.query().order(-RootTeam.total_points)
    extra_teams = query.fetch(globals.free_agent_pagination * page * 4)

    free_agent_teams = []
    #Get rid of the taken teams from the list
    for team in extra_teams:
        if not (team.key.id()
                in taken_teams):  # If this team has not been taken
            free_agent_teams.append(team)
        else:  # This team has been taken
            taken_teams.remove(
                team.key.id())  # Not necessary, but improves efficiency

    free_agent_list = []
    for i, team in enumerate(
            free_agent_teams[(page - 1) * globals.free_agent_pagination:page *
                             globals.free_agent_pagination]):
        free_agent_list.append({
            'rank':
            i + ((page - 1) * globals.free_agent_pagination) + 1,
            'name':
            team.name,
            'number':
            team.key.id(),
            'total_points':
            team.total_points
        })

    return free_agent_list
Exemplo n.º 12
0
def get_unique_location(lat, lon):
    seperation = 0.001
    newlat = lat
    newlon = lon
    datastore_lat_lon = str(lat) + "," + str(lon)
    query = RootTeam.query().filter(RootTeam.latlon == datastore_lat_lon)
    results = query.fetch(1)
    if len(results) != 0:
        dir = random.randint(0, 3)
        if dir == 0:
            newlat = lat - seperation
        elif dir == 1:
            newlat = lat + seperation
        elif dir == 2:
            newlon = lon - seperation
        elif dir == 3:
            newlon = lon + seperation
        return get_unique_location(newlat, newlon)
    else:
        return str(newlat) + "," + str(newlon)
Exemplo n.º 13
0
def get_unique_location(lat, lon):
    seperation = 0.001
    newlat = lat
    newlon = lon
    datastore_lat_lon = str(lat) + "," + str(lon)
    query = RootTeam.query().filter(RootTeam.latlon == datastore_lat_lon)
    results = query.fetch(1)
    if len(results) != 0:
        dir = random.randint(0, 3)
        if dir == 0:
            newlat = lat - seperation
        elif dir == 1:
            newlat = lat + seperation
        elif dir == 2:
            newlon = lon - seperation
        elif dir == 3:
            newlon = lon + seperation
        return get_unique_location(newlat, newlon)
    else:
        return str(newlat) + "," + str(newlon)
Exemplo n.º 14
0
def get_max_free_agent_pages(league_id):
    """
        Return the maximum number of free agent pages possible in a specific league

        :param league_id: The league to calculate this in
        :return: The maximum number of pages in the free agent list
    """
    query = RootTeam.query().order(-RootTeam.total_points)
    extra_teams = query.fetch()

    taken_teams = get_taken_teams(league_id)

    #Get rid of the taken teams from the list
    for team in extra_teams:
        if team.key.id() in taken_teams:
            extra_teams.remove(team)
            taken_teams.remove(team.key.id())  # Not necessary, but improves efficiency

    number_of_teams = len(extra_teams)
    if number_of_teams % globals.free_agent_pagination == 0:
        return number_of_teams / globals.free_agent_pagination
    else:
        return math.floor(number_of_teams / globals.free_agent_pagination) + 1
Exemplo n.º 15
0
def get_lat_lng_json(league_id):
    """
        Return the latitude and longitude data for all available teams in a league

        :parameter league_id: The league used to determine which teams are available
        :type: string
        :return: A json object containing all of the information.
                This is intended to be read by the javascript on the browser side
    """
    team_data = []
    teams = RootTeam.query().fetch()
    taken_teams = get_taken_teams(league_id)
    for team in teams:
        if team.key.id() in taken_teams:
            teams.remove(team)

    for team in teams:
        team_data.append({"number": team.key.id(),
                          "name": team.name,
                          "lat": float(team.latlon.split(',')[0]),
                          "lon": float(team.latlon.split(',')[1])})
    extra_stupid_layer = {'data': team_data}
    return json.dumps(extra_stupid_layer)
Exemplo n.º 16
0
def get_max_free_agent_pages(league_id):
    """
        Return the maximum number of free agent pages possible in a specific league

        :param league_id: The league to calculate this in
        :return: The maximum number of pages in the free agent list
    """
    query = RootTeam.query().order(-RootTeam.total_points)
    extra_teams = query.fetch()

    taken_teams = get_taken_teams(league_id)

    #Get rid of the taken teams from the list
    for team in extra_teams:
        if team.key.id() in taken_teams:
            extra_teams.remove(team)
            taken_teams.remove(
                team.key.id())  # Not necessary, but improves efficiency

    number_of_teams = len(extra_teams)
    if number_of_teams % globals.free_agent_pagination == 0:
        return number_of_teams / globals.free_agent_pagination
    else:
        return math.floor(number_of_teams / globals.free_agent_pagination) + 1
Exemplo n.º 17
0
def update_total_points():
    query = RootTeam.query()
    teams = query.fetch()
    for team in teams:
        team.total_points = get_points_to_date(team.key.id())
        team.put()
Exemplo n.º 18
0
def update_total_points():
    query = RootTeam.query()
    teams = query.fetch()
    for team in teams:
        team.total_points = get_points_to_date(team.key.id())
        team.put()