def add_gender(self, name, cap): # Update Memory self._players.update({name: []}) self._j_data['settings'].update({name + "_cap": cap}) # Update Files File.add_gender(self.name(), name, cap)
def toggle_file_saving(self, menu_ref): # Update State self._file_saving = not self._file_saving # Update File Settings File.update_file_saving(self.season().name(), self.name(), self.file_saving()) # Update Round Data within 'seasons.json' if(self.file_saving()): self.save_rounds() # Update Menu item if(menu_ref != None): Builder.add_menu(menu_ref, "{0} Saving".format("Disable" if self.file_saving() else "Enable"), "{0}_{1}".format(menu_ref, "fs")) # Skip over monitor_input halt return "SKIP"
def advanced(out, *files): matrix, min_d, min_m = File._make_matrix(files) matrix = list(zip(*matrix)) data = File._advanced_matrix(matrix, min_d) out_data = list() for values in data: temp_dict = dict() for i, value in enumerate(values): if i < min_d: temp_dict["D{}".format(i + 1)] = value else: temp_dict["MS{}".format(i + 1 - min_d)] = value out_data.append(temp_dict) with open(out, 'w') as outfile: json.dump({"fields": out_data}, outfile)
def main(): data = File("../f_libraries_of_the_world.txt") log.info(data.wholeData) # Create libraries for lib in data.libraries: l = Library(lib["days"], lib["numBooks"], lib["dailyScan"], lib["books"], lib["index"]) LIBRARIES.append(l) # Creates list of max Score for each library # maxScoreBooty = LIBRARIES.sort(key=lambda x: x.) maxScores = [] for lib in LIBRARIES: maxScores.append([lib.maxTime(), lib]) sorted(maxScores, key=itemgetter(0)) log.info(maxScores) daysLeft = int(data.meta["days"]) numberOfLibs = 0 libIndexes = [] books = [] for key, value in enumerate(maxScores): if value[1].signUpTime < daysLeft: numberOfLibs += 1 libIndexes.append(value[1].libraryID) daysLeft -= value[1].signUpTime # books[key] = value[1].books[:daily * daysLeft ] books.append(value[1].books) # Num of libs, libraries, books data.saveAnswer(numberOfLibs, libIndexes, books)
class LMM: lmm = [] obj_file = File() matrix_a = obj_file.matrix_a def compare(self, x, y): Z = [] # U - верх, RL, D - низ, С - середина UL = (x - 1, y - 1) UC = (x - 1, y) UR = (x - 1, y + 1) LC = (x, y - 1) RC = (x, y + 1) DL = (x + 1, y - 1) DC = (x + 1, y) DR = (x + 1, y + 1) Z_ = [UL, UC, UR, LC, RC, DL, DC, DR] for z in Z_: try: x_, y_ = z if x_ >= 0 and y_ >= 0: Z.append(self.matrix_a[x_][y_]) except IndexError: pass return Z def show_lmm(self, matrix_a): for n in range(len(matrix_a)): for m in range(len(matrix_a[0])): if matrix_a[n][m] < min(self.compare(n, m)): self.lmm.append([matrix_a[n][m], n, m]) self.lmm.insert(0, ['Local\nnumber', 'coordinate\nx', 'coordinate\ny']) table = SingleTable(self.lmm) table.inner_row_border = True for i in range(len(matrix_a)): table.justify_columns[i] = 'center' print(table.table)
from terminaltables import AsciiTable from colorclass import Color # ================================== [Functions] ================================ def cls(): if platform == "linux" or platform == "linux2": os.system(['clear'][os.name == os.sys.platform]) elif platform == "win32": os.system(['cls'][os.name == os.sys.platform]) # =============================================================================== # ================================== [Variables] ================================ obj_file = File() # =============================================================================== while True: menu = [['1', 'Show information about gold'], ['2', 'Show information about gold quality'], ['3', 'Add column'], ['4', 'Add line'], ['5', 'Delete line'], ['6', 'Delete column'], ['7', 'Find average for each quality'], ['8', 'Write to a new file all the gold that has quality 1 and 2'], ['9', 'Show information about gold'], ['10', 'Find the maximum amount of gold that the robot can mine'], ['11', 'Find local minimums in the matrix'], ['0', 'Close program']] table = AsciiTable(menu) table.title = Color('{blue}Menu{/blue}') table.inner_row_border = True
def save_rounds(self): return File.update_tournament_rounds(self.season().name(), self.name(), self._rounds_raw)
def advanced(out, *files): matrix, min_d, min_m = CSV._make_matrix(files) matrix = list(zip(*matrix)) out_data = File._advanced_matrix(matrix, min_d) # записываем файл CSV._write_to_file(out, out_data, min_d, min_m, name_m="MS")
def advanced(out, *files): matrix, min_d, min_m = XML._make_matrix(files) matrix = list(zip(*matrix)) matrix = File._advanced_matrix(matrix, min_d) XML._write_to_file(out, matrix, min_d, min_m, name_m="MS")