Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.18 KB | None | 0 0
  1. import csv
  2. import tkinter as tk
  3. from tkinter import ttk
  4. import os
  5. reader = csv.reader(open((os.path.join('./data', 'ncaam.csv'))))
  6.  
  7. result = {}
  8. for row in reader:
  9.     key = row[0]
  10.     result[key] = row[1:]
  11.     pass
  12.  
  13. ################################
  14. LARGE_FONT = ("Verdana", 12)
  15.  
  16.  
  17. class SPI(tk.Tk):
  18.     def __init__(self, *args, **kwargs):
  19.         tk.Tk.__init__(self, *args, **kwargs)
  20.  
  21.         tk.Tk.iconbitmap(self, default='icon.ico')
  22.         tk.Tk.wm_title(self, "Sports Power Index")
  23.  
  24.         container = tk.Frame(self)
  25.         container.pack(side="top", fill="both", expand=True)
  26.         container.grid_rowconfigure(0, weight=1)
  27.         container.grid_columnconfigure(0, weight=1)
  28.  
  29.         self.frames = {}
  30.  
  31.         for F in (Teams, Final):
  32.             frame = F(container)
  33.             self.frames[F] = frame
  34.             frame.grid(row=0, column=0, sticky="nsew")
  35.  
  36.         self.show_frame(Teams)
  37.  
  38.     def get_page(self, page_class):
  39.         return self.frames [page_class]
  40.  
  41.     def show_frame(self, cont):
  42.         frame = self.frames[cont]
  43.         frame.tkraise()
  44.  
  45.  
  46. class Teams(tk.Frame):
  47.     def __init__(self, controller):
  48.         tk.Frame.__init__(self, master=None)
  49.         self.controller = controller
  50.  
  51.         label = ttk.Label(self, text="Enter the Home Team", font=LARGE_FONT)
  52.         label.pack(pady=10, padx=10)
  53.  
  54.         self.hometeam = tk.StringVar()
  55.         entry = ttk.Entry(self, textvariable=self.hometeam)
  56.         entry.pack()
  57.  
  58.         label2 = ttk.Label(self, text="Enter the Away Team", font=LARGE_FONT)
  59.         label2.pack(pady=50, padx=50)
  60.  
  61.         self.awayteam = tk.StringVar()
  62.         entry2 = ttk.Entry(self, textvariable=self.awayteam)
  63.         entry2.pack()
  64.  
  65.         def _callback():
  66.             if entry in result.keys():
  67.                 pass
  68.  
  69.         def sequence(*functions):
  70.             def func(*args, **kwargs):
  71.                 return_value = None
  72.                 for function in functions:
  73.                     return_value = function(*args, **kwargs)
  74.                 return return_value
  75.  
  76.         self.teams = {
  77.             'home team': self.awayteam,
  78.             'away team': self.hometeam
  79.         }
  80.  
  81.         button = ttk.Button(self, text="Calculate", state='disabled', command=sequence(lambda: _callback(), lambda:
  82.                                                                                        (controller.show_frame(Final))))
  83.         button.pack(pady=10, padx=10, side='left')
  84.  
  85.         if entry or entry2 not in result:
  86.             button.config(state='disabled')
  87.         elif entry and entry2 in result:
  88.             button.config(state='!disabled')
  89.  
  90.  
  91. class Final(tk.Frame):
  92.     def __init__(self, controller):
  93.         tk.Frame.__init__(self, master=None)
  94.         self.controller = controller
  95.  
  96.         label = ttk.Label(self, text="", font=LARGE_FONT)
  97.         label.grid(pady=10, padx=10)
  98.  
  99.         ppg2 = float(result[self.controller.teams['away team'].get()][0])
  100.         apg2 = float(result[self.controller.teams['away team'].get()][1])
  101.         rpg2 = float(result[self.controller.teams['away team'].get()][2])
  102.         bpg2 = float(result[self.controller.teams['away team'].get()][3])
  103.         spg2 = float(result[self.controller.teams['away team'].get()][4])
  104.         win_pct2 = float(result[self.controller.teams['away team'].get()][5])
  105.         rb_pct2 = float(result[self.controller.teams['away team'].get()][6])
  106.         ast_pct2 = float(result[self.controller.teams['away team'].get()][7])
  107.         sos2 = float(result[self.controller.teams['away team'].get()][8])
  108.         fg_pct2 = float(result[self.controller.teams['away team'].get()][9])
  109.         games2 = float(result[self.controller.teams['away team'].get()][10])
  110.  
  111.         ppg1 = float(result[self.controller.teams['home team'].get()][0])
  112.         apg1 = float(result[self.controller.teams['home team'].get()][1])
  113.         rpg1 = float(result[self.controller.teams['home team'].get()][2])
  114.         bpg1 = float(result[self.controller.teams['home team'].get()][3])
  115.         spg1 = float(result[self.controller.teams['home team'].get()][4])
  116.         win_pct1 = float(result[self.controller.teams['home team'].get()][5])
  117.         rb_pct1 = float(result[self.controller.teams['home team'].get()][6])
  118.         ast_pct1 = float(result[self.controller.teams['home team'].get()][7])
  119.         sos1 = float(result[self.controller.teams['home team'].get()][8])
  120.         fg_pct1 = float(result[self.controller.teams['home team'].get()][9])
  121.         games1 = float(result[self.controller.teams['home team'].get()][10])
  122.  
  123.         self.stats = {
  124.             ppg1, ppg2,
  125.             apg1, apg2,
  126.             bpg1, bpg2,
  127.             spg1, spg2,
  128.             win_pct1, win_pct2,
  129.             rb_pct1, rb_pct2,
  130.             ast_pct1, ast_pct2,
  131.             sos1, sos2,
  132.             fg_pct1, fg_pct2,
  133.             games1, games2
  134.         }
  135.         self.final1 = (
  136.             (((((self.controller.stats[spg1] * 5) / games1) + ((self.controller.stats[apg1] * 3) / games1) + (
  137.                 (self.controller.stats[rpg1] * 4) / games1) + (self.controller.stats[bpg1] / games1)
  138.                + ((self.controller.stats[spg1] * 2) / games1) + (self.controller.stats[win_pct1] * 106) + (
  139.                    self.controller.stats[rb_pct1] * 2)
  140.                + (self.controller.stats[ast_pct1] * 1.5) + (self.controller.stat[sos1] * 2.5) + (
  141.                    self.controller.stat[fg_pct1] * 103.5)) * 1.1) / 29.5))
  142.  
  143.         self.final2 = (
  144.             (((((self.controller.stats[spg2] * 5) / games2) + ((self.controller.stats[apg2] * 3) / games2) + (
  145.                 (self.controller.stats[rpg2] * 4) / games2) + (self.controller.stats[bpg2] / games2)
  146.                + ((self.controller.stats[spg2] * 2) / games2) + (self.controller.stats[win_pct2] * 106) + (
  147.                    self.controller.stats[rb_pct2] * 2)
  148.                + (self.controller.stats[ast_pct2] * 1.5) + (self.controller.stat[sos2] * 2.5) + (
  149.                    self.controller.stat[fg_pct2] * 103.5))) / 29.5))
  150.         self.finals = {
  151.             "home final": self.final2,
  152.             "home team": self.controller['home team'],
  153.             "away final": self.final1,
  154.             "away team": self.controller['away team']
  155.         }
  156.  
  157.         home_final = self.controller.fianls["home final"].get()
  158.         home_team = self.controller.fianls["home team"].get()
  159.         away_team = self.controller.fianls["away team"].get()
  160.         away_final = self.controller.fianls["away final"].get()
  161.  
  162.         self.hTeamName = ttk.Label(self, textvariable=home_team, font=LARGE_FONT)
  163.         label.pack(pady=5, padx=10)
  164.  
  165.         self.hTeamScore = ttk.Label(self, textvariable=home_final, font=LARGE_FONT)
  166.         label.pack(pady=10, padx=10)
  167.  
  168.         self.aTeamName = ttk.Label(self, textvariable=away_team, font=LARGE_FONT)
  169.         label.pack(pady=15, padx=10)
  170.  
  171.         self.aTeamScore = ttk.Label(self, textvariable=away_final, font=LARGE_FONT)
  172.         label.pack(pady=20, padx=10)
  173.  
  174.         button1 = ttk.Button(self, text="Enter a New Match up",
  175.                              command=lambda: controller.show_frame(Teams))
  176.         button1.grid()
  177.  
  178.         button2 = ttk.Button(self, text="Save(TODO)")
  179.         button2.grid()
  180.  
  181.  
  182. app = SPI()
  183. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement