def __init__(self, output, sheet_count=1, for_tableu=False): self.out = output self.__sheet_count = sheet_count self.row_types = [] for i in range(0, 11): self.row_types.append(0) self.large_row = False self.data = [] self.baseTextObj = format_lib.BaseText(self, ['']) self.totalObj = format_lib.Total(self, ['']) self.tableNameObj = format_lib.TableName(self, ['']) self.btxt = 0 self.footer = [] self.__for_tableu = for_tableu if self.out.many_sheets: self.__SheetName = "T{0}".format(sheet_count) self.__out_ws = Sheet(output, self.__SheetName) else: self.__SheetName = "Tables" self.__out_ws = self.out.get_current_ws() if not for_tableu: self.__out_ws.get_sheet().set_column(0, 0, 25) self.__row_start = self.__out_ws.get_current_row()
def test_exclude_when_unknown_for_rank_marks_unknown_cards_as_excluded(self): sheet = Sheet('test') sheet.own_cards([(2, 'L'), (6, 'L'), (9, 'L')]) sheet.exclude_when_unknown_for_rank(6) self.assertEqual(sheet_table(excluded=[(6, 'H'), (6, '$')], owned=[(2, 'L'), (6, 'L'), (9, 'L')]), sheet.table)
def process_sheet_name_row(self, row): row[0] = row[0].replace("$$sheet_name$$", "") if not self.__for_tableu: self.__out_ws = Sheet(self.out, row[0]) self.__row_start = 0 self.out.set_current_ws(self.__out_ws) else: self.out.set_current_ws(row[0])
def message_score_sheet_status(self, client, group_id): sheet = Sheet() player_list = sheet.get_player_list() message = "Score Sheet Tally: \n" + ''.join( str(e.name + " " + e.timesPaid + "\n") for e in player_list) client.send(Message(text=message), thread_id=group_id, thread_type=ThreadType.GROUP)
def test_exclude_when_unknown_for_suit_marks_unknown_cards_as_excluded(self): sheet = Sheet('test') sheet.own_cards([(2, 'L'), (6, 'L'), (9, 'L')]) sheet.exclude_when_unknown_for_suit('L') self.assertEqual(sheet_table(excluded=[(1, 'L'), (3, 'L'), (4, 'L'), (5, 'L'), (7, 'L'), (8, 'L')], owned=[(2, 'L'), (6, 'L'), (9, 'L')]), sheet.table)
def compile_sheet(self, sheet_json): sheet = Sheet() for name in sheet_json: definition = sheet_json[name] rule = self.compile_rule(name, definition) if rule: sheet.add(rule) self.compile_regexp(rule, definition) if not sheet.root: raise Exception("No rule scoped 'root'") self.compile_children(sheet) return sheet
def sheet_table(**kwargs): sheet = Sheet('test') sheet.exclude_cards(kwargs.get('excluded', [])) sheet.own_cards(kwargs.get('owned', [])) for total_type, value in kwargs.get('totals', {}).iteritems(): if isinstance(total_type, basestring): sheet.set_suit_total(total_type, value) else: sheet.set_rank_total(total_type, value) return sheet.table
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)
def __init__(self, formula_text_dialog): self.sheet = Sheet() self.view = SheetView(self.sheet) self.input_mode = False self.config = {} #Load from file self.key_bindings = None self.key_bindings = self.bindings() self.formula_text_dialog = formula_text_dialog
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)
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()
def get_lowest_paid(self, client, group_id): sheet = Sheet() player_list = sheet.get_player_list() # select who is paying team sheet min_times_paid = [] lowest_times_paid = 100 for player in player_list: if int(player.timesPaid) < lowest_times_paid: lowest_times_paid = int(player.timesPaid) for player in player_list: if int(player.timesPaid) == lowest_times_paid: min_times_paid.append(player.name) secure_random = rand.SystemRandom() message = "Player to pay next is: " + secure_random.choice( min_times_paid) client.send(Message(text=message), thread_id=group_id, thread_type=ThreadType.GROUP)
def __init__(self, output_excel, title_row_num, many_sheets): super(self.__class__, self).__init__(output_excel, { 'constant_memory': True, 'strings_to_numbers': True }) if os.path.isfile("TableOfContent.txt"): os.remove("TableOfContent.txt") self.sheet_count = 1 self.one_sheet_ws = None self.TableOfContent = open("TableOfContent.txt", "ab") self.TableOfContent.write("<?xml version='1.0' encoding='UTF-8'?>\n") self.TableOfContent.write("<tables>\n") self.add_styles() self.many_sheets = many_sheets self.current_row = 1 self.table_number = 0 if not many_sheets: # self.one_sheet_ws = self.add_worksheet("Tables") self.one_sheet_ws = Sheet(self, "Tables") self.tables_sheet = self.one_sheet_ws self.current_ws = self.one_sheet_ws
def parse_worksheet(file_name, sheet_index, start_col, end_col, start_row_ids, col_numbers_with_filling_gaps=None): file = xlrd.open_workbook(file_name) file_sheet = file.sheet_by_index(sheet_index) sheet = Sheet(sheet_index, file_sheet.name, ExcelParser.find_heading(file_sheet)) for i, start_row_id in enumerate(start_row_ids): for col_number in range(start_col, end_col): if i == len(start_row_ids) - 1: values = file_sheet.col_values(col_number, start_row_id) else: values = file_sheet.col_values( col_number, start_row_id, start_row_ids[i + 1] - start_row_id + 1) if not col_numbers_with_filling_gaps is None and col_number in col_numbers_with_filling_gaps: ExcelParser.fill_gaps_in_col(values) sheet.data.append(values) return sheet
def test_exclude_cards_with_only_one_card(self): sheet = Sheet('test') sheet.exclude_cards((8, '$')) self.assertEqual(sheet_table(excluded=[(8, '$')]), sheet.table)
from Sheet import Sheet sheet = Sheet(10, 10) #sheet.modifyValue(0, A, string) #sheet.modifyValue(0, 0, '') #B sheet.modifyValue(0, 0, '=D1') #A1 sheet.modifyValue(1, 0, '=D2') #A2 sheet.modifyValue(2, 0, '=D3') #A3 sheet.modifyValue(3, 0, '=D4') #A4 sheet.modifyValue(4, 0, '=sum(A1:A4)') #A1 sheet.modifyValue(0, 1, '=D1+C1') #B1 sheet.modifyValue(1, 1, '=D2+C2') #B2 sheet.modifyValue(2, 1, '=D3+C3') #B3 sheet.modifyValue(3, 1, '=D4+C4') #B4 sheet.modifyValue(4, 1, '=sum(B1:B4)') #B5 sheet.modifyValue(0, 2, '1') #C1 sheet.modifyValue(1, 2, '2') #C2 sheet.modifyValue(2, 2, '3') #C3 sheet.modifyValue(3, 2, '4') #C4 sheet.modifyValue(0, 3, '=E1+F1') #D1 sheet.modifyValue(1, 3, '=E2+F2') #D2 sheet.modifyValue(2, 3, '=E3+F3') #D3 sheet.modifyValue(3, 3, '=E4+F4') #D4 sheet.modifyValue(0, 4, '=G1-H1') #E1 sheet.modifyValue(1, 4, '=G2*H2') #E2
tk_root.protocol('WM_DELETE_WINDOW', exit_app) # root is your root window def exit_app(): # check if saving # if not: tk_root.destroy() if __name__ == "__main__": tk_root = tk.Tk() tk_canvas = tk.Canvas(tk_root) img = ImageTk.PhotoImage(file=h.DIR + '\\icons\\mindmap.png') tk_root.tk.call('wm', 'iconphoto', tk_root._w, img) graphicsInit() fileName = h.DIR + "\\Sheets\\tmp_thought.json" if len(sys.argv) >= 2: fileName = sys.argv[1] print("fileName:", fileName) sheet = Sheet(root=tk_root, canvas=tk_canvas, fileName=fileName) # have to do this after creating sheet, since resizeLayout calls sheet resize functions tk_root.bind("<Configure>", resizeLayout) resizeLayout() tk_root.mainloop()
def test_own_cards(self): sheet = Sheet('test') sheet.own_cards([(3, 'L'), (3, 'H'), (3, '$')]) self.assertEqual(sheet_table(owned=[(3, 'L'), (3, 'H'), (3, '$')]), sheet.table)
def __init__(self, website, sheet_id): self.website = website self.sheet = Sheet(sheet_id)
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)
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)
def test_voids_for_a_rank(self): sheet = Sheet('test') sheet.exclude_cards((5, 'H')) self.assertItemsEqual([(5, 'L'), (5, '$')], sheet.voids(rank=5))
from _sha3 import sha3_224 from Sheet import Sheet from Conversions import * import re original = Sheet(10, 10) original.modifyValue(0, 0, '0') #A original.modifyValue(1, 0, '0') # original.modifyValue(2, 0, '2') # original.modifyValue(3, 0, '8') # original.modifyValue(4, 0, '0') # original.modifyValue(5, 0, '7') # original.modifyValue(6, 0, '5') # original.modifyValue(7, 0, '0') # original.modifyValue(8, 0, '0') # original.modifyValue(9, 0, '=sum(A1:A9)') original.modifyValue(0, 1, '6') #B original.modifyValue(1, 1, '0') # original.modifyValue(2, 1, '0') # original.modifyValue(3, 1, '0') # original.modifyValue(4, 1, '0') # original.modifyValue(5, 1, '0') # original.modifyValue(6, 1, '0') # original.modifyValue(7, 1, '0') # original.modifyValue(8, 1, '4') # original.modifyValue(9, 1, '=sum(B1:B9)')
def test_exclude_cards(self): sheet = Sheet('test') sheet.exclude_cards([(1, 'L'), (5, 'H'), (9, '$')]) self.assertEqual(sheet_table(excluded=[(1, 'L'), (5, 'H'), (9, '$')]), sheet.table)
def test_set_rank_total(self): sheet = Sheet('test') sheet.own_cards([(5, 'L')]) sheet.set_rank_total(5, 2) self.assertEqual(sheet_table(owned=[(5, 'L')], totals={5: 2}), sheet.table)
def test_voids_for_a_suit(self): sheet = Sheet('test') sheet.exclude_cards(Range((2, 'L'), (8, '$')).cards()) self.assertItemsEqual([(1, 'H'), (9, 'H')], sheet.voids('H'))
class Table: __current_row = 0 __BaseText = "" __base_text_row = 0 __Total = "" __empty_row = True __max_cell = 0 __last_ban_row = False __row_start = 1 __first_break = True __TableName = "" banner = True workbook = "" out = "" __out_ws = "" row_types = [] large_row = "" current_row_type = "" footer = [] data = [] __for_tableu = False def __init__(self, output, sheet_count=1, for_tableu=False): self.out = output self.__sheet_count = sheet_count self.row_types = [] for i in range(0, 11): self.row_types.append(0) self.large_row = False self.data = [] self.baseTextObj = format_lib.BaseText(self, ['']) self.totalObj = format_lib.Total(self, ['']) self.tableNameObj = format_lib.TableName(self, ['']) self.btxt = 0 self.footer = [] self.__for_tableu = for_tableu if self.out.many_sheets: self.__SheetName = "T{0}".format(sheet_count) self.__out_ws = Sheet(output, self.__SheetName) else: self.__SheetName = "Tables" self.__out_ws = self.out.get_current_ws() if not for_tableu: self.__out_ws.get_sheet().set_column(0, 0, 25) self.__row_start = self.__out_ws.get_current_row() def write(self, *args): lst = list(args) if re.search('^[0-9.]+%$', str(lst[2].encode('utf8', 'replace'))): lst[2] = str(lst[2]).encode('utf8', 'replace').replace('%', '').decode('utf8') lst[2] = float(lst[2]) / 100 if not (len(lst) > 4 and lst[4] == "total row"): if len(lst) == 3: lst.append(self.out.percentage) else: lst[3] = self.out.percentage else: lst[3] = self.out.blued_style_pc elif re.search('^[0-9.]+ *$', str(lst[2].encode( 'utf8', 'replace'))) and self.current_row_type in (4, 5): lst[3] = self.out.number elif lst[2].encode('utf8', 'replace') in ["-", "- "]: lst[3] = self.out.center if len(lst) > 4: del lst[4:] t = tuple(lst) self.__out_ws.write(*t) @staticmethod def wrap_write_to_xml(string): string = string.replace('&', '&') string = string.replace('>', '>') string = string.replace('<', '<') return string def append_to_table_of_content(self): if not self.__for_tableu: self.out.TableOfContent\ .write('<table>\n' + '<table_id>' + self.wrap_write_to_xml(str(self.__sheet_count)) + '</table_id>\n' + '<sheet_name>' + self.wrap_write_to_xml(self.__out_ws.get_sheetname().encode('utf8')) + '</sheet_name>\n' + '<name>' + self.wrap_write_to_xml(self.__TableName.encode('utf8')) + '</name>\n' + '<b_text>' + self.wrap_write_to_xml(self.__BaseText.encode('utf8')) + '</b_text>\n' + '<total>' + self.wrap_write_to_xml(self.__Total.encode('utf8')) + '</total>\n' + '<row_start>' + self.wrap_write_to_xml(str(self.__row_start + 1)) + '</row_start>\n' + '</table>\n') def set__table_name(self, table_name): self.__TableName = table_name def set__base_text(self, base_text): temp = base_text.replace("Base: ", "") temp = temp.replace("Base - ", "") self.__BaseText = temp def get__base_text(self): return self.__BaseText def set__total(self, total): if self.__Total == "": self.__Total = total #if (self.out.many_sheets): self.freeze_pane() def get__total(self): return self.__Total def freeze_pane(self): self.__out_ws.get_sheet().freeze_panes( self.__out_ws.get_current_row() + 1, 2) def print_link_to_contents(self): link = "internal:#'Contents'!B" + str(self.out.get_table_number() + 3) self.__out_ws.get_sheet().write_url(self.__out_ws.get_current_row(), 0, link, self.out.hyperlink, "Table of content") self.__out_ws.add_to_current_row(1) def update_base_text_row(self): if self.__base_text_row == 0: self.__base_text_row = self.__out_ws.get_current_row() def n23(self, cell): self.write(self.__out_ws.get_current_row(), 0, str(cell), self.out.n23_background) for i in range(1, self.__max_cell + 1): self.write(self.__out_ws.get_current_row(), i, None, self.out.n23_background) def get_row_type(self, row): # Returns the row type: # Row Type 0 = blank # Row Type 1 = first column only - Title # Row Type 2 = first column only - n23 # Row Type 3 = not first column only - cross-break # Row Type 4 = not first column only - tstat # Row Type 5 = data on first and other columns # Row Type 6 = tstat letters in cross-break # Row Type 7 = sub-title # Row Type 8 = foot note # Row Type 9 = Total row # Row Type 10 = Unweighted Base # Row Type 11 = Table number rtype = 0 temp = 0 tstat_cb = True if row[0].find("bot:") == 0: return 8 if (row[0].find("Unweighted") == 0) and len(row) > 1: return 10 if (row[0].find("Total") == 0 or row[0].find("Base") == 0 or row[0].find("Weighted") == 0) and len(row) > 1: return 9 for cell in row: pattern = re.compile(ur'[^ ]', re.UNICODE) if len(cell) > 0 and pattern.search(cell): temp += 1 if temp == 0: return 0 if temp == 1: if len(row[0]) > 0: check = 0 for i in range(2, 6): if self.row_types[i] > 0: check += 1 if check > 0: return 2 else: if len(self.__TableName) > 0: return 7 # if re.match(ur"[0-9]+", row[0]): # return 11 return 1 if len(row[0]) == 0: if self.row_types[5] > 0: return 4 else: for cell in row: pattern = re.compile(ur'^[A-Za-z]$', re.UNICODE) if len(cell) > 0 and not pattern.search(cell): tstat_cb = False break if tstat_cb: return 6 return 3 return 5 def print_bold(self, row): for i in range(0, len(row)): self.write(self.__out_ws.get_current_row(), i, row[i], self.out.bold) def print_title(self, row): for cell in row: self.write(self.__out_ws.get_current_row(), 0, cell) def print_n23(self, row): self.write(self.__out_ws.get_current_row(), 0, row[0], self.out.n23_background) for i in range(1, self.__max_cell): self.write(self.__out_ws.get_current_row(), i, "", self.out.n23_background) def print_cross_break(self, row): check = self.row_types[3] + self.row_types[6] if check == 1: self.__out_ws.add_to_current_row(2) temp = 0 if len(row) > self.__max_cell: self.__max_cell = len(row) for i in range(0, len(row)): if not row[i] == "" and not row[i] == " ": if not temp == 0: if temp + 1 < i: self.__out_ws.get_sheet().merge_range( self.__out_ws.get_current_row(), temp, self.__out_ws.get_current_row(), i - 1, row[temp], self.out.banner) else: self.write(self.__out_ws.get_current_row(), i - 1, row[temp], self.out.banner) self.write(self.__out_ws.get_current_row(), i, row[i], self.out.banner) else: self.write(self.__out_ws.get_current_row(), i, row[i], self.out.banner) temp = i else: self.write(self.__out_ws.get_current_row(), i, '', self.out.banner) if temp + 1 <= i and temp > 0 and len(row[temp]) > 1: self.__out_ws.get_sheet().merge_range( self.__out_ws.get_current_row(), temp, self.__out_ws.get_current_row(), i, row[temp], self.out.banner) self.__out_ws.get_sheet().set_row(self.__out_ws.get_current_row(), 25) def print_tstat(self, row): i = 0 for cell in row: pattern = re.compile(ur'[^A-Za-z]', re.UNICODE) if len(cell) > 0 and not pattern.search(cell): self.write(self.__out_ws.get_current_row(), i, cell, self.out.tstat) else: self.write(self.__out_ws.get_current_row(), i, cell, self.out.borders) i += 1 def print_regular(self, row): i = 0 for cell in row: self.write(self.__out_ws.get_current_row(), i, cell, self.out.borders) i += 1 def print_total_row(self, row): self.set__total(row[1]) i = 0 #self.__out_ws.add_to_current_row(-1) if not self.large_row: self.__out_ws.get_sheet().set_row( self.__out_ws.get_current_row() - 1, 100) self.large_row = True for cell in row: self.write(self.__out_ws.get_current_row(), i, cell, self.out.blued_style, "total row") i += 1 #self.row_types[5] += 1 #self.__out_ws.add_to_current_row(1) def print_unweighted_base(self, row): if not self.large_row: self.__out_ws.get_sheet().set_row( self.__out_ws.get_current_row() - 1, 100) self.large_row = True self.print_center(row) def print_sub_title(self, row): self.add_sub_title(row[0]) self.print_title(row) def print_footer(self): if not self.__for_tableu: self.__out_ws.add_to_current_row(1) for row in self.footer: self.print_title(row) self.__out_ws.add_to_current_row(1) def print_center(self, row): i = 0 for cell in row: self.write(self.__out_ws.get_current_row(), i, cell, self.out.center) i += 1 def append_to_footer(self, row): self.footer.append([row[0][5:]]) def switcher(self, arg): switch = { 1: self.print_title, 2: self.print_n23, 3: self.print_cross_break, 4: self.print_tstat, 5: self.print_regular, 6: self.print_center, 7: self.print_sub_title, 8: self.append_to_footer, 9: self.print_total_row, 10: self.print_unweighted_base, } return switch.get(arg) def print_content(self, row): r_type = self.get_row_type(row) self.current_row_type = r_type if r_type == 0 and self.row_types[5] == 0: return if not r_type in [1, 7] and self.btxt == 0: self.baseTextObj.process() self.btxt = 1 if r_type == 0: r_type = 6 if r_type in (2, 4, 5, 6) and not self.large_row: self.__out_ws.get_sheet().set_row( self.__out_ws.get_current_row() - 1, 100) self.large_row = True self.row_types[r_type] += 1 func = self.switcher(r_type) func(row) if r_type == 6: self.__out_ws.get_sheet().set_row(self.__out_ws.get_current_row(), 15) if not r_type == 8: self.__out_ws.add_to_current_row(1) def close_file(self): self.__out_ws.get_sheet()._opt_close() def add_sub_title(self, string): if len(string) > 0: self.__TableName = self.__TableName + " - " + string def get_current_row(self): return self.__current_row def increment_current_row(self): self.__out_ws.add_to_current_row(1) def fill_data(self, row): if row[0].find("$$sheet_name$$") >= 0 and not self.__for_tableu: self.process_sheet_name_row(row) return 0 self.data.append(row) def process_sheet_name_row(self, row): row[0] = row[0].replace("$$sheet_name$$", "") if not self.__for_tableu: self.__out_ws = Sheet(self.out, row[0]) self.__row_start = 0 self.out.set_current_ws(self.__out_ws) else: self.out.set_current_ws(row[0]) def get_total_row_num(self): for x, row in enumerate(self.data): if self.get_row_type(row) == 9: return x def get_break_count(self, total_row_num): cnt = 0 for x in self.data[:total_row_num]: if self.get_row_type(x) == 3: cnt += 1 return cnt def get_has_t_stat(self, total_row_num): for x in self.data[:total_row_num]: if self.get_row_type(x) == 6: return True return False def get_is_weighted(self, total_row_num): for x in self.data[:total_row_num]: if self.get_row_type(x) == 10: return True return False def get_title(self): first = True for num, x in enumerate(self.data): if self.get_row_type(x) == 1 and not re.match(ur"^[0-9]+$", x[0]): if first: first = False continue return num, x[0]
class SheetController: def __init__(self, scope, id, ranges): self.sheet = Sheet(scope, id) self.ranges = ranges ## READ # Returns Dict def read_metadata(self): data = self.sheet.fetch(self.ranges.get('num_raids', None)) num_raids = int(data[0][0]) data = self.sheet.fetch(self.ranges.get('types', None)) types = {} for row in data: types.update({row[0]: row[1]}) metadata = {'num_raids': num_raids, 'types': types} return metadata # Returns 1D Array def read_info(self, raid_num): data = self.sheet.fetch(self.ranges.get('info', None) % raid_num) info = data[0] return info # Returns 2D Array def read_roster(self, raid_num): data = self.sheet.fetch(self.ranges.get('roster', None) % raid_num) roster = data return roster # Returns Dict def read_raid(self, raid_num): raid = { 'number': raid_num, 'info_table': self.read_info(raid_num), 'roster_table': self.read_roster(raid_num) } return raid # Returns List def read_raid_list(self): metadata = self.read_metadata() raid_list = [] for i in range(1, int(metadata.get('num_raids', None)) + 1): raid = self.read_raid(i) raid_list.append(raid) return raid_list # Returns Dict def read_application_list(self, type): data = self.sheet.fetch('{0}Applications'.format(type)) data.pop(0) application_list = {'type': type, 'applicant_table': data} return application_list # Returns List def read_application_lists(self): metadata = self.read_metadata() types = metadata.get('types', {}) application_lists = [] for key in types.keys(): application_list = self.read_application_list(key) application_lists.append(application_list) return application_lists # Returns tuple def read_everything(self): metadata = self.read_metadata() raid_list = self.read_raid_list() application_lists = self.read_application_lists() return metadata, raid_list, application_lists ## WRITE def write_row(self, range, row): body = {'values': [row]} self.sheet.append(range, body) def write_application(self, type, application): self.write_row('{0}Applications'.format(type), application)
from Point import Point from Rectangle import Rectangle from Sheet import Sheet from helping_functions import show_graphics, insert_rectangles sh = Sheet(500, 400) sh.get_info() n = int(input("Enter the number of rectangles : ")) input_rect = [] for i in range(n): s = input("rect {} length breadth : ".format(i + 1)).split() input_rect.append((int(s[0]), int(s[1]))) #input_rect = [(100,30), (20,50), (200,70), (70, 50), (300, 120), (90,90), (40, 120), (50, 150)] insert_rectangles(input_rect, sh) sh.get_info() show_graphics(sh.rectangles_tl_br, sh.l, sh.b)
def __init__(self, scope, id, ranges): self.sheet = Sheet(scope, id) self.ranges = ranges
def test_owned_for_a_suit(self): sheet = Sheet('test') sheet.own_cards([(2, 'L'), (6, 'L'), (3, 'H')]) self.assertItemsEqual([(2, 'L'), (6, 'L')], sheet.owned('L'))
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)
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)
list_urls = open('scripts\general-urls.txt') list_keywords = open('scripts\keywords.txt', encoding='UTF-8').read().splitlines() forbidden_file = open('forbidden-urls.txt', 'a') iterator = 0 url_number = 0 max_scrape = 0 occurrences = 0 row = 2 en = Enhance() sc = Score() obj_sheet = Workbook() sheet = obj_sheet.active ns = Sheet('Planilha de Ocorrencias', 'sheet', obj_sheet, sheet) ns.set_header1() ns.save_sheet() for url in list_urls: # if iterator >= max_scrape: # break if en.set_delay(url): delay = random.randint(0, 13) print('Delay: ' + str(delay)) time.sleep(delay) print('Sheet: {} | N: {} | URL: {}'.format(iterator + 1, url_number + 1, url))
class Manager(object): ''' classdocs Helps manage the football pool tracker. ''' def __init__(self, website, sheet_id): self.website = website self.sheet = Sheet(sheet_id) def get_players(self): rows = self.sheet.getValuesFromSheet("A2:Z99") player_list = [] index = 1 for row in rows: if len(row) == 0: break i = 0 if len(row) == 1: index += 1 continue for cell in row: i += 1 if is_int(cell): break player_list.append(Player(index, row[0], row[1:i])) index += 1 return player_list def format_all_team_names(self): team_lists = self.sheet.getValuesFromSheet("B2:L99") for team_list in team_lists: if len(team_list) == 0: continue for team_name in team_list: if not team_name.strip(): continue self.website.formatTeam(team_name) def get_games(self): team_names = self.sheet.getValuesFromSheet("B2:L2")[0] game_list = [] column_index = 1 for team_name in team_names: if not team_name: continue game_attrs = self.website.get_game_attrs(team_name) game = Game(column_index, game_attrs[0], game_attrs[1], game_attrs[2], game_attrs[3], game_attrs[4]) game_list.append(game) if game.is_tb_game: break column_index += 1 return game_list def update_records(self, players, game): winner_row_index_list = [] num_players = len(players) for player in players: if not game.is_tb_game: for pick in player.picks: if game.get_winner().lower() == self.website.formatTeam( pick.lower()): player.record[0] += 1 winner_row_index_list.append(player.id) break else: player.record[1] += 1 else: #is tb player.record[2] = abs((int)(game.score[0]) + (int)(game.score[1]) - (int)(player.tbpts)) game.been_updated = True if not game.is_tb_game: if len(winner_row_index_list) == 0: #there should never be a game that has no winners print("Error updating game: " + game.teams[0] + ' vs ' + game.teams[1]) raise Exception('Error updating game') self.sheet.color_winning_cells(winner_row_index_list, game.column_id) self.sheet.color_losing_cells( self.get_loser_index_list(winner_row_index_list, num_players), game.column_id) def get_loser_index_list(self, winner_row_index_list, num_players): loser_row_list = [False for i in range(num_players + 1)] for i in range(len(loser_row_list)): loser_row_list[i] = False if i in winner_row_index_list else True return [i for i, x in enumerate(loser_row_list) if x and i > 0] def update_sheet_winner(self, players): self.sheet.update_winner(players) def update_sheet(self, players, game): self.update_records(players, game) self.sheet.update(players) def add_column_headings_and_format(self, num_games): self.sheet.add_column_headings_and_format(num_games)
def test_set_suit_total(self): sheet = Sheet('test') sheet.own_cards([(5, 'L')]) sheet.set_suit_total('L', 3) self.assertEqual(sheet_table(owned=[(5, 'L')], totals={'L': 3}), sheet.table)
def test_owned_for_a_rank(self): sheet = Sheet('test') sheet.own_cards([(3, 'L'), (6, 'L'), (3, 'H')]) self.assertItemsEqual([(3, 'L'), (3, 'H')], sheet.owned(rank=3))