-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlooper.py
177 lines (150 loc) · 6.47 KB
/
looper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# -*- coding: utf-8 -*-
"""
Created on Wed May 12 17:28:46 2021
@author: Omar Olivarez
"""
import tkinter
from tkinter import *
from tkinter import font
from tkinter.filedialog import askopenfilename
import pandas as pd
from tkinter.ttk import Frame, Button, Style, Progressbar
from tkinter import scrolledtext
import os
import datetime
import sqlite3
import bstrap as bs
class Looper(Frame):
def __init__(self):
super().__init__()
self.initUI()
self.path = ""
self.reps_path = ""
#self.starting_row = 0
self.df = 0
self.con = sqlite3.connect("looper.db")
self.cur = self.con.cursor()
self.table_name = ""
def initUI(self):
# this section sets which columns are the ones that move - weight is what will expand when expanded
self.pack(fill=BOTH, expand=True)
#self.rowconfigure(5, pad=7)
#self.rowconfigure(17, weight=1)
#self.columnconfigure(3, weight=1)
#self.columnconfigure(3, pad=7)
menubar = Menu(self.master)
self.master.config(menu=menubar)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Import csv", command=self.import_csv_data)
#filemenu.add_separator()
#filemenu.add_command(label="Save", command=self.save)
menubar.add_cascade(label="File", menu=filemenu)
region_l = Label(self, text = "Label 1")
region_l.grid(row = 1, column = 0, padx = 0, sticky=W)
region_2 = Label(self, text = "Label 2")
region_2.grid(row = 1, column = 1, padx = 0, sticky=E)
self.progress = Progressbar(self, orient = HORIZONTAL, length=750, mode = 'determinate')
self.progress.grid(row=0, column = 0, columnspan=2, pady = 3, padx = 3, sticky=N+S+E+W)
def import_csv_data(self):
csv_file_path = askopenfilename()
self.setPath(csv_file_path)# .set(csv_file_path)
d = pd.read_csv(self.getPath())
self.setDataframe(d)
self.popup_details()
#print("HERE")
def import_reps(self):
print("IMPORT REPS()")
if self.radio == 2:
reps_file_path = askopenfilename()
self.set_reps_path(reps_file_path)# .set(csv_file_path)
f = open(self.get_reps_path(), "r")
self.set_reps(f)
def popup_details(self):
win = Toplevel()
win.wm_title("Details")
win.geometry("230x230") # width by height
win.minsize("220", "230")
win.rowconfigure(5, weight=1)
win.columnconfigure(1, weight=1)
self.radio = IntVar() # use this to store the value of the radio button
self.radio.set(1)
l = Label(win, text="Column to bootstrap")
l.grid(row=0, column=0, pady=(10, 0), padx=(10, 0))
COL_OPTS= list(self.df)
self.col_var = StringVar(self)
self.col_var.set(COL_OPTS[0]) # default value
dropdown_col = OptionMenu(win, self.col_var, *COL_OPTS) #, command=lambda _: self.getFont()
dropdown_col.config(indicatoron=False)
dropdown_col.grid(row = 0, column=1, sticky = W, pady=(10, 0))
stats_label = Label(win, text="Statistic")
stats_label.grid(row=1, column=0, sticky=E, pady=(5, 0))
STAT_OPTS= ['Mean', 'Median', 'St Dev']
self.stat_var = StringVar(self)
self.stat_var.set(STAT_OPTS[0]) # default value
dropdown_stat = OptionMenu(win, self.stat_var, *STAT_OPTS)
dropdown_stat.config(indicatoron=False)
dropdown_stat.grid(row = 1, column=1, sticky = W, pady=(5, 0))
reps_label = Label(win, text="Repetitions")
reps_label.grid(row=2, column=0, sticky=E, pady=(5, 0))
self.reps = Entry(win, width='12')
self.reps.grid(row=2, column=1, sticky=W, pady=(5, 0))
reps_file_label = Label(win, text="Upload reps file?")
reps_file_label.grid(row=3, column=0, sticky=E, pady=(5, 0))
no_rb = Radiobutton(win, text="No", variable=self.radio, value=1)
no_rb.grid(row = 3, column = 1, pady=(5, 0), sticky = W)
self.yes_rb = Radiobutton(win, text="Yes", variable=self.radio, value=2)
self.yes_rb.grid(row = 4, column = 1, pady=(5, 0), sticky = W)
b = Button(win, text="Next", command= self.create_table) #lambda:[win.destroy, self.create_table, self.import_reps]
b.grid(row=5, column=1, sticky=S+W, pady=(5, 10), padx=(0, 10))
def create_table(self):
print("CREATE TABLE()")
# NOTE: in a future feature, I need to know how to handle what happens if someone wants to run bootstrap for the same column and metric all over
# again given that I think in the current state it would just append to the previous results
self.set_table_name()
print(self.table_name)
#col_1 = self.col_var.get().upper() + "_" + self.stat_var.get().upper() + "S"
#print(col_1)
"""self.cur.execute('SELECT * FROM ?', (self.table_name))
entry = self.cur.fetchone()
if entry is None:
self.cur.execute('CREATE TABLE ? ', ('a', 'b', 'c'))
print('New table created')
else:
print('Table already exists')
return"""
create_table_query = "CREATE TABLE IF NOT EXISTS " + self.table_name + " (id integer PRIMARY KEY,statistic integer);"
#create_table_query = "CREATE TABLE IF NOT EXISTS liwc_means (id integer PRIMARY KEY,statistic integer);"
print(create_table_query)
self.cur.execute(create_table_query)
def getFont(self):
return
#col = self.font_var.get()
#self.myFont.configure(size=int(font_size))
def setPath(self, p):
self.path = p
def set_table_name(self):
self.table_name = self.col_var.get().upper() + "_" + self.stat_var.get().upper() + "S" #
def getPath(self):
return self.path
def set_reps_path(self, p):
self.reps_path = p
def get_reps_path(self):
return self.reps_path
def set_reps(self, f):
r = f.readline()
self.reps = int(r)
def setDataframe(self, dataframe):
self.df = dataframe
def getDataframe(self):
return self.df
def main():
global v
# Create window object
root = Tk()
root.title("Looper")
root.geometry('800x500') # width x height
root.minsize("400", "400")
app = Looper()
root.mainloop()
if __name__ == '__main__':
main()