Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import tkinter as tk
- from tkinter import ttk
- import os
- reader = csv.reader(open((os.path.join('./data', 'ncaam.csv'))))
- result = {}
- for row in reader:
- key = row[0]
- result[key] = row[1:]
- pass
- ################################
- LARGE_FONT = ("Verdana", 12)
- class SPI(tk.Tk):
- def __init__(self, *args, **kwargs):
- tk.Tk.__init__(self, *args, **kwargs)
- tk.Tk.iconbitmap(self, default='icon.ico')
- tk.Tk.wm_title(self, "Sports Power Index")
- container = tk.Frame(self)
- container.pack(side="top", fill="both", expand=True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- self.frames = {}
- for F in (Teams, Final):
- frame = F(container)
- self.frames[F] = frame
- frame.grid(row=0, column=0, sticky="nsew")
- self.show_frame(Teams)
- def get_page(self, page_class):
- return self.frames [page_class]
- def show_frame(self, cont):
- frame = self.frames[cont]
- frame.tkraise()
- class Teams(tk.Frame):
- def __init__(self, controller):
- tk.Frame.__init__(self, master=None)
- self.controller = controller
- label = ttk.Label(self, text="Enter the Home Team", font=LARGE_FONT)
- label.pack(pady=10, padx=10)
- self.hometeam = tk.StringVar()
- entry = ttk.Entry(self, textvariable=self.hometeam)
- entry.pack()
- label2 = ttk.Label(self, text="Enter the Away Team", font=LARGE_FONT)
- label2.pack(pady=50, padx=50)
- self.awayteam = tk.StringVar()
- entry2 = ttk.Entry(self, textvariable=self.awayteam)
- entry2.pack()
- def _callback():
- if entry in result.keys():
- pass
- def sequence(*functions):
- def func(*args, **kwargs):
- return_value = None
- for function in functions:
- return_value = function(*args, **kwargs)
- return return_value
- self.teams = {
- 'home team': self.awayteam,
- 'away team': self.hometeam
- }
- button = ttk.Button(self, text="Calculate", state='disabled', command=sequence(lambda: _callback(), lambda:
- (controller.show_frame(Final))))
- button.pack(pady=10, padx=10, side='left')
- if entry or entry2 not in result:
- button.config(state='disabled')
- elif entry and entry2 in result:
- button.config(state='!disabled')
- class Final(tk.Frame):
- def __init__(self, controller):
- tk.Frame.__init__(self, master=None)
- self.controller = controller
- label = ttk.Label(self, text="", font=LARGE_FONT)
- label.grid(pady=10, padx=10)
- ppg2 = float(result[self.controller.teams['away team'].get()][0])
- apg2 = float(result[self.controller.teams['away team'].get()][1])
- rpg2 = float(result[self.controller.teams['away team'].get()][2])
- bpg2 = float(result[self.controller.teams['away team'].get()][3])
- spg2 = float(result[self.controller.teams['away team'].get()][4])
- win_pct2 = float(result[self.controller.teams['away team'].get()][5])
- rb_pct2 = float(result[self.controller.teams['away team'].get()][6])
- ast_pct2 = float(result[self.controller.teams['away team'].get()][7])
- sos2 = float(result[self.controller.teams['away team'].get()][8])
- fg_pct2 = float(result[self.controller.teams['away team'].get()][9])
- games2 = float(result[self.controller.teams['away team'].get()][10])
- ppg1 = float(result[self.controller.teams['home team'].get()][0])
- apg1 = float(result[self.controller.teams['home team'].get()][1])
- rpg1 = float(result[self.controller.teams['home team'].get()][2])
- bpg1 = float(result[self.controller.teams['home team'].get()][3])
- spg1 = float(result[self.controller.teams['home team'].get()][4])
- win_pct1 = float(result[self.controller.teams['home team'].get()][5])
- rb_pct1 = float(result[self.controller.teams['home team'].get()][6])
- ast_pct1 = float(result[self.controller.teams['home team'].get()][7])
- sos1 = float(result[self.controller.teams['home team'].get()][8])
- fg_pct1 = float(result[self.controller.teams['home team'].get()][9])
- games1 = float(result[self.controller.teams['home team'].get()][10])
- self.stats = {
- ppg1, ppg2,
- apg1, apg2,
- bpg1, bpg2,
- spg1, spg2,
- win_pct1, win_pct2,
- rb_pct1, rb_pct2,
- ast_pct1, ast_pct2,
- sos1, sos2,
- fg_pct1, fg_pct2,
- games1, games2
- }
- self.final1 = (
- (((((self.controller.stats[spg1] * 5) / games1) + ((self.controller.stats[apg1] * 3) / games1) + (
- (self.controller.stats[rpg1] * 4) / games1) + (self.controller.stats[bpg1] / games1)
- + ((self.controller.stats[spg1] * 2) / games1) + (self.controller.stats[win_pct1] * 106) + (
- self.controller.stats[rb_pct1] * 2)
- + (self.controller.stats[ast_pct1] * 1.5) + (self.controller.stat[sos1] * 2.5) + (
- self.controller.stat[fg_pct1] * 103.5)) * 1.1) / 29.5))
- self.final2 = (
- (((((self.controller.stats[spg2] * 5) / games2) + ((self.controller.stats[apg2] * 3) / games2) + (
- (self.controller.stats[rpg2] * 4) / games2) + (self.controller.stats[bpg2] / games2)
- + ((self.controller.stats[spg2] * 2) / games2) + (self.controller.stats[win_pct2] * 106) + (
- self.controller.stats[rb_pct2] * 2)
- + (self.controller.stats[ast_pct2] * 1.5) + (self.controller.stat[sos2] * 2.5) + (
- self.controller.stat[fg_pct2] * 103.5))) / 29.5))
- self.finals = {
- "home final": self.final2,
- "home team": self.controller['home team'],
- "away final": self.final1,
- "away team": self.controller['away team']
- }
- home_final = self.controller.fianls["home final"].get()
- home_team = self.controller.fianls["home team"].get()
- away_team = self.controller.fianls["away team"].get()
- away_final = self.controller.fianls["away final"].get()
- self.hTeamName = ttk.Label(self, textvariable=home_team, font=LARGE_FONT)
- label.pack(pady=5, padx=10)
- self.hTeamScore = ttk.Label(self, textvariable=home_final, font=LARGE_FONT)
- label.pack(pady=10, padx=10)
- self.aTeamName = ttk.Label(self, textvariable=away_team, font=LARGE_FONT)
- label.pack(pady=15, padx=10)
- self.aTeamScore = ttk.Label(self, textvariable=away_final, font=LARGE_FONT)
- label.pack(pady=20, padx=10)
- button1 = ttk.Button(self, text="Enter a New Match up",
- command=lambda: controller.show_frame(Teams))
- button1.grid()
- button2 = ttk.Button(self, text="Save(TODO)")
- button2.grid()
- app = SPI()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement