def __post_init__(self, order: str, search_sheet: Worksheet): row = int(re.search(r"(R[0-9]+)", order).group(0)[1:]) # type: ignore column = int( re.search(r"(C[0-9]+)", order).group(0)[1:] # type: ignore ) - 1 self.cell_coordinates = (row, column) self.cell_address = search_sheet.cell(row, column).address self.steel_type = search_sheet.cell(row, 4).value self.steel_depth = search_sheet.cell(row, 5).value self.user_cell_color = get_format_safe( get_user_entered_format, search_sheet, self.cell_address).backgroundColor self.user_f_row_color = get_format_safe(get_user_entered_format, search_sheet, f"F{row}").backgroundColor
def is_row_empty(ws: gspread.Worksheet, row: int, min_horizontal_empty_cells: int) -> bool: """ Checks whether a given row in a worksheet is empty :param ws: Worksheet to check whether the given row is empty on. :param row: The index of the row to check :param min_horizontal_empty_cells: Minimum number of empty continuous cells needed, from left to right. :return: Whether there are at least min_horizontal_empty continuous empty cells in the row from left to right. """ for col in range(1, 1 + min_horizontal_empty_cells): if ws.cell(row, col).value: return False return True
def done(self, ws: Worksheet, env: Env, results: Optional[Dict[str, int]] = None, prefix_metrics: Optional[str] = None): self.update_state(ws, State.done, env) if env != Env.eval: self.update_date(ws, env, TestProgress.end, datetime.now()) metrics = [ Metrics.loss, Metrics.accuracy, Metrics.f1_score, Metrics.miou, Metrics.precision, Metrics.recall ] cells = [] prefix_col = '' if env == Env.train else f'{env.value}_' for m in metrics: cell = ws.cell(self.id + 1, self.columns.index(prefix_col + m.value) + 1) value = results[(prefix_metrics or '') + m.value] cell.value = "{:.6f}".format(value).replace('.', ',') cells.append(cell) if env != env.test: for m in metrics: name_key_best_val = f'best_{prefix_col}{m.value}' cell = ws.cell(self.id + 1, self.columns.index(name_key_best_val) + 1) value = results['best_' + (prefix_metrics or '') + m.value] cell.value = "{:.6f}".format(value).replace('.', ',') cells.append(cell) cell = ws.cell(self.id + 1, self.columns.index('machine') + 1) cell.value = socket.gethostname() ws.update_cells([*cells, cell])