def get_todays_optimal_lineup(self): # # uncomment to also prepare csvs print "Step 0: Getting data and creating CSVs." # let's first get all the data we need and store it in csvs ch = CSVHelper() ch.create_csvs() print "---> Data successfully stored!" print "Step 1: Preparing data from CSVs :)" # let's prepare out data for projections dp = DailyProjector() dp.prepare_data_for_projections("data/numberfire_data_sample.txt") print "------> Data is prepared!" print "Step 2: Time to make some projections :)" # let's get the projections based on the prepared data projections = dp.project_fd_score() print projections print "------> Projections are ready!" print "Step 3: Let's get that golden lineup!!!!" # let's get the optimal lineup based on the projections lo = LineupOptimizer(projections) with open('static/data/optimal_lineup.json', 'wb') as ol: json.dump(lo.optimize(), ol) print "------> Your lineup has been stored in static/data/optimal_lineup.json. \ Let's make some cash money ;)" print "------> This lineup can also be viewed at \
def prepare_data_for_projections(self, text_file=None): nf_scraper = NumberFireScraper() if text_file: with open(text_file, 'r') as inf: for line in inf: nf_data = eval(line) else: nf_data = nf_scraper.get_todays_player_data() csv_helper = CSVHelper() self.players, nf_to_stattleship_map = \ csv_helper.prepare_data_from_csvs() for nf_id, attributes in nf_data.iteritems(): stattleship_slug = nf_to_stattleship_map[nf_id] self.upcoming_games[stattleship_slug] = dict() for attr in attributes: self.upcoming_games[stattleship_slug][attr] = \ nf_data[nf_id][attr] # setting team to unknown if it is not known # it is unknown between days when numberfire is switching over if 'team' not in self.upcoming_games[stattleship_slug].keys(): self.upcoming_games[stattleship_slug]['team'] = 'UNK'