Skip to content

Commit

Permalink
WIP #118 & #128: Fixed error handling of name textbox, need to implem…
Browse files Browse the repository at this point in the history
…ent for regression
  • Loading branch information
MatthewSpofford committed Jan 15, 2021
1 parent bae2cae commit f0b9161
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
50 changes: 29 additions & 21 deletions src/multi_stat_analysis/StatsTestsUI.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import warnings

from multi_stat_analysis import __main__

warnings.simplefilter("error", RuntimeWarning)

import wx
Expand All @@ -14,6 +12,8 @@
from GraphDialogs import SymbolDialog
from GraphDialogs import LegendDialog

import multi_stat_analysis.__main__ as main


class FTestException(Exception):
def __init__(self, msg):
Expand All @@ -23,12 +23,13 @@ def __init__(self, msg):
# class for the dialog that performs the F-test
class FtestDialog(wx.Dialog):
# this is all just GUI stuff
def __init__(self, parent, data, tree_menu, root):
def __init__(self, parent, data, tree_menu, root, wb):
wx.Dialog.__init__(self, parent, wx.ID_ANY, "F-test", size=(840, 450))

self.parent = parent
self.tree_menu = tree_menu
self.root = root
self.selected_wb = wb

self.panel = wx.Panel(self, wx.ID_ANY)
self.data = data
Expand Down Expand Up @@ -153,12 +154,13 @@ def OnOK(self, event):
plot.get_graph().draw_scatter()

self.name = self.name_box.GetValue()
selected_wb = __main__.get_selected_wb()

if self.name in [result.name for result in selected_wb.results]:
if self.name in [result.name for result in self.selected_wb.results]:
raise TTestException("Result with this name already exists under this workbook.")

self.selected_wb.results.append(self)
self.get_tree_menu().AppendItem(self.get_root(), self.name, data=plot)
self.get_tree_menu().Expand(self.get_root())
self.Close()
if tails == 'left (σ1 ≥ σ2)':
for dset in d:
Expand All @@ -185,12 +187,13 @@ def OnOK(self, event):
plot.get_graph().draw_scatter()

self.name = self.name_box.GetValue()
selected_wb = __main__.selected_wb

if self.name in [result.name for result in selected_wb.results]:
if self.name in [result.name for result in self.selected_wb.results]:
raise TTestException("Result with this name already exists under this workbook.")

self.selected_wb.results.append(self)
self.get_tree_menu().AppendItem(self.get_root(), self.name, data=plot)
self.get_tree_menu().Expand(self.get_root())
self.Close()
if tails == 'right (σ1 ≤ σ2)':
for dset in d:
Expand All @@ -215,12 +218,13 @@ def OnOK(self, event):
plot.get_graph().draw_scatter()

self.name = self.name_box.GetValue()
selected_wb = __main__.selected_wb

if self.name in [result.name for result in selected_wb.results]:
if self.name in [result.name for result in self.selected_wb.results]:
raise TTestException("Result with this name already exists under this workbook.")

self.selected_wb.results.append(self)
self.get_tree_menu().AppendItem(self.get_root(), self.name, data=plot)
self.get_tree_menu().Expand(self.get_root())
self.Close()
else:
raise FTestException('F-test: Groups must be the same size')
Expand Down Expand Up @@ -376,11 +380,11 @@ def F_Tail_helper(self, alpha, data, num_data, f1, f2):
# check if the test should be accepted or rejected
if f1 < f_val < f2:
if num_data == 2:
__main__.errorMsg("F-Test Warning", accepted)
main.errorMsg("F-Test Warning", accepted)
self.get_res_list().append(['accepted', var1, var2, mean1, mean2, sd1, sd2, p_val, p_val, np.round_(p_val * 100, 3), f_val, p_r, f1, f2])
else:
if num_data == 2:
__main__.errorMsg("F-Test Warning", rejected)
main.errorMsg("F-Test Warning", rejected)
self.get_res_list().append(['rejected', var1, var2, mean1, mean2, sd1, sd2, p_val, p_val,np.round_(p_val * 100, 3), f_val, p_r, f1, f2])

def F_TwoTail(self, alpha, data, num_data):
Expand Down Expand Up @@ -439,12 +443,13 @@ def __init__(self, msg):
# class for the dialog that performs the Welch's t-test
class TtestDialog(wx.Dialog):
# again more GUI stuff for the dialog
def __init__(self, parent, data, tree_menu, root):
def __init__(self, parent, data, tree_menu, root, wb):
wx.Dialog.__init__(self, parent, wx.ID_ANY, "T-test", size=(840, 450))

self.parent = parent
self.tree_menu = tree_menu
self.root = root
self.selected_wb = wb

self.panel = wx.Panel(self, wx.ID_ANY)
self.data = data
Expand All @@ -453,7 +458,7 @@ def __init__(self, parent, data, tree_menu, root):
self.name_txt = wx.StaticText(self.panel, wx.ID_ANY, 'Results Name: ', pos=(180, 45))
self.name_box = wx.TextCtrl(self.panel, wx.ID_ANY,
value=self.name,
pos=(190, 45), size=(100, 20))
pos=(275, 42), size=(300, 20))

self.group_selection = GroupSelection(self.panel, self.data, 110)

Expand Down Expand Up @@ -552,12 +557,13 @@ def OnOK(self, event):
plot.get_graph().draw_scatter()

self.name = self.name_box.GetValue()
selected_wb = __main__.selected_wb

if self.name in [result.name for result in selected_wb.results]:
if self.name in [result.name for result in self.selected_wb.results]:
raise TTestException("Result with this name already exists under this workbook.")

self.selected_wb.results.append(self)
self.get_tree_menu().AppendItem(self.get_root(), self.name, data=plot)
self.get_tree_menu().Expand(self.get_root())
self.Close()

# if tails == 'two (σ1 = σ2)':
Expand Down Expand Up @@ -757,7 +763,7 @@ def WelchsTTest(self, a, data, num_data):
Confidence: {}%""".format(N, var1, var2, avg1, avg2, std1, std2, t_score, Lpval, Rpval, pval, confidence)

if num_data == 2:
__main__.errorMsg("T-test Warning", results_text)
main.errorMsg("T-test Warning", results_text)

self.get_res_list().append([var1, var2, avg1, avg2, std1, std2, t_score, pval, Lpval, Rpval, confidence])

Expand Down Expand Up @@ -803,12 +809,13 @@ def __init__(self, msg):
# functions same as in the above 2 classes.
class ANOVAtestDialog(wx.Dialog):

def __init__(self, parent, data, tree_menu, root):
def __init__(self, parent, data, tree_menu, root, wb):
wx.Dialog.__init__(self, parent, wx.ID_ANY, "ANOVA", size=(840, 450))

self.parent = parent
self.tree_menu = tree_menu
self.root = root
self.selected_wb = wb

self.panel = wx.Panel(self, wx.ID_ANY)
self.data = data
Expand All @@ -817,7 +824,7 @@ def __init__(self, parent, data, tree_menu, root):
self.name_txt = wx.StaticText(self.panel, wx.ID_ANY, 'Results Name: ', pos=(180, 45))
self.name_box = wx.TextCtrl(self.panel, wx.ID_ANY,
value=self.name,
pos=(190, 45), size=(100, 20))
pos=(275, 42), size=(300, 20))

# self.hyp_box = wx.StaticBox(self.panel, wx.ID_ANY, 'Hypotheses', pos=(20, 20), size=(600, 80))
# self.hyp0 = wx.StaticText(self.hyp_box, wx.ID_ANY, "H0: σ1^2 = σ2^2", pos=(15, 25))
Expand Down Expand Up @@ -924,12 +931,13 @@ def OnOK(self, event):
plot.get_graph().set_alpha(1 - alpha)

self.name = self.name_box.GetValue()
selected_wb = __main__.selected_wb

if self.name in [result.name for result in selected_wb.results]:
if self.name in [result.name for result in self.selected_wb.results]:
raise ANOVAException("Result with this name already exists under this workbook.")

self.selected_wb.results.append(self)
self.get_tree_menu().AppendItem(self.get_root(), self.name, data=plot)
self.get_tree_menu().Expand(self.get_root())
self.Close()

else:
Expand Down Expand Up @@ -1052,7 +1060,7 @@ def F_anova(self, alpha, data, num_data):
self.get_res_list().append([MSR, MSR_min, (1-alpha)*100, dfn, dfd])

if num_data == 2:
__main__.errorMsg("ANOVA Test Warning", res_txt)
main.errorMsg("ANOVA Test Warning", res_txt)

self.get_flist().append(MSR)

Expand Down
9 changes: 8 additions & 1 deletion src/multi_stat_analysis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, wb_id, surfaces_id, results_id):


def get_selected_wb():
global selected_wb
return selected_wb


Expand All @@ -65,6 +66,7 @@ def warnMsg(title, msg):

# function for show the curve fit dialog and get regression graphs
def OnRegression(event):
global selected_wb
dataset = selected_wb.dataset

warnings.simplefilter("error", OptimizeWarning)
Expand Down Expand Up @@ -177,6 +179,7 @@ def OnRegression(event):

# function to get the x-regression values
def OnData(event):
global selected_wb
dataset = selected_wb.dataset

datadialog = XRValuesDialog(frame, dataset.get_x_regress())
Expand All @@ -198,11 +201,12 @@ class DiscrimTests:


def OnDiscrimTests(test_choice):
global selected_wb
selected_test_func, test_str = test_choice
dataset = selected_wb.dataset

try:
dlg = selected_test_func(frame, dataset, tree_menu, _selected_results_ID)
dlg = selected_test_func(frame, dataset, tree_menu, _selected_results_ID, selected_wb)
except (ZeroDivisionError, RuntimeError, Exception, Warning, TypeError, RuntimeWarning, OptimizeWarning) as e:
errorMsg(test_str, str(e))
if __debug__:
Expand Down Expand Up @@ -255,6 +259,7 @@ def display_graph_frame(graph_panel):
def OnScalePlot(plot_choice: ScalePlots):
plot_str, title, scale_func, draw_func, menu_text, y_label = plot_choice.value

global selected_wb
if selected_wb is None or selected_wb.dataset.is_empty():
errorMsg(plot_str, "No surfaces given.")
return
Expand Down Expand Up @@ -531,6 +536,7 @@ def OnAbout(event):

# function to open the data files
def OnOpen(event):
global selected_wb
frame.EnableCloseButton(False)

try:
Expand Down Expand Up @@ -623,6 +629,7 @@ def OnNewWB(event):


def OnSave(event):
global selected_wb
frame.EnableCloseButton(False)
output = False
try:
Expand Down

0 comments on commit f0b9161

Please sign in to comment.