コード例 #1
0
def RefreshScheduleFiles():
    now = datetime.now()
    year = int(now.year)
    scrape_schedule.year = year
    scrape_schedule.main(sys.argv[1:])
コード例 #2
0
ファイル: score_week.py プロジェクト: tonylom3/pyBlitz
def PredictTournament(week, stat_file, merge_file, verbose):
    now = datetime.now()
    year = int(now.year)
    week_path = "{0}{1}/".format(settings.predict_root, year)
    sched_path = "{0}{1}/{2}".format(settings.predict_root, year,
                                     settings.predict_sched)
    saved_path = "{0}{1}/{2}".format(settings.predict_root, year,
                                     settings.predict_saved)
    weekly_files = GetSchedFiles(week_path, "week*.csv")
    SaveOffFiles(saved_path, weekly_files)
    for p in Path(week_path).glob("week*.csv"):
        p.unlink()
    if (not CurrentStatsFile(stat_file)):
        RefreshStats()
    schedule_files = GetSchedFiles(sched_path, "sched*.json")
    if (not schedule_files):
        scrape_schedule.year = now.year
        scrape_schedule.main(sys.argv[1:])
        schedule_files = GetSchedFiles(sched_path, "sched*.json")
    if (not schedule_files):
        print(
            "schedule files are missing, run the scrape_schedule tool to create"
        )
        exit()
    dict_merge = []
    if (not os.path.exists(merge_file)):
        print(
            "master merge file is missing, run the combine_merge tool to create"
        )
        exit()
    with open(merge_file) as mergefile:
        dict_merge = json.load(mergefile, object_pairs_hook=OrderedDict)
    if (not os.path.exists(stat_file)):
        print(
            "statistics file is missing, run the combine_stats tool to create")
        exit()
    with open(stat_file) as stats_file:
        dict_stats = json.load(stats_file, object_pairs_hook=OrderedDict)
    list_schedule = []
    for file in schedule_files:
        with open(file) as schedule_file:
            item = json.load(schedule_file, object_pairs_hook=OrderedDict)
            list_schedule.append(item)
    weeks = GetWeekRange(week, list_schedule)
    if (not "a" in week.lower().strip()):
        idx = GetIndex(week)
        if ((idx < 1) or (idx > len(schedule_files))):
            week = "current"
    print("Weekly Prediction Tool")
    print("**************************")
    print("Statistics file:\t{0}".format(stat_file))
    print("Team Merge file:\t{0}".format(merge_file))
    print("\trunning for Week: {0}".format(week))
    print("\tDirectory Location: {0}".format(week_path))
    print("**************************")
    for idx in range(len(schedule_files)):
        if (idx in weeks):
            list_predict = []
            list_predict.append([
                "Index", "Year", "Date", "TeamA", "AbbrA", "ChanceA", "ScoreA",
                "Spread", "TeamB", "AbbrB", "ChanceB", "ScoreB", "Exceptions"
            ])
            index = 0
            for item in list_schedule[idx].values():
                teama, teamb = FindTeams(item["TeamA"], item["TeamB"],
                                         dict_merge)
                abbra, abbrb = FindAbbr(teama, teamb, dict_merge)
                neutral = False
                if (item["Home"].lower().strip() == "neutral"):
                    neutral = True
                settings.exceptions = []
                dict_score = pyBlitz.Calculate(teama, teamb, neutral, verbose)
                errors = " "
                if (settings.exceptions):
                    for itm in settings.exceptions:
                        errors += itm + ", "
                errors = errors[:-2]
                index += 1
                if (len(dict_score) > 0):
                    list_predict.append([
                        str(index), item["Year"], item["Date"], item["TeamA"],
                        abbra, dict_score["chancea"], dict_score["scorea"],
                        dict_score["spread"], item["TeamB"], abbrb,
                        dict_score["chanceb"], dict_score["scoreb"], errors
                    ])
                else:
                    list_predict.append([
                        str(index), item["Year"], item["Date"], item["TeamA"],
                        abbra, "?", "?", "?", item["TeamB"], abbrb, "?", "?",
                        "Warning: cannot predict, both teams missing, fix the merge spreadsheets"
                    ])
                    print(
                        "Warning: Neither {0} or {1} have been found, \n\t Suggest reviewing/fixing the merge spreadsheet(s) and re-run"
                        .format(item["TeamA"], item["TeamB"]))
            Path(week_path).mkdir(parents=True, exist_ok=True)
            output_file = "{0}week{1}.csv".format(
                week_path, GetIndex(schedule_files[idx]))
            SaveStats(output_file, week_path, stat_file)
            predict_sheet = open(output_file, 'w', newline='')
            csvwriter = csv.writer(predict_sheet)
            for row in list_predict:
                csvwriter.writerow(row)
            predict_sheet.close()
            print("{0} has been created.".format(output_file))

    # How are we doing? Let's find Out!
    file = "{0}results.json".format(saved_path)
    if (os.path.exists(file)):
        dict_results = []
        last_week = GetIndex(week) - 1
        with open(file) as results_file:
            dict_results.append(
                json.load(results_file, object_pairs_hook=OrderedDict))
        if (len(dict_results) > 0):
            for idx in range(len(dict_results)):
                for item in dict_results[idx].values():
                    if (last_week > 0 and last_week == item["Week"]):
                        print(
                            "================================================="
                        )
                        print("For week{0}, winning percent was: {1}%".format(
                            last_week, item["Percent Correct"]))
                        print(
                            "================================================="
                        )
                    if (item["Week"] == 99):
                        print(
                            "================================================="
                        )
                        print("For this year so far, winning percent is: {0}%".
                              format(item["Percent Correct"]))
                        print(
                            "================================================="
                        )
    print("done.")
コード例 #3
0
ファイル: test_abbreviations.py プロジェクト: kcfike/pyBlitz
now = datetime.datetime.now()
year = int(now.year)
lastyear = year - 1
path = "{0}{1}/{2}".format(settings.predict_root, lastyear,
                           settings.predict_sched)

file = '{0}merge.json'.format(settings.data_path)
if (not os.path.exists(file)):
    print("merge.json file is missing, run the combine_merge tool to create")
    exit()
with open(file) as merge_file:
    dict_merge = json.load(merge_file, object_pairs_hook=OrderedDict)

scrape_schedule.year = lastyear
scrape_schedule.main(sys.argv[1:])
schedule_files = GetSchedFiles(path, "sched*.json")

if (not os.path.exists(schedule_files[0])):
    print("schedule files are missing, run the scrape_schedule tool to create")
    exit()

list_schedule = []
for file in schedule_files:
    with open(file) as schedule_file:
        list_schedule.append(
            json.load(schedule_file, object_pairs_hook=OrderedDict))
AllAbbr = []
for idx in range(len(schedule_files)):
    for item in list_schedule[idx].values():
        abbrw, abbrl = GetSchedAbbr(item["Score"])
コード例 #4
0
ファイル: scrape.py プロジェクト: tonylom3/pyBlitz
def RefreshSched(year):
    scrape_schedule.year = year
    scrape_schedule.main(sys.argv[1:])