Пример #1
0
    def onSaveAs(self, e):
        # What happens when you hit Save as
        try:
            # every second | is an new option
            wildcard = "Xls files (*.xls)|*.xls|XLSX files(*.xlsx)|*.xlsx"
            dlg = wx.FileDialog(self, "Save file", self.directory_name,
                                self.file_name, wildcard,
                                wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

            if dlg.ShowModal() == wx.ID_OK:
                self.file_name = dlg.GetFilename()
                self.dirname = dlg.GetDirectory()
                self.type = dlg.GetFilterIndex()  # 0 is xls, 1 xlsx
                self.SetTitle("Hypotest: " + self.file_name)
                if self.type == 0:
                    writer = pd.ExcelWriter(dlg.GetFilename())
                elif self.type == 1:
                    writer = pd.ExcelWriter(dlg.GetFilename(),
                                            engine='xlsxwriter')

                for i in self.data:  # could that be better ?
                    self.data[i].to_excel(writer, sheet_name=i, index=False)

                writer.save()

            dlg.Destroy()

        except AttributeError:
            give_MessageDialog(self, "Open a file first", "Error",
                               wx.ICON_ERROR)
        except Exception as exception:
            give_MessageDialog(self, str(exception), "Error", wx.ICON_ERROR)
Пример #2
0
 def onSelection1(self, e):
     if self.hold1:
         self.combobox0.Append(self.hold1)
     self.hold1 = self.combobox1.GetStringSelection()
     try:
         self.combobox0.Delete(self.combobox0.GetItems().index(self.hold1))
     except Exception as e:
         msg = "An error occurred"
         give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
Пример #3
0
    def onOpen(self, e):
        # every second | creates a new type of file
        # on the left is what goes in UI
        # on the right is what files are shown
        wildcard = "Xls files (*.xls)|*.xls|Xlsx files (*.xlsx)|*.xlsx"
        dlg = wx.FileDialog(self, "Choose a file", self.directory_name, "",
                            wildcard, wx.FD_OPEN)  # for files in wildcard

        if dlg.ShowModal() == wx.ID_OK:
            try:
                self.file_name = dlg.GetFilename()
                self.directory_name = dlg.GetDirectory()
                self.type = dlg.GetFilterIndex()
                path = os.path.join(self.directory_name, self.file_name)
                self.data = pd.read_excel(io=path,
                                          sheet_name=None,
                                          skip_rows=None)

            except FileNotFoundError:
                give_MessageDialog(self, "No such file or directory", "Error",
                                   wx.ICON_ERROR)
                dlg.Destroy()
                return None
            except Exception as exception:
                give_MessageDialog(self, str(exception), "Error",
                                   wx.ICON_ERROR)
                dlg.Destroy()
                return None
            dlg.Destroy()
        else:
            dlg.Destroy()
            return None

        self.SetTitle("Hypotest: " + self.file_name)
        self.notebook = None
        self.pages = []
        for child in self.panel.GetChildren():
            child.Destroy()

        self.notebook = My_Notebook(self.panel)
        for i in self.data:
            self.pages.append(Sheet(self.notebook, i))

        for i in self.pages:
            self.notebook.AddPage(i, i.return_name())

        panel_sizer = wx.BoxSizer()
        panel_sizer.Add(self.notebook, 1, wx.ALL | wx.EXPAND)
        self.panel.SetSizer(panel_sizer)

        for i in self.pages:
            i.construct_grid(self.data[i.return_name()])

        self.panel.Layout()
Пример #4
0
 def onSave(self, e):
     # What happens when you hit Save
     # you need to change the numbers to strings or make a dictionary
     try:
         if self.type == 0:  # xls
             writer = pd.ExcelWriter(self.file_name)
         elif self.type == 1:  # xlsx
             writer = pd.ExcelWriter(self.file_name, engine='xlsxwriter')
         for i in self.data:
             self.data[i].to_excel(writer, sheet_name=i, index=False)
         writer.save()
     except AttributeError:
         give_MessageDialog(self, "Open a file first", "Error",
                            wx.ICON_ERROR)
     except Exception as exception:
         give_MessageDialog(self, str(exception), "Error", wx.ICON_ERROR)
Пример #5
0
    def onPrint(self, e):
        # Needs more testing
        try:
            if self.file_name != '':
                grid_print = prout.PrintGrid(
                    self, self.pages[self.notebook.page].returnGrid())
                grid_print.setAttributes()

                table = grid_print.GetTable()
                table.SetLandscape()
                grid_print.Preview()

            else:
                give_MessageDialog(self, "Open a file first", "Error",
                                   wx.ICON_ERROR)

        except Exception as exception:
            give_MessageDialog(self, str(exception), "Error", wx.ICON_ERROR)
Пример #6
0
 def on2ANOVA(self, e):
     # create frame for two ANOVA
     try:
         var = self.notebook.GetPageText(self.notebook.page)
         two_ANOVA_frame = TwoANOVA(self, self.data[var], var,
                                    self.notebook, self.pages, self.data)
     except AttributeError as e:
         give_MessageDialog(self, "Open a file first \n" + str(e), "Error",
                            wx.ICON_ERROR)
     except KeyError:
         give_MessageDialog(self, "We can not read this sheet", "Error",
                            wx.ICON_ERROR)
     except Exception as exception:
         give_MessageDialog(self, str(exception), "Error", wx.ICON_ERROR)
Пример #7
0
 def ontTestPaired(self, e):
     # create frame for one tTest paired
     try:
         var = self.notebook.GetPageText(self.notebook.page)
         paired_frame = PairedtTest(self, self.data[var], var,
                                    self.notebook, self.pages, self.data)
     except AttributeError:
         give_MessageDialog(self, "Open a file first", "Error",
                            wx.ICON_ERROR)
     except KeyError:
         give_MessageDialog(self, "We can not read this sheet", "Error",
                            wx.ICON_ERROR)
     except Exception as exception:
         give_MessageDialog(self, str(exception), "Error", wx.ICON_ERROR)
Пример #8
0
    def onOk(self, e):
        dataframe0 = self.dataframe
        if dataframe0.shape[1] < 3:
            msg = "You need more than two columns"
            give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
            return
        try:
            bg, rows, columns, interaction, wg, total = ptl_anova2(dataframe0)
        except Exception as exception:
            give_MessageDialog(self, str(exception), "Error", wx.ICON_ERROR)

        out = False
        if (columns[4] <= 0.05):
            j = 0
            alist = []
            for i in dataframe0.columns[1:]:
                alist.append(dataframe0[i].dropna())

            t = tuple(alist)
            out = self.run_Tukey(t, dataframe0.columns[1:], 0.05)

        # proccess to save the data
        name = "Two way ANOVA results"
        ok = False
        number = 0
        ok, number = self.find_sheet(name)
        local_dataframe = pd.DataFrame(columns=("A", "B", "C"))
        if not ok:
            new_sheet = Sheet(self.notebook, name)
            self.pages.append(new_sheet)
            self.notebook.AddPage(new_sheet, name)
            new_sheet.create_new_sheet()
            number = len(self.pages) - 1
            local_dataframe.loc[0] = ("Timestamp", "Test \n Sheet and Column",
                                      "Statistics")
            self.data[name] = local_dataframe

        # front end
        self.pages[number].add_results_2ANOVA(self.GetTitle(), bg, rows,
                                              columns, interaction, wg, total,
                                              out)
        # back end
        length = len(self.data[name])
        self.data[name].loc[length] = self.pages[number].last_value()

        msg = "Your data has been saved on the sheet with name "
        give_MessageDialog(self, msg + name, "Results saved",
                           wx.ICON_INFORMATION)
Пример #9
0
    def onOk(self, e):
        dataframe0 = self.dataframe
        if dataframe0.shape[1] < 3:
            msg = "You need more than two columns"
            give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
            return
        try:
            bg, wg, error, subjects, total, F, p = ptl_anovaR(dataframe0)
        except Exception as e:
            give_MessageDialog(self, str(e), "Error", wx.ICON_ERROR)
            return

        a_list = []
        for i in dataframe0:
            dataframe_na = dataframe0[[i]].dropna()
            a_list.append(dataframe_na.to_numpy().flatten())
            t = tuple(a_list)

        out = self.run_Tukey(t, self.dataframe.columns, 0.05)
        name = "Repeated ANOVA results"
        ok = False
        number = 0
        ok, number = self.find_sheet(name)
        local_dataframe = pd.DataFrame(columns=("A", "B", "C"))

        if not ok:
            # creates the sheet to save data
            new_sheet = Sheet(self.notebook, name)
            self.pages.append(new_sheet)
            self.notebook.AddPage(new_sheet, name)
            new_sheet.create_new_sheet()
            number = len(self.pages) - 1
            local_dataframe.loc[0] = ("Timestamp", "Test \n Sheet and Coulumn",
                                      "Statistics")
            self.data[name] = local_dataframe

        self.pages[number].add_results_rANOVA(self.GetTitle(), bg, wg, error,
                                              subjects, total, F, p, out)

        length = len(self.data[name])
        self.data[name].loc[length] = self.pages[number].last_value()

        msg = "Your data has been saved on the sheet with name"
        give_MessageDialog(self, msg + name, "Results saved",
                           wx.ICON_INFORMATION)
Пример #10
0
    def onOk(self, e):
        if self.combobox0.GetCurrentSelection() == -1:
            give_MessageDialog(self, "You must select a column", "Error",
                               wx.ICON_ERROR)
            return None

        dataframe0 = self.dataframe[[self.combobox0.GetStringSelection()]]

        column_name = str(list(dataframe0))
        column_name = column_name[2:len(column_name) - 2]
        description = dataframe0.describe()
        count = description.iat[0, 0]
        mean = description.iat[1, 0]
        std = description.iat[2, 0]
        dataframe0_dropna = dataframe0.dropna()

        try:
            z = float(self.text.GetLineText(0))
            error = False
        except ValueError:
            give_MessageDialog(self, "A string has been detected", "Error",
                               wx.ICON_ERROR)
            return None
        except Exception as e:
            give_MessageDialog(self, str(e), "Error", wx.ICON_ERROR)
            return None

        if z < 0:
            give_MessageDialog(self, "A negative number has been detected",
                               "Error", wx.ICON_ERROR)
        elif (dataframe0_dropna.shape[0] * dataframe0_dropna.shape[1]) < 3:
            give_MessageDIalog(self, "The set of data is smaller than 3",
                               "Error", wx.ICON_ERROR)
        else:
            try:
                shap = stats.shapiro(dataframe0_dropna)
                x, y = stats.ttest_1samp(dataframe0_dropna, z)

                string0 = ''
                string0 = ("The result of tTest one sample is t = " + str(x) +
                           ", p = " + str(y))
                give_MessageDialog(self, string0, "tTest", wx.ICON_INFORMATION)

                name = "One sample tTest results"
                ok = False
                num = 0
                ok, num = self.find_sheet(name)

                if not ok:  # create new sheet for the resutls
                    temp_sheet = Sheet(self.notebook, name)
                    self.pages.append(temp_sheet)
                    self.notebook.AddPage(temp_sheet, name)
                    temp_sheet.create_new_sheet()
                    num = len(self.pages) - 1

                    temp_data = pd.DataFrame(columns=("A", "B", "C"))
                    temp_data.loc[0] = ("Timestamp",
                                        "Test \n Sheet and Column",
                                        "Statistics")
                    self.data[name] = temp_data

                title = self.GetTitle()
                string = self.combobox0.GetStringSelection()
                self.pages[num].add_results_tTest1_sample(
                    title, string, x, y, shap, z, column_name, count, mean,
                    std)
                val = self.pages[num].last_value()
                self.data[name].loc[len(self.data[name])] = val
                msg = "Your data has been saved on sheet with name " + name
                give_MessageDialog(self, msg, "Results saved",
                                   wx.ICON_INFORMATION)
            except ValueError:
                msg = "There is an error in your data. \n Propably a string"
                give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
            except Exception as e:
                give_MessageDialog(self, str(e), "Error", wx.ICON_ERROR)
Пример #11
0
    def onOk(self, e):
        try:
            z = float(self.text.GetValue())
            error = False
        except ValueError:
            error = True

        if len(self.list) < 2:
            msg = "You need to give more than one column"
            give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
        elif error:
            msg = "A string has been detected at the text book"
            give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
        elif z <= 0:
            msg = "The number must be greater than 0"
            give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
        elif z >= 1:
            msg = "The number must be smaller than 1"
            give_MessageDialgo(self, msg, "Error", wx.ICON_ERROR)
        else:
            try:
                count = []
                mean = []
                std = []
                self.shapiro_list = []
                replace_eval = []

                for i in self.list:
                    dataframe_na = self.dataframe[[i]].dropna()
                    desc = dataframe_na.describe()
                    count.append(desc.iat[0, 0])
                    mean.append(desc.iat[1, 0])
                    std.append(desc.iat[2, 0])
                    if (dataframe_na.shape[0] * dataframe_na.shape[1]) < 3:
                        msg = "The column " + i + " is not size of 3 "
                        give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
                        return None

                    self.shapiro_list.append(stats.shapiro(dataframe_na))
                    replace_eval.append(dataframe_na.to_numpy().flatten())

                t = tuple(replace_eval)
                s = stats.levene(*t)
                F, p = stats.f_oneway(*t)
                out = self.run_Tukey(t, self.list, z)

                # now you start the process to show the results
                name = "ANOVA one results"
                ok = False
                num = 0
                temp_dataframe = pd.DataFrame(columns=("A", "B", "C"))
                ok, num = self.find_sheet(name)
                if not ok:
                    # this is for creating the sheet for back end
                    temp_sheet = Sheet(self.notebook, name)
                    self.pages.append(temp_sheet)
                    self.notebook.AddPage(temp_sheet, name)
                    temp_sheet.create_new_sheet()
                    num = len(self.pages) - 1
                    temp_dataframe.loc[0] = ("Timestamp",
                                             "Test \n Sheet and Column",
                                             "Statistics")
                    self.data[name] = temp_dataframe

                self.pages[num].add_results_ANOVA(self.GetTitle(), self.list,
                                                  self.shapiro_list, s, F, p,
                                                  self.list, count, mean, std,
                                                  out, z)

                length = len(self.data[name])
                # for back end
                self.data[name].loc[length] = self.pages[num].last_value()
                msg = "Your data has been saved on the sheet with name" + name
                give_MessageDialog(self, msg, "Results saved",
                                   wx.ICON_INFORMATION)

            except Exception as e:
                give_MessageDialog(self, str(e), "Error", wx.ICON_ERROR)
Пример #12
0
    def onOk(self, e):
        try:
            dataframe0 = self.dataframe[[self.hold0]]
            dataframe1 = self.dataframe[[self.hold1]]

            column_name = (str(list(dataframe0)), str(list(dataframe1)))

            # clear string from "" and () from start and end of the string
            column_name = (column_name[0][2:len(column_name[0]) - 2],
                           column_name[1][2:len(column_name[1]) - 2])
            description = (dataframe0.describe(), dataframe1.describe())

            count = (description[0].iat[0, 0], description[1].iat[0, 0])
            mean = (description[0].iat[1, 0], description[1].iat[1, 0])
            std = (description[0].iat[2, 0], description[1].iat[2, 0])

            dataframe0 = dataframe0.dropna()
            dataframe1 = dataframe1.dropna()

            size0 = dataframe0.shape[0] * dataframe0.shape[1]
            size1 = dataframe1.shape[0] * datafrane1.shape[1]

            if size0 < 3:
                msg = "The first set of data is smaller than 3"
                give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
            elif size1 < 3:
                msg = "The second set of data is smaller that 3"
                give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
            else:
                try:
                    shapiro0 = stats.shapiro(dataframe0)
                    shapiro1 = stats.shapiro(dataframe1)

                    levene = stats.levene(dataframe0.to_numpy().flatten(),
                                          dataframe1.to_numpy().flatten())

                    if size0 == size1:
                        x, y = stats.ttest_ind(dataframe0, dataframe1)
                    else:
                        x, y = stats.ttest_ind(dataframe0,
                                               dataframe1,
                                               equal_var=False)

                    string0 = ""
                    string0 = ("The results of tTest independent is t = " +
                               str(x) + ", p = " + str(y))
                    give_MessageDialog(self, string0, "tTest",
                                       wx.ICON_INFORMATION)

                    # Check if the sheet to save data exist
                    man = stats.mannwhitneyu(dataframe0, dataframe1)
                    name = "tTest independent resutls"
                    ok, num = self.find_sheet(name)
                    if not ok:
                        temp_sheet = Sheet(self.notebook, name)
                        self.pages.append(temp_sheet)
                        self.notebook.AddPage(temp_sheet, name)
                        temp_sheet.create_new_sheet()
                        num = len(self.pages) - 1
                        # This is for back end
                        temp_dataframe = pd.DataFrame(columns=("A", "B", "C"))
                        temp_dataframe.loc[0] = ("Timestamp",
                                                 "Test \n Sheet and Column",
                                                 "Statistics")
                        self.data[name] = temp_dataframe

                    t = self.GetTitle()
                    cb0 = self.combobox0.GetStringSelection()
                    cb1 = self.combobox1.GetStringSelection()
                    self.pages[num].add_results_tTest_independent(
                        t, cb0, cb1, x, y, shapiro0, shapiro1, levene, man,
                        column_name, count, mean, std)

                    # This for the back end
                    pos = self.data[name]
                    val = self.pages[num].last_value()
                    self.data[name].loc[len(pos)] = val
                    msg = "Your data has been saved on sheet " + name
                    give_MessageDialog(self, msg, "Results saved",
                                       wx.ICON_INFORMATION)
                except ValueError as e:
                    msg = ("Ther is an error in your data.\n" +
                           "Probably a string")
                    give_MessageDialog(self, str(e), "Error", wx.ICON_ERROR)
                except Exception as exception:
                    msg = "Both must have a selected column"
                    give_MessageDialog(self, str(exception), "Error",
                                       wx.ICON_ERROR)

        except KeyError:
            give_MessageDialog(self, "Both boxes must have a selected column",
                               "Error", wx.ICON_ERROR)
Пример #13
0
    def onOk(self, e):
        try:
            dataframe0 = self.dataframe[[self.hold0]]
            dataframe1 = self.dataframe[[self.hold1]]

            frames = [dataframe0, dataframe1]
            result = pd.concat(frames, axis=1)  # outter join
            results_dropna = result.dropna()  # you take data in pairs

            dataframe0 = results_dropna[[self.hold0]]
            dataframe1 = results_dropna[[self.hold1]]

            column_name = (str(list(dataframe0)),
                           str(list(dataframe1)))

            # remove "" and () from the string
            column_name = (column_name[0][2: len(column_name[0]) - 2],
                           column_name[1][2: len(column_name[1]) - 2])

            description = (dataframe0.describe(), dataframe1.describe())
            count = (description[0].iat[0, 0], description[1].iat[0, 0])
            mean = (description[0].iat[1, 0], description[1].iat[1, 0])
            std = (description[0].iat[2, 0], description[1].iat[2, 0])

            size0 = dataframe0.shape[0] * dataframe0.shape[1]
            size1 = dataframe1.shape[0] * dataframe1.shape[1]

            if size0 <= 3:
                msg = "The first set of data is not size of 3"
                give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
            elif size1 <= 3:
                msg = "The second set of data is not size of 3"
                give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
            elif size0 != size1:
                msg = ("The data is not of the same length. \n"
                       + "The empty variable will be remove automaticly")
                give_MessageDialog(self, msg, "tTest", wx.ICON_ERROR)
            else:
                try:
                    shapiro0 = stats.shapiro(dataframe0)
                    shapiro1 = stats.shapiro(dataframe1)
                    string = ""

                    levene = stats.levene(dataframe0.to_numpy().flatten(),
                                          dataframe1.to_numpy().flatten())

                    x, y = stats.ttest_rel(dataframe0, dataframe1)
                    string = ("The results of tTest paired is t = " + str(x)
                              + ", p = " + str(y))
                    give_MessageDialog(self, string,
                                       "tTest", wx.ICON_INFORMATION)

                    wil = stats.wilcoxon(dataframe0.to_numpy().flatten(),
                                         dataframe1.to_numpy().flatten())

                    name = "tTest paired results"
                    ok, num = self.find_sheet(name)

                    if not ok:
                        temp_sheet = Sheet(self.notebook, name)
                        self.pages.append(temp_sheet)
                        self.notebook.AddPage(temp_sheet, name)
                        temp_sheet.create_new_sheet()
                        num = len(self.pages) - 1
                        # This is for backend
                        temp_dataframe = pd.DataFrame(columns=("A", "B", "C"))
                        temp_dataframe.loc[0] = ("Timestamp",
                                                 "Test \n Sheet and Column",
                                                 "Statistics")
                        self.data[name] = temp_dataframe

                    cb0 = self.combobox0.GetStringSelection()
                    cb1 = self.combobox1.GetStringSelection()
                    self.pages[num].add_results_paired_tTest(self.GetTitle(),
                                                             cb0, cb1, x, y,
                                                             shapiro0,
                                                             shapiro1,
                                                             levene,
                                                             wil,
                                                             column_name,
                                                             count, mean,
                                                             std)

                    # This for the backend
                    val = self.pages[num].last_value()
                    self.data[name].loc[len(self.data[name])] = val
                    msg = "Your data has been saved on the sheet with name "
                    give_MessageDialog(self, msg + name, "Results saved",
                                       wx.ICON_INFORMATION)
                except ValueError:
                    msg = "There is an error in data. \n Probably a string"
                    give_MessageDialog(self, msg, "Error", wx.ICON_ERROR)
                except Exception as e:
                    give_MessageDialog(self, str(e), "Error", wx.ICON_ERROR)

        except KeyError:
            give_MessageDialog(self, "Both boxes must have a selected column",
                               "Error", wx.ICON_ERROR)