def __init__(self, **kwargs): super(MainWidget, self).__init__(**kwargs) self.do_default_tab = False self.tab_width = 200 self.UsRoster = TabbedPanelHeader(text='Our Team') self.ThemRoster = TabbedPanelHeader(text='Their Team') self.UsRoster.content = Roster() self.UsRoster.content.name = 'Us' self.ThemRoster.content = Roster() self.ThemRoster.content.name = 'Them' self.add_widget(self.UsRoster) self.add_widget(self.ThemRoster) self.VMeet = TabbedPanelHeader(text='Varsity Meet') self.JVMeet = TabbedPanelHeader(text='Junior Varsity Meet') self.VMeet.content = DualMeet() self.JVMeet.content = DualMeet() self.add_widget(self.VMeet) self.add_widget(self.JVMeet) self.JVMeet.content.UsRoster = self.UsRoster.content self.JVMeet.content.ThemRoster = self.ThemRoster.content self.JVMeet.content.Daddy = self self.VMeet.content.UsRoster = self.UsRoster.content self.VMeet.content.ThemRoster = self.ThemRoster.content self.VMeet.content.Daddy = self self.VMeet.content.populate() self.JVMeet.content.populate()
def simple_list(player_list, budget = 35000, debug=False, logger=None): """ player_list is a list of Player objects sort players by value/cost for each player, starting by the 'best' take the player IF we have a slot for it and it's under budget """ remaining_budget = budget roster = Roster() player_list.sort(key=lambda p: p.value/p.fan_duel_cost, reverse=True) for p in player_list: if roster.allocated[p.position] < roster.limits[p.position] and \ remaining_budget >= p.fan_duel_cost: roster.add(p) remaining_budget -= p.fan_duel_cost logger.debug("Currently have %d players: %s", roster.length(), roster) logger.debug("Budget: %d/%d", remaining_budget, budget) elif debug: #TODO: replauce debub with logger state if p.fan_duel_cost > remaining_budget: reason_string = "player cost (%d) was over remaining budget (%d/%d)" % ( p.fan_duel_cost, remaining_budget, budget) else: reason_string = "slot for position %s already has %d members" % ( p.position, roster.allocated[p.position]) logger.debug(("Skipped %s because " % p.name) + reason_string) if roster.is_full(): break #testing roster.test_invariants(budget) return roster
def _init_rosters(): roster_data = read_csv('CSV/Teams.csv') # initialize return variable roster_list = [] # initialize roster basic info for data in roster_data: temp_roster = Roster(data[0], data[1], data[2]) roster_list.append(temp_roster) return roster_list
def simple_list(player_list, budget=35000, logger=None): """ player_list is a list of Player objects sort players by value/cost for each player, starting by the 'best' take the player IF we have a slot for it and it's under budget """ remaining_budget = budget roster = Roster() # player_list.sort(key=lambda p: p.value/p.fan_duel_cost, reverse=True) # find min player cost min_cost = sorted(p.getFanDuelCost() for p in player_list)[9] player_list.sort(key=lambda p: p.getFPPG(), reverse=True) for p in player_list: if ( roster.allocated[p.position] < roster.limits[p.position] and remaining_budget - p.fan_duel_cost >= (9 - roster.length()) * min_cost ): roster.add(p) remaining_budget -= p.fan_duel_cost logger.debug("Currently have %d players: %s", roster.length(), roster) logger.debug("Budget: %d/%d", remaining_budget, budget) elif logger.getEffectiveLevel() <= logging.DEBUG: if p.fan_duel_cost > remaining_budget: reason_string = "player cost (%d) was over remaining budget (%d/%d)" % ( p.fan_duel_cost, remaining_budget, budget, ) else: reason_string = "slot for position %s already has %d members" % ( p.position, roster.allocated[p.position], ) logger.debug(("Skipped %s because " % p.name) + reason_string) if roster.is_full(): break roster.test_invariants(budget) if logger.getEffectiveLevel() <= logging.DEBUG: roster_log(logger, roster, budget, remaining_budget) return roster
def __init__(self, configFile, printInfo=True, logTrain=True): # if printInfo is false, the trainer wont print anything self.printInfo = printInfo # assign the roster that will be used on the data self.roster = Roster() # creates a config object that stores all of the information for the settup self.config = Config(configFile) # creates the neural netowrk that will be trained self.neuralNet = NeuralNetwork(self.config.inputSize, self.config.hiddenSize, self.config.outputSize) # open a temporary file fin = open(self.config.dataFile, 'r') if fin is None: print('Error: Trainer(): data file not found:', datafile) raise ValueError() # read in all the training data self.trainingData = self.roster.readData(fin, self.config.trainingSize, self.config.delimiters) # read in all the testing data self.testingData = self.roster.readData(fin, self.config.testingSize, self.config.delimiters) # stores the accuracy of the neural network self.accuracy = None # close file after using it fin.close() # if logTrain is True run logTraining self.logTraining()
def disjoint_rosters(self, n): self.setup() rosters = [] while(len(rosters) < n): self._prob.solve() if LpStatus[self._prob.status] != 'Optimal': raise "Unable to find optimal solution" players = filter(lambda x: value(self._choices[x]) == 1, self._choices) valid = self._frame.index.map(lambda x: x in players) roster = Roster(self._frame[valid].copy()) rosters.append(roster) # Exclude these player from further iterations for player in players: if self._frame[COL_USED][player] == 0: self._frame.set_value(player, COL_USED, 1) self._prob += self._choices[player] == 0, "Exclude " + str(player) return rosters
def top_rosters(self, n): self.setup() # For some reason smaller steps like 1e-6 don't work epsilon = .001 count = 0 while(count < n): self._prob.solve() if LpStatus[self._prob.status] != 'Optimal': raise "Unable to find optimal solution" players = filter(lambda x: value(self._choices[x]) == 1, self._choices) valid = self._frame.index.map(lambda x: x in players) roster = Roster(self._frame[valid].copy()) yield roster count += 1 # Set the threshold a bit lower high_score = value(self._prob.objective) self._prob += lpSum([self._choices[player] * self._frame[COL_POINTS][player] for player in self._players]) <= high_score - epsilon, "{0}th highest".format(count)
# # 3. Replace the print_student function with a call to this # get_info function. # # 4. If you have time, try creating a Roster class that allows you to # store students. This allows us to have different Roster objects # corresponding to, say, different classes or class years. # # 5. Make sure your Roster class has a print_all method that prints the # details of every student it holds. Call it summarize, or something # similar. # ############################################################################### # Class Roster. roster = Roster() while True: # Get information and assign via unpacking, and then instantiate a new # Student. Order matters for unpacking. first, last, middle, address, email, phone = get_student_information() student = Student(first, last, middle, address, email, phone) student.print_info() # Prompt for confirmation. if confirm('Is this information correct? (Y/n) '): roster.add(student) if confirm('Would you like to add a student to the roster? (Y/n) '): continue
def __init__(self, parent): super(RosterWindow, self).__init__(None, -1, 'Roster') self.rosterModel = Roster() self.SetClientSizeWH(300, 700) self.parent = parent self.foldPanelBar = fpb.FoldPanelBar(self, size=(300, 200), style=fpb.FPB_VERTICAL, agwStyle=fpb.FPB_SINGLE_FOLD) for i in range(0, len(self.rosterModel.students)): self.AddRosterItem(self.foldPanelBar, self.rosterModel.students[i]) self.foldPanelBarRemote = fpb.FoldPanelBar( self, size=(300, 200), style=fpb.FPB_VERTICAL, agwStyle=fpb.FPB_SINGLE_FOLD) for i in range(0, len(self.rosterModel.remoteList)): self.AddRosterItem(self.foldPanelBarRemote, self.rosterModel.remoteList[i]) attendance = wx.TextCtrl(self, size=(300, 80), style=wx.TE_CENTRE | wx.TE_READONLY) attendance.SetValue('Attendance \n\n Present: 3\n Absent: 11') attendance.SetForegroundColour(wx.WHITE) attendance.SetBackgroundColour('#0041C2') inClassText = wx.TextCtrl(self, size=(300, 30), style=wx.TE_CENTRE | wx.TE_READONLY) inClassText.SetValue('In Class') inClassText.SetBackgroundColour('#5CB3FF') remoteAccessText = wx.TextCtrl(self, size=(300, 30), style=wx.TE_CENTRE | wx.TE_READONLY) remoteAccessText.SetValue('Remote Access') remoteAccessText.SetBackgroundColour('#5CB3FF') remoteAccessPanel = wx.Panel(self, size=(300, 50), style=wx.TE_CENTRE) remoteAccessPanel.SetBackgroundColour('#FEEECC') addButton = wx.Button(self, label='Add Student', size=(150, 30)) addButton.Bind(wx.EVT_BUTTON, self.AddStudent) removeButton = wx.Button(self, label='Remove Student', size=(150, 30)) removeButton.Bind(wx.EVT_BUTTON, self.Remove) rosterVertSizer = wx.BoxSizer(wx.VERTICAL) rosterVertSizer.AddStretchSpacer(1) rosterVertSizer.Add(attendance, 1, wx.CENTER) rosterVertSizer.Add(inClassText, 1, wx.CENTER) rosterVertSizer.Add(self.foldPanelBar, 1, wx.CENTER) rosterVertSizer.Add(remoteAccessText, 1, wx.CENTER) rosterVertSizer.Add(self.foldPanelBarRemote, 1, wx.CENTER) rosterVertSizer.Add(remoteAccessPanel, 1, wx.CENTER) rosterHoriSizer = wx.BoxSizer(wx.HORIZONTAL) rosterHoriSizer.AddStretchSpacer(1) rosterHoriSizer.Add(addButton, 1, wx.CENTER) rosterHoriSizer.Add(removeButton, 1, wx.CENTER) rosterHoriSizer.AddStretchSpacer(1) rosterVertSizer.Add(rosterHoriSizer, 1, wx.CENTER) rosterVertSizer.AddStretchSpacer(1) self.Bind(wx.EVT_CLOSE, self.onClose) self.SetSizer(rosterVertSizer) self.SendSizeEvent() EClass.GetInstance().rosterModel = self.rosterModel
class RosterWindow(wx.Frame): def __init__(self, parent): super(RosterWindow, self).__init__(None, -1, 'Roster') self.rosterModel = Roster() self.SetClientSizeWH(300, 700) self.parent = parent self.foldPanelBar = fpb.FoldPanelBar(self, size=(300, 200), style=fpb.FPB_VERTICAL, agwStyle=fpb.FPB_SINGLE_FOLD) for i in range(0, len(self.rosterModel.students)): self.AddRosterItem(self.foldPanelBar, self.rosterModel.students[i]) self.foldPanelBarRemote = fpb.FoldPanelBar( self, size=(300, 200), style=fpb.FPB_VERTICAL, agwStyle=fpb.FPB_SINGLE_FOLD) for i in range(0, len(self.rosterModel.remoteList)): self.AddRosterItem(self.foldPanelBarRemote, self.rosterModel.remoteList[i]) attendance = wx.TextCtrl(self, size=(300, 80), style=wx.TE_CENTRE | wx.TE_READONLY) attendance.SetValue('Attendance \n\n Present: 3\n Absent: 11') attendance.SetForegroundColour(wx.WHITE) attendance.SetBackgroundColour('#0041C2') inClassText = wx.TextCtrl(self, size=(300, 30), style=wx.TE_CENTRE | wx.TE_READONLY) inClassText.SetValue('In Class') inClassText.SetBackgroundColour('#5CB3FF') remoteAccessText = wx.TextCtrl(self, size=(300, 30), style=wx.TE_CENTRE | wx.TE_READONLY) remoteAccessText.SetValue('Remote Access') remoteAccessText.SetBackgroundColour('#5CB3FF') remoteAccessPanel = wx.Panel(self, size=(300, 50), style=wx.TE_CENTRE) remoteAccessPanel.SetBackgroundColour('#FEEECC') addButton = wx.Button(self, label='Add Student', size=(150, 30)) addButton.Bind(wx.EVT_BUTTON, self.AddStudent) removeButton = wx.Button(self, label='Remove Student', size=(150, 30)) removeButton.Bind(wx.EVT_BUTTON, self.Remove) rosterVertSizer = wx.BoxSizer(wx.VERTICAL) rosterVertSizer.AddStretchSpacer(1) rosterVertSizer.Add(attendance, 1, wx.CENTER) rosterVertSizer.Add(inClassText, 1, wx.CENTER) rosterVertSizer.Add(self.foldPanelBar, 1, wx.CENTER) rosterVertSizer.Add(remoteAccessText, 1, wx.CENTER) rosterVertSizer.Add(self.foldPanelBarRemote, 1, wx.CENTER) rosterVertSizer.Add(remoteAccessPanel, 1, wx.CENTER) rosterHoriSizer = wx.BoxSizer(wx.HORIZONTAL) rosterHoriSizer.AddStretchSpacer(1) rosterHoriSizer.Add(addButton, 1, wx.CENTER) rosterHoriSizer.Add(removeButton, 1, wx.CENTER) rosterHoriSizer.AddStretchSpacer(1) rosterVertSizer.Add(rosterHoriSizer, 1, wx.CENTER) rosterVertSizer.AddStretchSpacer(1) self.Bind(wx.EVT_CLOSE, self.onClose) self.SetSizer(rosterVertSizer) self.SendSizeEvent() EClass.GetInstance().rosterModel = self.rosterModel def AddRosterItem(self, fpb, username): if fpb == self.foldPanelBar: foldPanel = self.foldPanelBar.AddFoldPanel(username, collapsed=True) # TODO use actual student panel = RosterItemPanel(foldPanel, Student('Dummy', 'Ymmud')) self.foldPanelBar.AddFoldPanelWindow(foldPanel, panel) elif fpb == self.foldPanelBarRemote: foldPanel = self.foldPanelBarRemote.AddFoldPanel(username, collapsed=True) # TODO use actual student panel = RosterItemPanel(foldPanel, Student('Dummy', 'Ymmud')) self.foldPanelBarRemote.AddFoldPanelWindow(foldPanel, panel) def AddStudent(self, event): self.rosterModel.AddNewStudent() def Remove(self, event): self.rosterModel.RemoveStudent() def onClose(self, event): self.parent.showRosterMenuItem.Check(False) self.Hide()
def getCurrentRoster(): roster = Roster([3213, 1194, 4020, 3056]); # takes an argument of players to exclude weeklyPlan = WeeklyPlan(roster.getWeeklyRoster(), roster.getWeeklySchedule());
# # 3. Replace the print_student function with a call to this # get_info function. # # 4. If you have time, try creating a Roster class that allows you to # store students. This allows us to have different Roster objects # corresponding to, say, different classes or class years. # # 5. Make sure your Roster class has a print_all method that prints the # details of every student it holds. Call it summarize, or something # similar. # ############################################################################### # Class Roster. roster = Roster() while True: # Get information and assign via unpacking, and then instantiate a new # Student. Order matters for unpacking. first, last, middle, address, email, phone = get_student_information() student = Student(first, last,middle, address, email,phone) student.print_info() # Prompt for confirmation. if confirm('Is this information correct? (Y/n) '): roster.add(student) if confirm('Would you like to add a student to the roster? (Y/n) '): continue
class Trainer: # config file is the file name of the json config file for the trainer # the roster is a class that contains support functions specific to the data # being trained def __init__(self, configFile, printInfo=True, logTrain=True): # if printInfo is false, the trainer wont print anything self.printInfo = printInfo # assign the roster that will be used on the data self.roster = Roster() # creates a config object that stores all of the information for the settup self.config = Config(configFile) # creates the neural netowrk that will be trained self.neuralNet = NeuralNetwork(self.config.inputSize, self.config.hiddenSize, self.config.outputSize) # open a temporary file fin = open(self.config.dataFile, 'r') if fin is None: print('Error: Trainer(): data file not found:', datafile) raise ValueError() # read in all the training data self.trainingData = self.roster.readData(fin, self.config.trainingSize, self.config.delimiters) # read in all the testing data self.testingData = self.roster.readData(fin, self.config.testingSize, self.config.delimiters) # stores the accuracy of the neural network self.accuracy = None # close file after using it fin.close() # if logTrain is True run logTraining self.logTraining() # this function would do one epoch with the training data def epoch(self): i = 0 while i < self.config.trainingSize: # this is the output array for back propagation result = self.roster.convert(self.trainingData[i], self.config.outputSize, self.config.resultIndex) # train the neural net with the given training data self.neuralNet.train(self.trainingData[i], result, self.config.learningRate) i += 1 # this function will train the data for the number of epochs in config def train(self): # this variable is for printing the percentage of work being done rem = self.config.epochs i = 0 while i < self.config.epochs: if self.printInfo: print('Progress [', i, ']\r', end='') self.epoch() i += 1 # test the the neural network with the training set def test(self): # number of correctly classifed examples correct = 0 # iterate through all the testing examples i = 0 while i < self.config.testingSize: # calculate the result for the training example self.neuralNet.forwardPropagation(self.testingData[i]) # get the result of the forward propagation result = self.neuralNet.getResults() # check to see if the result is correct if self.roster.compare(self.testingData[i], result, self.config.resultIndex): correct += 1 i += 1 self.accuracy = correct / self.config.testingSize return self.accuracy # logs the accuracy after each epoch to a specified dir # the file name will be log<number-hidden-neurons>.txt def logTraining(self): fd = open( self.config.logFolder + 'log' + str(self.config.hiddenSize) + '.txt', 'w') # this variable is for printing the percentage of work being done rem = self.config.epochs i = 0 while i < self.config.epochs: if self.printInfo: print('Progress [', i, ']\r', end='') self.epoch() fd.write(str(self.test())) fd.write('\n') i += 1 if self.printInfo: print('accuracy =', self.test()) fd.close()
# Enter desired parameters # All possible values are stored in the file called "usapl_parameters.txt" sex = 'Female' # Possible Values: 'Male' and 'Female' div = 'Raw Open' # Possible Values: 'All', 'Raw Open', etc. fed = 'IPF - Female' # Possible Values: 'IPF - Female' and 'IPF - Male' wclass = '-84' # Possible Values: '-84', '84+', etc. exercise = 'Total' # Possible Values: 'Total', 'Squat', 'Bench press', 'Deadlift' state = 'All' # Possible Values: 'All', 'Nationals', 'Regionals', 'New York' year = 'All' # Possible Values: 'All', '2017', etc. order = 'Weight' # Possible Values: 'Points' and 'Weight' par_list = [sex,div,fed,wclass,exercise,state,year,order] # Name of the roster file rawinputfile = '2017 Raw Nationals Roster.csv' # Weightclass and division of interest (based on values in the row roster file) weightclass = 'F-84' division = 'FR-O' # create Roster object roster = Roster(par_list, rawinputfile, weightclass, division) writetoCSV_lev3(roster.return_dict(),roster.get_col_names(), roster.build_filename()) # create RankingList object rank = RankingList(par_list) writetoCSV_lev2(rank.return_dict(),rank.get_col_names(), rank.build_filename()) # create Competition object based on competition URL reference comp = Competition('competitions-view?id=1763') writetoCSV_lev3(comp.return_hist_dict(),comp.get_hist_col_names(), comp.build_hist_filename())
import statsapi from Team import Team from datetime import datetime from Roster import Roster from Roster import valid_positions def team_roster(teamId): team_roster = statsapi.roster(teamId, rosterType=None, season=datetime.now().year, date=None) return team_roster if __name__ == '__main__': team_dict = {} teams = statsapi.get('teams', {'sportIds': 1, 'activeStatus': 'Yes'}) for team in teams['teams']: team_dict[team['id']] = Team(team) league_roster_dict = {} for teamId in team_dict.keys(): roster = team_roster(teamId) team_roster_list = roster.split('\n') league_roster_dict[teamId] = Roster(teamId, team_roster_list) print (team_dict[teamId].summary_info()) for position in valid_positions: for uniform_number in league_roster_dict[teamId].position(position): print ('{}, #{}, {}'.format(position, uniform_number, league_roster_dict[teamId].uniform_number(uniform_number)))
def __init__(self): self.Config = Config() self.Roster = Roster() self.Season = Season()