def submitcallback(): ImagePath= save_as_png(cv,'Image') model=getmodel() try: Result,message=calculate(ImagePath,model,digital=True) except: message='An error happened, Please try again' if message: messagebox.showerror("Error", message) else: messagebox.showinfo(title='Operation Done', message='The result of the operation is '+str(Result))
def fileDialog2(): filename_uploaded = filedialog.askopenfilename(title = "Select An uncropped Image", filetype =ftypes,initialdir="/") dst=os.path.join(BASE_PATH, r"app/Images/Image.png") ImagePath=copy(filename_uploaded,dst) model=getmodel() try: Result,message=calculate(ImagePath,model,digital=False,scan=True) except: message='An error happened, Please try again' if message: messagebox.showerror("Error", message) else: messagebox.showinfo(title='Operation Done', message='The result of the operation is '+str(Result))
def show_team_history(): rd = setup_nav() form = HistoryForm(request.form, prefix="form") cpg = ComparisonGraphForm() ggf = GameGraphForm(request.form, prefix="game-form") cpg.xaxis.data = "season" now = datetime.datetime.now().date() extrateams = [] if request.method == "POST" and form.validate(): extrateams = ggf.steam.data print extrateams else: form.endingDate.data = now form.startingDate.data = datetime.datetime.strptime( "2002-10-01", "%Y-%m-%d").date() startingDate = form.startingDate.data endingDate = form.endingDate.data if endingDate is None: endingDate = datetime.datetime.strptime("2002-10-01", "%Y-%m-%d").date() team = form.filterTeams.data team = [ team, ] team.extend(extrateams) columns = form.tablecolumns.data regularplayoffs = form.regularplayoffs.data # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [ constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict ] else: teamstrengths = [ teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [ constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict ] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [ int(homeaway), ] periods = constants.periods_options["All"]["value"] if 0 in periods: periods = [ 0, ] if 7 in scoresituations: scoresituations = [ 7, ] if 7 in teamstrengths: teamstrengths = [ 7, ] teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(team), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, True) return render_template("teams/teamhistory.html", rd=rd, cpg=cpg, ggf=ggf, form=form, games=games, seasons=seasons)
def show_team_comparisons(): rd = setup_nav() cpg = ComparisonGraphForm() teamgames = get_r_seasons() tablecolumns = [ 0, ] form = ComparisonForm(request.form) form.startingSeason.choices = [ (x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True) ] form.endingSeason.choices = [ (x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True) ] filterteams = form.filterTeams.data if filterteams is None: filterteams = [] allteams = form.filterTeams.choices try: oldStart = form.startingSeason.data oldEnd = form.endingSeason.data form.startingSeason.data = int(form.startingSeason.data) form.endingSeason.data = int(form.endingSeason.data) except: pass allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] usedates = False if request.method == "POST" and form.validate(): startingSeason = form.startingSeason.data endingSeason = form.endingSeason.data form.startingSeason.data = oldStart form.endingSeason.data = oldEnd startingDate = form.startingDate.data endingDate = form.endingDate.data usedates = form.bydate.data if not usedates: if endingSeason > startingSeason: begin = startingSeason end = endingSeason else: begin = endingSeason end = startingSeason currSeason = begin seasons = [ begin, ] # TODO: Error check this? while begin != end: bsplit = str(begin)[0:4] begin = int(bsplit) * 10000 + 10001 + int(bsplit) + 1 seasons.append(begin) else: if endingDate < startingDate: temp = endingDate endingDate = startingDate startingDate = temp else: smax = max(teamgames.keys()) seasons = [ smax, ] # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [ constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict ] else: teamstrengths = [ teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [ constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict ] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [ int(homeaway), ] periods = constants.periods_options[form.period.data]["value"] if 0 in periods: periods = [ 0, ] if 7 in scoresituations: scoresituations = [ 7, ] if 7 in teamstrengths: teamstrengths = [ 7, ] if not usedates: if len(filterteams) == 0: teamrun = TeamRun.query.filter( TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter( TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() else: if len(filterteams) == 0: teamrun = TeamRun.query.filter( TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter( TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, form.divideSeason.data) if form.splitgame.data == True: summaries = games else: summaries = seasons return render_template('teams/teamcomparison.html', rd=rd, form=form, summaries=summaries, cpg=cpg, filterteams=filterteams, allteams=allteams)
def show_team_history(): rd = setup_nav() form = HistoryForm(request.form, prefix="form") cpg = ComparisonGraphForm() ggf = GameGraphForm(request.form, prefix="game-form") cpg.xaxis.data = "season" now = datetime.datetime.now().date() extrateams = [] if request.method == "POST" and form.validate(): extrateams = ggf.steam.data; print extrateams else: form.endingDate.data = now form.startingDate.data = datetime.datetime.strptime("2002-10-01", "%Y-%m-%d").date() startingDate = form.startingDate.data endingDate = form.endingDate.data if endingDate is None: endingDate = datetime.datetime.strptime("2002-10-01", "%Y-%m-%d").date() team = form.filterTeams.data team = [team, ] team.extend(extrateams) columns = form.tablecolumns.data regularplayoffs = form.regularplayoffs.data # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict] else: teamstrengths = [teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [int(homeaway), ] periods = constants.periods_options["All"]["value"] if 0 in periods: periods = [0, ] if 7 in scoresituations: scoresituations = [7, ] if 7 in teamstrengths: teamstrengths = [7, ] teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(team), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, True) return render_template("teams/teamhistory.html", rd=rd, cpg=cpg, ggf=ggf, form=form, games=games, seasons=seasons)
def show_team_comparisons(): rd = setup_nav() cpg = ComparisonGraphForm() teamgames = get_r_seasons() tablecolumns = [0, ] form = ComparisonForm(request.form) form.startingSeason.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] form.endingSeason.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] filterteams = form.filterTeams.data if filterteams is None: filterteams = [] allteams = form.filterTeams.choices try: oldStart = form.startingSeason.data oldEnd = form.endingSeason.data form.startingSeason.data = int(form.startingSeason.data) form.endingSeason.data = int(form.endingSeason.data) except: pass allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] usedates = False if request.method == "POST" and form.validate(): startingSeason = form.startingSeason.data endingSeason = form.endingSeason.data form.startingSeason.data = oldStart form.endingSeason.data = oldEnd startingDate = form.startingDate.data endingDate = form.endingDate.data usedates = form.bydate.data if not usedates: if endingSeason > startingSeason: begin = startingSeason end = endingSeason else: begin = endingSeason end = startingSeason currSeason = begin seasons = [begin, ] # TODO: Error check this? while begin != end: bsplit = str(begin)[0:4] begin = int(bsplit) * 10000 + 10001 + int(bsplit) + 1 seasons.append(begin) else: if endingDate < startingDate: temp = endingDate endingDate = startingDate startingDate = temp else: smax = max(teamgames.keys()) seasons = [smax, ] # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict] else: teamstrengths = [teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [int(homeaway), ] periods = constants.periods_options[form.period.data]["value"] if 0 in periods: periods = [0, ] if 7 in scoresituations: scoresituations = [7, ] if 7 in teamstrengths: teamstrengths = [7, ] if not usedates: if len(filterteams) == 0: teamrun = TeamRun.query.filter(TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter(TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() else: if len(filterteams) == 0: teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, form.divideSeason.data) if form.splitgame.data == True: summaries = games else: summaries = seasons return render_template('teams/teamcomparison.html', rd=rd, form=form, summaries=summaries, cpg=cpg, filterteams=filterteams, allteams=allteams)