def predict_tournament(matchlist_file, expos=None, start=0): """ - Given a matchlist for a tournament, predict the winner of each match. - If only the matchlist file is given, predict the tournament based on previous match data. - If a starting round is specified, predict the tournament based on previously available match data when available, falling back on old data when necessary. """ # Parse Matchlist matches = roboscout.getData(matchlist_file, True) # Get a list of teams from the matchlist teams = [] for match in matches: positions = ['Red 1', 'Red 2', 'Blue 1', 'Blue 2'] for n in positions: if match[n] not in teams: teams.append(match[n]) if expos is None: # Pre-scout from the main match pool expos, vars, caps = metatournament.best_robots( officialparser.get_tournaments()) # filter expo to only include teams we care about expos = filter_dict(lambda t: t in teams, expos) # Run roboscout on the first n rounds to get more accurate # expected output when possible. s = roboscout.scout(matches[:start]) for team in teams: if team in s['expo']: expos[team] = s['expo'][team] # Get an average for teams with no data expo_avg = avg(expos.values()) for team in teams: if team not in expos: expos[team] = expo_avg # Fill in match predictions based on expected output for each team for match in matches: rs = round(expos[match['Red 1']] + expos[match['Red 2']]) bs = round(expos[match['Blue 1']] + expos[match['Blue 2']]) match['Red Score'] = rs match['Blue Score'] = bs return matches
def robot_stats(t): s = roboscout.scout(t) highcap = capabilities(s, HIGH_GOAL) midcap = capabilities(s, MID_GOAL) lowcap = capabilities(s, LOW_GOAL) hangcap = capabilities(s, HANG) auto = auto_expo(s) autoend = futil.mapd(max, auto_ending_pos(s)) teams = {} for team in highcap.keys(): teams[team] = { 'expo': s['expo'][team], 'variance': s['variance'][team], 'caps': { 'high': highcap[team], 'mid': midcap[team], 'low': lowcap[team], 'hang': hangcap[team], 'auto': auto[team], 'autopos': autoend[team] } } return teams
for x in xrange(len(m1)): p = m1[x] r = m2[x] pw = 'Red' if p['Red Score'] > p['Blue Score'] else 'Blue' rw = 'Red' if int(r['Red Score']) > int(r['Blue Score']) else 'Blue' confirmation.append({ 'Round #': p['Round #'], 'Red Diff': p['Red Score'] - int(r['Red Score']), 'Blue Diff': p['Blue Score'] - int(r['Blue Score']), 'Win Predicted': pw == rw }) return confirmation if __name__ == '__main__': s = roboscout.scout(roboscout.getData('matchlists/hopper1.csv')) t = predict_tournament('matchlists/hopper1.csv', s['expo']) d = map(lambda r: [r['Round #'], r['Red Score'], r['Blue Score'], 'Blue' if r['Blue Score'] > r['Red Score'] else 'Red'], t) h = ['#', 'Red', 'Blue', 'Winner'] scratch.print_table(h, d) # confirmation = compare_matchlists( # predict_tournament('scoreboard_tesla.csv'), # roboscout.getData('scoreboard_tesla.csv')) # # h = ['Round #', 'RD', 'BD', 'Right?'] #
def capabilities(s, i): tc = futil.mapd( lambda matches: map(lambda m: m[m['team'] + ' Breakdown'][i], matches), s['m']) cap = roboscout.scout({}, s['m'], tc) return cap['expo']
def auto_expo(s): ac = futil.mapd( lambda matches: map(lambda m: m[m['team'] + ' Auto'], matches), s['m']) auto = roboscout.scout({}, s['m'], ac) return auto['expo']
p = m1[x] r = m2[x] pw = 'Red' if p['Red Score'] > p['Blue Score'] else 'Blue' rw = 'Red' if int(r['Red Score']) > int(r['Blue Score']) else 'Blue' confirmation.append({ 'Round #': p['Round #'], 'Red Diff': p['Red Score'] - int(r['Red Score']), 'Blue Diff': p['Blue Score'] - int(r['Blue Score']), 'Win Predicted': pw == rw }) return confirmation if __name__ == '__main__': s = roboscout.scout(roboscout.getData('matchlists/hopper1.csv')) t = predict_tournament('matchlists/hopper1.csv', s['expo']) d = map( lambda r: [ r['Round #'], r['Red Score'], r['Blue Score'], 'Blue' if r['Blue Score'] > r['Red Score'] else 'Red' ], t) h = ['#', 'Red', 'Blue', 'Winner'] scratch.print_table(h, d) # confirmation = compare_matchlists( # predict_tournament('scoreboard_tesla.csv'), # roboscout.getData('scoreboard_tesla.csv')) # # h = ['Round #', 'RD', 'BD', 'Right?']
if __name__ == '__main__': # mode = sys.argv[2] url = sys.argv[1] filename = sys.argv[2] if url.startswith('http'): html_doc = urllib2.urlopen(url).read() else: html_doc = open(url, 'r').read() html_doc = html_doc.replace("\xc2\xa0", " ") # if mode == 'match': # matches = html_to_matchlist(html_doc) # elif mode in ['Tot', 'Auto', 'EndG', 'Tele']: # matches = details_to_matchlist(parse_details(html_doc), mode) details = parse_details(html_doc) tms = {} for mode in ['Tot', 'Auto', 'EndG', 'Tele']: matches = details_to_matchlist(details, mode) save_matchlist(matches, filename + mode + '.csv') s = scout(matches) for k, v in s['expo'].iteritems(): if k not in tms: tms[k] = {} tms[k][mode] = v save_details(tms, filename) # save_matchlist(matches, filename)
if __name__ == '__main__': # mode = sys.argv[2] url = sys.argv[1] filename = sys.argv[2] if url.startswith('http'): html_doc = urllib2.urlopen(url).read() else: html_doc = open(url, 'r').read() html_doc = html_doc.replace("\xc2\xa0", " ") # if mode == 'match': # matches = html_to_matchlist(html_doc) # elif mode in ['Tot', 'Auto', 'EndG', 'Tele']: # matches = details_to_matchlist(parse_details(html_doc), mode) details = parse_details(html_doc) tms = {} for mode in ['Tot', 'Auto', 'EndG', 'Tele']: matches = details_to_matchlist(details, mode) save_matchlist(matches, filename+mode+'.csv') s = scout(matches) for k, v in s['expo'].iteritems(): if k not in tms: tms[k] = {} tms[k][mode] = v save_details(tms, filename) # save_matchlist(matches, filename)