diff --git a/.~lock.ringe_short_out.xlsx# b/.~lock.ringe_short_out.xlsx# deleted file mode 100644 index 9de1353..0000000 --- a/.~lock.ringe_short_out.xlsx# +++ /dev/null @@ -1 +0,0 @@ -,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_short.xlsx# b/data/.~lock.ringe_short.xlsx# deleted file mode 100644 index 9776c27..0000000 --- a/data/.~lock.ringe_short.xlsx# +++ /dev/null @@ -1 +0,0 @@ -,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_short.xlsx b/data/ringe_short.xlsx index 012728d..312442b 100644 Binary files a/data/ringe_short.xlsx and b/data/ringe_short.xlsx differ diff --git a/data/zählungen_short.xlsx b/data/zählungen_short.xlsx index c1a6939..37e7717 100644 Binary files a/data/zählungen_short.xlsx and b/data/zählungen_short.xlsx differ diff --git a/fledermaus_formatter/instructions/countings_formater.py b/fledermaus_formatter/instructions/countings_formater.py index b854a0d..f6cdd73 100644 --- a/fledermaus_formatter/instructions/countings_formater.py +++ b/fledermaus_formatter/instructions/countings_formater.py @@ -19,32 +19,39 @@ EXPECTED_OUTPUT_TABLE_SCHEMA.remove("Geschlecht") COL_INSTRUCTIONS = { ("Art",): { "command": "FIND_AND_REPLACE", - "reqire_full_match": True, - "map": SPICIES + "map": SPICIES, + "reqire_full_match": True }, - ("Ort",): { - "command": "REGEX_MOVE_TO_COL", - "with_input_iteration": CATCHED_BY, # Moves matching group {{% 0 %}} to "to" - "match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", - "to": "Fangart" - }, - ("Anzahl",): { + ("Ort",): [ + { + "command": "FIND_AND_REPLACE", + "map": CATCHED_BY + }, + { + "command": "REGEX_MOVE_TO_COL", + "with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to" + "match": r"^.*({{% 0 %}}),?(?:.*+)*$", + "to": "Fangart" + } + ], + ("Anzahl",): [{ "command": "REGEX_EDIT_COL", "match": r"^ *$", - "replace_with": "1" - }, - ("Anzahl",): { + "replace_with": "1", + "match_none": True + }, + { "command": "REGEX_GROUP_VALUEBASED_CHOOS", "match": r"^ *([0-9]+) *oder *([0-9]+) *$", "highest": True - }, + }], } ROW_INSTRUCTION = [ { "command": "CONDITIONAL_COPY", "when_regex": { - "Geschlecht": r"^(?:[^ ]* +)*(m),?(?: .*+)*$", + "Geschlecht": r"^.*(m),?(?:.*+)*$", "Anzahl": r"([0-9]+)" }, "source": "Anzahl", @@ -53,7 +60,7 @@ ROW_INSTRUCTION = [ { "command": "CONDITIONAL_COPY", "when_regex": { - "Geschlecht": r"^(?:[^ ]* +)*(w),?(?: .*+)*$", + "Geschlecht": r"^.*(w),?(?:.*+)*$", "Anzahl": r"([0-9]+)" }, "source": "Anzahl", diff --git a/fledermaus_formatter/instructions/mappings.py b/fledermaus_formatter/instructions/mappings.py index 6766073..03bf651 100644 --- a/fledermaus_formatter/instructions/mappings.py +++ b/fledermaus_formatter/instructions/mappings.py @@ -1,3 +1,17 @@ +def flatten_dict(d): + flat = {} + for key, values in d.items(): + for value in values: + flat[value] = key + return flat + +def add_cased_options(inp: str): + return set([ + inp, + inp.lower(), + inp.upper(), + inp.capitalize(), + ]) SPICIES = { "Bbar": [ "B.bar.", @@ -298,14 +312,18 @@ SPICIES = { ], } -CATCHED_BY = [ - "Nfg", - "WQK", - "Wst", - "KK", - "AFZ", - "Detektor", -] +CATCHED_BY = { + "Nfg": [*add_cased_options("nfg")], + "KK": [*add_cased_options("kk"), + *add_cased_options("überwinterungskästen"), + *add_cased_options("kastenkontrolle"), + *add_cased_options("kasten")], + "WQK": [*add_cased_options("wqk"), + *add_cased_options("kontrolle")], + "Wst": [*add_cased_options("wst")], + "AFZ": [*add_cased_options("afz")], + "Detektor": [*add_cased_options("detektor")], +} AGE = { "j": [ @@ -341,9 +359,3 @@ REPRODUCTION = { ] } -def flatten_dict(d): - flat = {} - for key, values in d.items(): - for value in values: - flat[value] = key - return flat diff --git a/fledermaus_formatter/instructions/ring_formater.py b/fledermaus_formatter/instructions/ring_formater.py index 75407b6..9dbe12e 100644 --- a/fledermaus_formatter/instructions/ring_formater.py +++ b/fledermaus_formatter/instructions/ring_formater.py @@ -32,21 +32,15 @@ COL_INSTRUCTIONS = { { "command": "REGEX_MOVE_TO_COL", "with_input_iteration": list(REPRODUCTION.keys()), # Moves matching group {{% 1 %}} to "to" - "match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", + "match": r"^.*({{% 0 %}}),?(?:.*+)*$", "to": "Reproduktionsstatus" }, { "command": "REGEX_MOVE_TO_COL", "with_input_iteration": list(AGE.keys()), # Moves matching group {{% 1 %}} to "to" - "match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", + "match": r"^.*({{% 0 %}}),?(?:.*+)*$", "to": "Alter" - }, - { - # Special case ma -> Geschlecht a | Alter a - "command": "REGEX_MOVE_TO_COL", - "match": r"^(?:[^ ]* +)*m(a),?(?: .*+)*$", - "to": "Alter" }], ("Ringnummer",): { "command": "REGEX_EDIT_COL", @@ -59,12 +53,18 @@ COL_INSTRUCTIONS = { "map": SPICIES, "reqire_full_match": True }, - ("Ort",): { - "command": "REGEX_MOVE_TO_COL", - "with_input_iteration": CATCHED_BY, # Moves matching group {{% 1 %}} to "to" - "match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", - "to": "Fangart" - } + ("Ort",): [ + { + "command": "FIND_AND_REPLACE", + "map": CATCHED_BY + }, + { + "command": "REGEX_MOVE_TO_COL", + "with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to" + "match": r"^.*({{% 0 %}}),?(?:.*+)*$", + "to": "Fangart" + } + ] } diff --git a/fledermaus_formatter/table_handler/Entry.py b/fledermaus_formatter/table_handler/Entry.py index df803d2..758039a 100644 --- a/fledermaus_formatter/table_handler/Entry.py +++ b/fledermaus_formatter/table_handler/Entry.py @@ -4,5 +4,5 @@ from dataclasses import dataclass @dataclass class Entry: value: str|int|float|bool|None - bg_color: tuple[str, str, str] - fg_color: tuple[str, str, str] \ No newline at end of file + bg_color: tuple[str, str, str] = (255,255,255) + fg_color: tuple[str, str, str] = (255,255,255) \ No newline at end of file diff --git a/fledermaus_formatter/table_handler/commands/copy.py b/fledermaus_formatter/table_handler/commands/copy.py index 3a9d273..58c6035 100644 --- a/fledermaus_formatter/table_handler/commands/copy.py +++ b/fledermaus_formatter/table_handler/commands/copy.py @@ -1,4 +1,4 @@ - +from fledermaus_formatter.table_handler.Entry import Entry class Copy: def __init__(self, source: str, target: str, replace = False): @@ -8,6 +8,6 @@ class Copy: def execute_on_row(self, row=dict[str, str], source_col=None): return { - **({} if not self.replace else {self.source_col: ""}), - self.target: row[self.source].value + **({} if not self.replace else {self.source_col: Entry(value="")}), + self.target: Entry(row[self.source].value, bg_color=row[self.source].bg_color, fg_color=row[self.source].fg_color) } \ No newline at end of file diff --git a/fledermaus_formatter/table_handler/commands/regex_edit_col.py b/fledermaus_formatter/table_handler/commands/regex_edit_col.py index b7e89bb..c61f2a7 100644 --- a/fledermaus_formatter/table_handler/commands/regex_edit_col.py +++ b/fledermaus_formatter/table_handler/commands/regex_edit_col.py @@ -1,10 +1,11 @@ import regex class RegexEditCol: - def __init__(self, match, replace_with, matching_group_rearange: bool = False): + def __init__(self, match, replace_with, matching_group_rearange: bool = False, match_none: bool = False): self.match = match self.replace_with = replace_with self.matching_group_rearange = matching_group_rearange + self.match_none = match_none def _reorder(self, value: str): matches = regex.match(self.match, value) @@ -18,7 +19,9 @@ class RegexEditCol: def execute_on_cell(self, entry) -> str: value = entry.value if value is None: - return value + if self.match_none: + entry.value = self.replace_with + return entry if self.matching_group_rearange: entry.value = self._reorder(value) diff --git a/fledermaus_formatter/table_handler/serializer.py b/fledermaus_formatter/table_handler/serializer.py index bee5ceb..cb85b2b 100644 --- a/fledermaus_formatter/table_handler/serializer.py +++ b/fledermaus_formatter/table_handler/serializer.py @@ -108,7 +108,7 @@ class TableSerializer: res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration")) \ .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"))\ + res = RegexEditCol(instruct["match"], instruct["replace_with"], instruct.get("matching_group_rearange"), instruct.get("match_none"))\ .execute_on_cell(in_place_working_row[source_cell]) case "REGEX_GROUP_VALUEBASED_CHOOS": res = RegexGroupValuebasedChoose(instruct["match"], instruct["highest"])\ diff --git a/ringe_short_out.xlsx b/ringe_short_out.xlsx index 45394e1..67047eb 100644 Binary files a/ringe_short_out.xlsx and b/ringe_short_out.xlsx differ diff --git a/zählungen_short_out.xlsx b/zählungen_short_out.xlsx index 50da9be..383e4d2 100644 Binary files a/zählungen_short_out.xlsx and b/zählungen_short_out.xlsx differ