def show_comments(db, division): for team in get_teams(db, division): if team.comment: comment = team.comment.replace('\n', '\n' + ' ' * 56) clubname = truncate(team.clubname, 30) name = truncate(team.name, 20) print(f'{team.flt_pos:>3} {clubname:30} {name:20} {comment}')
def process(db, division, label, outfile): pairings = get_pairings(db, division, label) teams = get_teams(db, division) homes = defaultdict(list) aways = defaultdict(list) for _, home, away, t in pairings: homes[home].append(t) aways[away].append(t) rows = len(teams) + 1 doc = svg.Drawing( filename=outfile, style=label_style, size=("100%", rows * HEIGHT), ) base = 400 ends = [] for i, team in enumerate(teams): y = (i + 1) * HEIGHT print(team.name) doc.add(doc.text(team.name, text_anchor="end", insert=(base - 10, y))) key = team.id print(aways[key]) group, end = timebar(doc, aways[key], base, y - 5, '#66cc99') doc.add(group) ends.append(end) print(homes[key]) group, end = timebar(doc, homes[key], base, y - 5 - BAR, '#cc667f') doc.add(group) ends.append(end) end_time = 60 * ((max(ends) + 59) // 60) print(end_time, max(ends)) for i, t in enumerate(range(0, end_time + 59, 60)): doc.add( doc.line(start=(base + t, 0), end=(base + t, y + HEIGHT), stroke="gray", stroke_opacity=0.3, style="stroke-width:1")) doc.add(doc.text( f'{i}:00', insert=(base + t, BAR), style=bar_style, )) doc.attribs['width'] = base + end_time + 60 doc.save()
def do_profile(db, args): teams = get_teams(db, args.division) division_id = teams[0].division_id if not get_venues(db, teams): print("\nFix errors before proceeding\n") sys.exit() weights = get_costs(db, teams) nearest = {} rlookup = {} for i, t1 in enumerate(teams): rlookup[t1.flt_pos] = t1.id dist = [] for j, t2 in enumerate(teams): if t1 != t2: dist.append((weights[(i, j)], t2.flt_pos)) dist = list(sorted(dist))[:args.rounds] nearest[t1] = dist # print(t1.flt_pos, dist) stats = [] for team in sorted(teams, key=lambda x: x.name): if not args.quiet: print(team, end=" |") total = 0 for w, t in nearest[team]: if not args.quiet: print("{:3d}:{:3s}".format(w, t), end=" ") total += w avg = total / len(nearest[team]) if not args.quiet: print(" ", avg) stats.append((team.flt_pos, avg)) df = pd.DataFrame(stats, columns=["Team", "Travel"]) mean = df.Travel.mean() stddev = df.Travel.std() print("\nNum teams: %d" % len(teams)) print("Mean : {:0.1f}".format(mean)) print("Std Dev : {:0.1f}".format(stddev)) excess = df[df.Travel > max(CUTOFF, mean + stddev)].Team.tolist() if excess: print("Outlier teams:", excess) by_id = [(rlookup[x], ) for x in excess] cursor = db.cursor() cursor.execute('UPDATE team SET outlier=0 WHERE division_id=%s', division_id) cursor.executemany('UPDATE team SET outlier=1 WHERE id=%s', by_id) db.commit()
def get_params(): parser = ArgumentParser() parser.add_argument('--check', action='store') parser.add_argument('--show', action='store_true') parser.add_argument('-c', action='store') parser.add_argument('-v', action='store', type=int) params = parser.parse_args() return params if __name__ == '__main__': db = get_db() args = get_params() if args.check: teams = get_teams(db, args.check) venues = get_venues(db, teams) if not venues: if args.show: for vid, name in get_all_venues(): print(f'{vid:3} {name}') print('Assign a venue to the missing club') if args.c: if not args.v: print('Provide a venue ID to be assigned to the club') else: cursor = db.cursor() c_id = cursor.execute('INSERT INTO club SET name=%s', args.c) cursor.execute( 'INSERT INTO club_venue SET club_id=%s, venue_id=%s', (cursor.lastrowid, args.v))
''' SELECT home, away FROM pairing LEFT JOIN division on division.id=division_id WHERE division.label=%s AND pairing.label=%s ''', (division, label)) return cursor.fetchall() db = get_db() args = get_params() start, end, global_blackouts = get_season_info(db, args.season) start = arrow.get(start) end = arrow.get(end) teams = sorted(get_teams(db, args.division)) blackouts = Blackouts([arrow.get(x) for x in global_blackouts]) for team in teams: blackouts.set_away(team.flt_pos, [arrow.get(x) for x in team.black_away]) blackouts.set_home(team.flt_pos, [arrow.get(x) for x in team.black_home]) weights = {} rounds = {} for i, saturday in enumerate(arrow.Arrow.range('week', start, end)): sunday = saturday.shift(days=1) rounds[saturday] = i rounds[sunday] = i weights[saturday] = 1 if i < args.rounds else 20 if i < args.rounds // 2:
print(' ', best[2]) def update_teams(db, teams): records = [] for team in teams: records.append((team.venue_id, team.id)) cursor = db.cursor() cursor.executemany('UPDATE team SET team.venue_id=%s WHERE team.id=%s', records) db.commit() print(f'Updated {len(teams)} records') def get_params(): parser = ArgumentParser() parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('division', help='Team agegroup or division') params = parser.parse_args() return params if __name__ == '__main__': db = get_db() args = get_params() teams = get_teams(db, args.division) get_venues(db, teams) update_teams(db, teams) # update_venue(args.division)