From ce4efded122e433958a6bf33b9c74ed9da821160 Mon Sep 17 00:00:00 2001 From: Kyattsukuro Date: Thu, 2 Apr 2026 13:35:25 +0200 Subject: [PATCH] fixing things --- .../instructions/countings_formater.py | 3 ++- fledermaus_formatter/instructions/mappings.py | 1 + fledermaus_formatter/main.py | 2 +- .../table_handler/commands/find_and_replace.py | 2 -- .../table_handler/commands/regex_move_to_col.py | 12 ++++++++---- .../table_handler/commands/row_color_to_value.py | 2 +- fledermaus_formatter/table_handler/serializer.py | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/fledermaus_formatter/instructions/countings_formater.py b/fledermaus_formatter/instructions/countings_formater.py index f6cdd73..44175f0 100644 --- a/fledermaus_formatter/instructions/countings_formater.py +++ b/fledermaus_formatter/instructions/countings_formater.py @@ -31,7 +31,8 @@ COL_INSTRUCTIONS = { "command": "REGEX_MOVE_TO_COL", "with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to" "match": r"^.*({{% 0 %}}),?(?:.*+)*$", - "to": "Fangart" + "to": "Fangart", + "copy": True } ], ("Anzahl",): [{ diff --git a/fledermaus_formatter/instructions/mappings.py b/fledermaus_formatter/instructions/mappings.py index b6f8bb5..d7d2537 100644 --- a/fledermaus_formatter/instructions/mappings.py +++ b/fledermaus_formatter/instructions/mappings.py @@ -316,6 +316,7 @@ CATCHED_BY = { "Nfg": [*add_cased_options("nfg"), *add_cased_options("nf")], "KK": [*add_cased_options("kk"), + *add_cased_options(" k "), *add_cased_options("überwinterungskästen"), *add_cased_options("kastenkontrolle"), *add_cased_options("kasten")], diff --git a/fledermaus_formatter/main.py b/fledermaus_formatter/main.py index 059d2d0..49999e0 100644 --- a/fledermaus_formatter/main.py +++ b/fledermaus_formatter/main.py @@ -59,7 +59,7 @@ def main(): args = parser.parse_args() if args.v: - print("1.4") + print("1.5") return if not args.type: parser.error("The --type argument is required.") diff --git a/fledermaus_formatter/table_handler/commands/find_and_replace.py b/fledermaus_formatter/table_handler/commands/find_and_replace.py index 67b2828..54d76a7 100644 --- a/fledermaus_formatter/table_handler/commands/find_and_replace.py +++ b/fledermaus_formatter/table_handler/commands/find_and_replace.py @@ -1,4 +1,3 @@ -import re from fledermaus_formatter.table_handler.Entry import Entry from copy import deepcopy @@ -13,7 +12,6 @@ class FindAndReplace: for correct_name, bad_names in self.map.items(): for bad_name in bad_names: if self.require_full_match and bad_name == res: - # Todo remove random leading/trailing spaces before if res = correct_name break elif not self.require_full_match: diff --git a/fledermaus_formatter/table_handler/commands/regex_move_to_col.py b/fledermaus_formatter/table_handler/commands/regex_move_to_col.py index e911604..3fb8092 100644 --- a/fledermaus_formatter/table_handler/commands/regex_move_to_col.py +++ b/fledermaus_formatter/table_handler/commands/regex_move_to_col.py @@ -3,9 +3,10 @@ import re from fledermaus_formatter.table_handler.Entry import Entry class RegexMoveToCol: - def __init__(self, match: str, to: str, with_input_iteration: list[list[str]]|None = None): + def __init__(self, match: str, to: str, with_input_iteration: list[list[str]]|None = None, copy: bool = False): self.match = match self.to = to + self.copy = copy if with_input_iteration is not None: with_input_iteration = ( @@ -65,13 +66,16 @@ class RegexMoveToCol: def execute_on_row(self, row: dict[str, str], source_coll: str = None): if not source_coll: raise ValueError("source_col required") + changes = {} + if self.with_input_iteration: - changes = {} for iteration in self.with_input_iteration: used_regex = self.match for operation_id in range(0, self.__operation_input_depth): used_regex = used_regex.replace(f"{{{{% {operation_id} %}}}}", iteration[operation_id]) changes = self.do_changes(source_coll, used_regex, row, changes) - return changes else: - return self.do_changes(source_coll, self.match, row) \ No newline at end of file + changes = self.do_changes(source_coll, self.match, row) + if self.copy and source_coll in changes: + del changes[source_coll] + return changes \ No newline at end of file diff --git a/fledermaus_formatter/table_handler/commands/row_color_to_value.py b/fledermaus_formatter/table_handler/commands/row_color_to_value.py index 96679c4..06897cf 100644 --- a/fledermaus_formatter/table_handler/commands/row_color_to_value.py +++ b/fledermaus_formatter/table_handler/commands/row_color_to_value.py @@ -32,7 +32,7 @@ class RowColorToCalue: def _check_if_collection_matchers(self, collectin: dict[tuple[int, int, int]], color_place: str) -> bool: - threshold_sq = 120 + threshold_sq = 80 res_map = [] if self.approximate: diff --git a/fledermaus_formatter/table_handler/serializer.py b/fledermaus_formatter/table_handler/serializer.py index 994b436..d6ac936 100644 --- a/fledermaus_formatter/table_handler/serializer.py +++ b/fledermaus_formatter/table_handler/serializer.py @@ -105,7 +105,7 @@ class TableSerializer: case "FIND_AND_REPLACE": res = FindAndReplace(instruct["map"], instruct.get("reqire_full_match", False)).execute_on_cell(in_place_working_row[source_cell]) case "REGEX_MOVE_TO_COL": - res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration")) \ + res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration"), instruct.get("copy", False)) \ .execute_on_row(in_place_working_row, source_cell) case "REGEX_EDIT_COL": res = RegexEditCol(instruct["match"], instruct["replace_with"], instruct.get("matching_group_rearange"), instruct.get("match_none"))\