View Single Post
  #116   Spotlight this post!  
Unread 05-05-2016, 18:35
sdangelo sdangelo is offline
Registered User
FTC #10842 (Train of Thought)
Team Role: Alumni
 
Join Date: Sep 2015
Rookie Year: 2009
Location: State College, PA
Posts: 40
sdangelo has a spectacular aura aboutsdangelo has a spectacular aura about
Re: Split Champs assignment

Quote:
Originally Posted by Nathan Streeter View Post
It would be interesting to see which CMP would have more teams from the 2016 CMP elims...
Spoiler for Code:
Code:
import json
import urllib2

BASE_URL = 'http://www.thebluealliance.com/api/v2/'
APP_HEADER = 'X-TBA-App-Id'
APP_ID = 'sdangelo:splitchamps:v0.1'

event_codes = ['arc', 'cars', 'carv', 'cur', 'gal', 'hop', 'new', 'tes']

def fetch_endpoint(endpoint):
    #Checks Blue Alliance for data
    full_url = BASE_URL + endpoint
    url = urllib2.Request(full_url, headers={APP_HEADER: APP_ID, 'User-agent': 'Mozilla/5.0'})
    response = urllib2.urlopen(url)
    return json.loads(response.read())

def get_teams(event_key):
    #builds list of all teams
    teams = []
    event = fetch_endpoint("event/2016"+ str(event_key))
    for alliance in event["alliances"]:
        for team in alliance["picks"]:
            teams.append(str(team))
    return teams

def get_locations(teams_list):
    stl = []
    hous = []
    allTeams = []
    for team in teams_list:
        data = fetch_endpoint("team/" + team)
        if data["country_name"] == "USA":
            s = data["region"]
            if s == "Maine" or s == "Vermont" or s == "New Hampshire" or s == "Massachusetts" or\
               s == "Connecticut" or s == "Rhode Island" or s == "New York" or s == "Pennsylvania"\
               or s == "New Jersey" or s == "Delaware" or s == "Maryland" or s == "District of Columbia"\
               or s == "Virginia" or s == "West Virginia" or s == "Kentucky" or s == "Ohio" or\
               s == "Michigan" or s == "Indiana" or s == "Illinois" or s == "Wisconsin" or\
               s == "Minnesota" or s == "Iowa" or s == "Missouri" or s == "Kansas" or\
               s == "Nebraska" or s == "South Dakota" or s == "North Dakota":
                stl.append(data["team_number"])
            else:
                hous.append(data["team_number"])
        elif data["country_name"] == "Canada":
            p = data["region"]
            if p == "Ontario" or p == "Quebec" or p == "Newfoundland and Laborador"\
               or p == "Manitoba" or p == "Nunavit":
                stl.append(data["team_number"])
            else:
                hous.append(data["team_number"])
        else:
            c = data["country_name"]
            if c == "Mexico" or c == "Haiti" or c == "Dominican Republic" or\
               c == "Ecuador" or c == "Columbia" or c == "Peru" or c == "Chile"\
               or c == "Brazil" or c == "South Africa" or c == "Israel" or\
               c == "Egypt" or c == "Jordan" or c == "Lebanon" or c == "Turkey"\
               or c == "Kuwait" or c == "United Arab Emirates" or c == "Singapore"\
               or c == "Malaysia" or c == "Australia" or c == "New Zealand" or\
               c == "Philippines" or c == "China":
                hous.append(data["team_number"])
            else:
                stl.append(data["team_number"])
    allTeams.append(stl)
    allTeams.append(hous)
    return allTeams

if __name__ == "__main__":
    stLouis = []
    houston = []
    for event in event_codes:
        teamsList = get_teams(event)
        locList = get_locations(teamsList)
        for team in locList[0]:
            stLouis.append(team)
        for team in locList[1]:
            houston.append(team)
    print "Number of elims teams in St. Louis: " + str(len(stLouis))
    print "Number of elims teams in Houston: " + str(len(houston)) + "\n"

    stLouis.sort()
    houston.sort()
    print "St. Louis teams:"
    print stLouis
    print "Houston teams:"
    print houston


Results:
Number of elims teams in St. Louis: 174
Number of elims teams in Houston: 82

Spoiler for St. Louis Teams:
11, 20, 25, 27, 33, 41, 45, 48, 67, 68, 70, 74, 85, 107, 111, 120, 125, 133, 135, 166, 172, 175, 176, 177, 188, 193, 195, 217, 225, 228, 229, 230, 236, 245, 287, 303, 319, 329, 333, 341, 346, 365, 379, 494, 503, 525, 548, 558, 610, 623, 639, 694, 708, 836, 858, 868, 869, 870, 876, 910, 999, 1023, 1024, 1058, 1086, 1089, 1114, 1124, 1153, 1241, 1250, 1257, 1305, 1306, 1310, 1405, 1418, 1501, 1511, 1519, 1625, 1640, 1675, 1676, 1712, 1718, 1730, 1731, 1732, 1736, 1747, 1756, 1768, 1775, 1796, 1806, 1885, 1918, 1923, 1986, 2013, 2052, 2054, 2056, 2064, 2067, 2137, 2168, 2194, 2337, 2338, 2363, 2451, 2474, 2481, 2502, 2590, 2614, 2648, 2767, 2771, 2823, 2834, 2883, 2987, 3015, 3042, 3044, 3098, 3130, 3314, 3352, 3357, 3419, 3452, 3534, 3538, 3539, 3546, 3604, 3618, 3620, 3641, 3683, 3688, 4001, 4003, 4009, 4028, 4039, 4085, 4103, 4329, 4362, 4391, 4525, 4536, 4564, 4607, 4678, 4920, 4967, 5050, 5114, 5150, 5172, 5254, 5401, 5406, 5448, 5460, 5813, 5895, 6175

Spoiler for Houston Teams:
16, 57, 118, 148, 179, 180, 207, 231, 233, 254, 294, 330, 359, 360, 364, 842, 971, 973, 987, 1011, 1065, 1197, 1261, 1296, 1318, 1323, 1369, 1425, 1477, 1538, 1540, 1619, 1662, 1671, 1678, 1690, 1746, 1983, 2046, 2122, 2383, 2415, 2468, 2471, 2557, 2637, 2642, 2848, 2907, 2990, 3005, 3166, 3211, 3238, 3309, 3310, 3339, 3360, 3476, 3478, 3481, 3663, 3824, 3937, 3990, 4061, 4264, 4334, 4451, 4468, 4469, 4488, 4587, 4740, 4828, 4911, 5572, 5803, 5842, 5854, 5924, 5940


If anyone sees any teams in the wrong list or code errors, let me know and I'll try to fix it. Québec may not be working correctly as my Python editor couldn't handle the 'é'.
__________________

Last edited by sdangelo : 05-05-2016 at 18:46.
Reply With Quote