Skip to content

Instantly share code, notes, and snippets.

@illuzian
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save illuzian/68b881c4cc8ada3f84af to your computer and use it in GitHub Desktop.

Select an option

Save illuzian/68b881c4cc8ada3f84af to your computer and use it in GitHub Desktop.
from Tkinter import *
from ttk import *
import urllib
import csv
import operator
from collections import OrderedDict
class Lotto(object):
def __init__(self, url='http://dev-spook/callcentre/jason/MondayLotto-05-01-2015-19-02.csv'):
self.common_num = None
self.common_combos = None
self.url = url
self.i = 0
self.j = 0
self.num_counts = {}
self.num_freqs = {}
self.data = None
self.num_label_text = None
self.get_csv(url)
def get_csv(self, url):
# Allow manually setting csv data using custom url via get_csv method
response = urllib.urlopen(url)
self.data = csv.reader(response, delimiter=",")
# Rename to something more meaningful e.g get_occurances()
def get_occurances(self, from_col, to_col): # Make the columns dynamic
for row in self.data:
if self.i:
for num in row[from_col:to_col]:
if num in self.num_counts:
self.num_counts[num] += 1
else:
self.num_counts[num] = 1
for num1 in row[2:7]:
if num1 == num:
pass
elif num in self.num_freqs:
if num1 in self.num_freqs[num]:
self.num_freqs[num][num1] += 1
else:
self.num_freqs[num][num1] = 1
else:
self.num_freqs[num] = {}
self.num_freqs[num] = OrderedDict(sorted(self.num_freqs[num].items(), key=operator.itemgetter(1), reverse=True))
self.i += 1
sorted_counts = OrderedDict(sorted(self.num_counts.items(), key=operator.itemgetter(1), reverse=True))
sorted_freqs = sorted(self.num_freqs.items(), key=lambda x: max(x[1].values()), reverse=True)
self.common_num = sorted_counts.keys()[:6]
self.common_combos = {k: OrderedDict((a, b) for a, b in v.iteritems() if a in v.keys()[:6]) for k, v in sorted_freqs if k in sorted_counts.keys()[:6]}
return [self.common_num, self.common_combos]
lotto_calc = Lotto()
main_num = lotto_calc.get_occurances(2, 7) # Main
sub_num = lotto_calc.get_occurances(8.9) # Subs
class LottoUI(Frame):
def __init__(self, master):
Frame.__init__(self, master)
lotto = Lotto()
self.pack()
self.style = Style()
# self.style.theme_use("default")
self.num_label = None
self.num_view = None
self.num_view_text = lotto.common_num
self.create_widgets()
def create_widgets(self):
top_frame = Frame(root)
top_frame.pack(side=TOP)
middle_frame = Frame(root)
middle_frame.pack()
bottom_frame = Frame(root)
bottom_frame.pack(side=BOTTOM)
self.num_label = Label(top_frame, text='Your Suggested numbers for this week are...')
self.num_label.pack()
self.num_view = Label(middle_frame, text=self.num_view_text)
self.num_view.pack()
root = Tk()
root.geometry("300x80")
root.resizable(width=FALSE, height=FALSE)
root.title("Monday Lotto Analyser")
app = LottoUI(root)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment