def __init__(self, season=2014, week=-1): self.week = week if self.week == -1: self.week = "ALL" self.season = season self.season_examples = [] self.season_examples_file = '../resources/data/' + str(season) + '_week_' + str(self.week) + '_examples.csv' # TODO: write a test for this write_to_file flag self.write_to_file = True self.writer = nfl_example_io() self.ordered_columns = ['Season', 'Week', 'HOMEteam', 'AWAYteam', 'HOMEscore', 'AWAYscore']
def test_examples_for_one_week_in_one_season(self): # loop through each game a of particular week and # create example for each game and write to csv for game in self.schedule: if game["Week"] == str(self.week_num): home_team = game["HomeTeam"] away_team = game["AwayTeam"] if home_team != "BYE" and away_team != "BYE": example = nfl_example_maker(home_team, away_team, self.season, self.week_num) self.examples.append(example) key_order = self.examples[0].ordered_example_keys writer = nfl_example_io() writer.create_header(key_order, self.csv_output_file) for i in range(len(self.examples)): writer.write(self.examples[i].example_data_dict, key_order, self.csv_output_file, "a")
# TODO: need to recreate this file using existing data so as to not miss any new max or min values that may # have come in 2015 or 2016, since it was created only using data up to 2014 min_max_file = "../resources/data/all_examples_with_dvoa_no_teams_normalized_min_max.csv" data_list = [] with open(raw_data_file, "r") as data_file: reader = csv.DictReader(data_file) for line in reader: data_list.append(line) # this will churn through all the data and create a normalized data set # normalized_data = normalizer.normalize_data(data_list) normalizer = data_normalizer() normalized_data = normalizer.normalize_data_with_min_max_file(data_list, min_max_file) # the normal example file uses season, week, home, away as column headers but those are only for readability. They # are not needed for any inputs or outputs, so ignoring them here when creating the normalized data which is explicitly # used for input/output. key_order = example_creator.season_examples[0].ordered_example_keys key_order.remove("HOMEteam") key_order.remove("AWAYteam") key_order.remove("Season") key_order.remove("Week") writer = nfl_example_io() writer.create_header(key_order, normalized_data_file) for i in range(len(normalized_data)): writer.write(normalized_data[i], key_order, normalized_data_file, "a")
def setUp(self): self.csv_file = '/tmp/csv_test_file.csv' self.maxDiff = None self.writer = nfl_example_io()