diff --git a/.~lock.ringe_short_out.xlsx# b/.~lock.ringe_short_out.xlsx# new file mode 100644 index 0000000..9de1353 --- /dev/null +++ b/.~lock.ringe_short_out.xlsx# @@ -0,0 +1 @@ +,someone,nixLap,30.03.2026 10:11,file:///home/someone/.config/yolk/eggs/libreoffice/4; \ No newline at end of file diff --git a/data/.~lock.ringe.xlsx# b/data/.~lock.ringe.xlsx# new file mode 100644 index 0000000..a64071a --- /dev/null +++ b/data/.~lock.ringe.xlsx# @@ -0,0 +1 @@ +,someone,nixLap,30.03.2026 10:01,file:///home/someone/.config/yolk/eggs/libreoffice/4; \ No newline at end of file diff --git a/data/.~lock.ringe_short.xlsx# b/data/.~lock.ringe_short.xlsx# new file mode 100644 index 0000000..9776c27 --- /dev/null +++ b/data/.~lock.ringe_short.xlsx# @@ -0,0 +1 @@ +,someone,nixLap,30.03.2026 10:00,file:///home/someone/.config/yolk/eggs/libreoffice/4; \ No newline at end of file diff --git a/data/ringe.xlsx b/data/ringe.xlsx index fbcd6b0..ae38990 100644 Binary files a/data/ringe.xlsx and b/data/ringe.xlsx differ diff --git a/data/ringe_short.xlsx b/data/ringe_short.xlsx index 6dab367..012728d 100644 Binary files a/data/ringe_short.xlsx and b/data/ringe_short.xlsx differ diff --git a/fledermaus_formatter/instructions/ring_formater.py b/fledermaus_formatter/instructions/ring_formater.py index d4cc35d..27089f6 100644 --- a/fledermaus_formatter/instructions/ring_formater.py +++ b/fledermaus_formatter/instructions/ring_formater.py @@ -74,8 +74,8 @@ ROW_INSTRUCTIONS = [ "command": "ROW_COLOR_TO_BOOL", # Match when found as text color in any col of the row "fg_colors": [(255,0,0), (0,0,255)], "approximate": True, - "threshold": "ALL", # ALL, ANY, MAJORITY of row must be collored + "threshold": "MAJORITY", # ALL, ANY, MAJORITY of row must be collored "target": "Wiederfunde", - "value": "TRUE", + "value": True, } ] \ 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 3ba3c1a..4e0e305 100644 --- a/fledermaus_formatter/table_handler/commands/row_color_to_value.py +++ b/fledermaus_formatter/table_handler/commands/row_color_to_value.py @@ -13,9 +13,9 @@ class RowColorToCalue: self.fg_color = fg_colors if fg_colors else [] self.bg_color = bg_colors if bg_colors else [] - self.value = value, - self.target = target, - self.approximate = approximate, + self.value = value + self.target = target + self.approximate = approximate if threshold not in ("ALL", "ANY", "MAJORITY"): raise ValueError("threshold must be ALL, ANY or MAJORITY") @@ -23,12 +23,16 @@ class RowColorToCalue: def _check_if_collection_matchers(self, collectin: dict[tuple[int, int, int]], color_place: str) -> bool: + threshold_sq = 130 ** 2 + res_map = [] if self.approximate: - margin = 10 for color in collectin: - for allowed_color in self.__dict__[color_place]: - res_map.append(all(abs(a - b) <= margin for a, b in zip(color, allowed_color))) + is_match = any( + sum((a - b) ** 2 for a, b in zip(color, allowed_color)) <= threshold_sq + for allowed_color in self.__dict__[color_place] + ) + res_map.append(is_match) else: res_map = list(map(lambda x: x in self.__dict__[color_place])) @@ -44,9 +48,9 @@ class RowColorToCalue: def execute_on_row(self, row: dict[str, str], source_coll: str|None = None): color_pace_results = [] for color_place in ["fg_color", "bg_color"]: - color_collection = (map(lambda c: c.__dict__[color_place], row.values())) + color_collection = (map(lambda c: c.__dict__[color_place], filter(lambda x: x.value, row.values()))) color_pace_results.append(self._check_if_collection_matchers(color_collection, color_place)) - if all(color_pace_results): + if any(color_pace_results): return {self.target: self.value} return {} \ No newline at end of file diff --git a/fledermaus_formatter/table_handler/serializer.py b/fledermaus_formatter/table_handler/serializer.py index 0ab61dd..d03ed57 100644 --- a/fledermaus_formatter/table_handler/serializer.py +++ b/fledermaus_formatter/table_handler/serializer.py @@ -63,7 +63,7 @@ class TableSerializer: for expected_col, ws_idx in map_expected_with_ws.items(): cell = row[ws_idx] data[expected_col][rid] = Entry( - value=str(cell.value) if not cell.value is None else "", + value=str(cell._value) if not cell.value is None else "", bg_color=hex_to_rgb(cell.fill.start_color.rgb if cell.fill and cell.fill.start_color else "#0"), fg_color=hex_to_rgb(cell.font.color.rgb if cell.font and cell.font.color else "#0") ) diff --git a/ringe_short_out.xlsx b/ringe_short_out.xlsx index b089ad8..45394e1 100644 Binary files a/ringe_short_out.xlsx and b/ringe_short_out.xlsx differ