applying functional fixes

This commit is contained in:
Kyattsukuro 2026-03-30 21:19:02 +02:00
parent 195cda37bd
commit 26c1513148
13 changed files with 73 additions and 53 deletions

View File

@ -1 +0,0 @@
,someone,nixLap,30.03.2026 10:11,file:///home/someone/.config/yolk/eggs/libreoffice/4;

View File

@ -1 +0,0 @@
,someone,nixLap,30.03.2026 10:00,file:///home/someone/.config/yolk/eggs/libreoffice/4;

Binary file not shown.

Binary file not shown.

View File

@ -19,32 +19,39 @@ EXPECTED_OUTPUT_TABLE_SCHEMA.remove("Geschlecht")
COL_INSTRUCTIONS = { COL_INSTRUCTIONS = {
("Art",): { ("Art",): {
"command": "FIND_AND_REPLACE", "command": "FIND_AND_REPLACE",
"reqire_full_match": True, "map": SPICIES,
"map": SPICIES "reqire_full_match": True
}, },
("Ort",): { ("Ort",): [
{
"command": "FIND_AND_REPLACE",
"map": CATCHED_BY
},
{
"command": "REGEX_MOVE_TO_COL", "command": "REGEX_MOVE_TO_COL",
"with_input_iteration": CATCHED_BY, # Moves matching group {{% 0 %}} to "to" "with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to"
"match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", "match": r"^.*({{% 0 %}}),?(?:.*+)*$",
"to": "Fangart" "to": "Fangart"
}, }
("Anzahl",): { ],
("Anzahl",): [{
"command": "REGEX_EDIT_COL", "command": "REGEX_EDIT_COL",
"match": r"^ *$", "match": r"^ *$",
"replace_with": "1" "replace_with": "1",
"match_none": True
}, },
("Anzahl",): { {
"command": "REGEX_GROUP_VALUEBASED_CHOOS", "command": "REGEX_GROUP_VALUEBASED_CHOOS",
"match": r"^ *([0-9]+) *oder *([0-9]+) *$", "match": r"^ *([0-9]+) *oder *([0-9]+) *$",
"highest": True "highest": True
}, }],
} }
ROW_INSTRUCTION = [ ROW_INSTRUCTION = [
{ {
"command": "CONDITIONAL_COPY", "command": "CONDITIONAL_COPY",
"when_regex": { "when_regex": {
"Geschlecht": r"^(?:[^ ]* +)*(m),?(?: .*+)*$", "Geschlecht": r"^.*(m),?(?:.*+)*$",
"Anzahl": r"([0-9]+)" "Anzahl": r"([0-9]+)"
}, },
"source": "Anzahl", "source": "Anzahl",
@ -53,7 +60,7 @@ ROW_INSTRUCTION = [
{ {
"command": "CONDITIONAL_COPY", "command": "CONDITIONAL_COPY",
"when_regex": { "when_regex": {
"Geschlecht": r"^(?:[^ ]* +)*(w),?(?: .*+)*$", "Geschlecht": r"^.*(w),?(?:.*+)*$",
"Anzahl": r"([0-9]+)" "Anzahl": r"([0-9]+)"
}, },
"source": "Anzahl", "source": "Anzahl",

View File

@ -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 = { SPICIES = {
"Bbar": [ "Bbar": [
"B.bar.", "B.bar.",
@ -298,14 +312,18 @@ SPICIES = {
], ],
} }
CATCHED_BY = [ CATCHED_BY = {
"Nfg", "Nfg": [*add_cased_options("nfg")],
"WQK", "KK": [*add_cased_options("kk"),
"Wst", *add_cased_options("überwinterungskästen"),
"KK", *add_cased_options("kastenkontrolle"),
"AFZ", *add_cased_options("kasten")],
"Detektor", "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 = { AGE = {
"j": [ "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

View File

@ -32,21 +32,15 @@ COL_INSTRUCTIONS = {
{ {
"command": "REGEX_MOVE_TO_COL", "command": "REGEX_MOVE_TO_COL",
"with_input_iteration": list(REPRODUCTION.keys()), # Moves matching group {{% 1 %}} to "to" "with_input_iteration": list(REPRODUCTION.keys()), # Moves matching group {{% 1 %}} to "to"
"match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", "match": r"^.*({{% 0 %}}),?(?:.*+)*$",
"to": "Reproduktionsstatus" "to": "Reproduktionsstatus"
}, },
{ {
"command": "REGEX_MOVE_TO_COL", "command": "REGEX_MOVE_TO_COL",
"with_input_iteration": list(AGE.keys()), # Moves matching group {{% 1 %}} to "to" "with_input_iteration": list(AGE.keys()), # Moves matching group {{% 1 %}} to "to"
"match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", "match": r"^.*({{% 0 %}}),?(?:.*+)*$",
"to": "Alter" "to": "Alter"
},
{
# Special case ma -> Geschlecht a | Alter a
"command": "REGEX_MOVE_TO_COL",
"match": r"^(?:[^ ]* +)*m(a),?(?: .*+)*$",
"to": "Alter"
}], }],
("Ringnummer",): { ("Ringnummer",): {
"command": "REGEX_EDIT_COL", "command": "REGEX_EDIT_COL",
@ -59,12 +53,18 @@ COL_INSTRUCTIONS = {
"map": SPICIES, "map": SPICIES,
"reqire_full_match": True "reqire_full_match": True
}, },
("Ort",): { ("Ort",): [
{
"command": "FIND_AND_REPLACE",
"map": CATCHED_BY
},
{
"command": "REGEX_MOVE_TO_COL", "command": "REGEX_MOVE_TO_COL",
"with_input_iteration": CATCHED_BY, # Moves matching group {{% 1 %}} to "to" "with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to"
"match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$", "match": r"^.*({{% 0 %}}),?(?:.*+)*$",
"to": "Fangart" "to": "Fangart"
} }
]
} }

View File

@ -4,5 +4,5 @@ from dataclasses import dataclass
@dataclass @dataclass
class Entry: class Entry:
value: str|int|float|bool|None value: str|int|float|bool|None
bg_color: tuple[str, str, str] bg_color: tuple[str, str, str] = (255,255,255)
fg_color: tuple[str, str, str] fg_color: tuple[str, str, str] = (255,255,255)

View File

@ -1,4 +1,4 @@
from fledermaus_formatter.table_handler.Entry import Entry
class Copy: class Copy:
def __init__(self, source: str, target: str, replace = False): 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): def execute_on_row(self, row=dict[str, str], source_col=None):
return { return {
**({} if not self.replace else {self.source_col: ""}), **({} if not self.replace else {self.source_col: Entry(value="")}),
self.target: row[self.source].value self.target: Entry(row[self.source].value, bg_color=row[self.source].bg_color, fg_color=row[self.source].fg_color)
} }

View File

@ -1,10 +1,11 @@
import regex import regex
class RegexEditCol: 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.match = match
self.replace_with = replace_with self.replace_with = replace_with
self.matching_group_rearange = matching_group_rearange self.matching_group_rearange = matching_group_rearange
self.match_none = match_none
def _reorder(self, value: str): def _reorder(self, value: str):
matches = regex.match(self.match, value) matches = regex.match(self.match, value)
@ -18,7 +19,9 @@ class RegexEditCol:
def execute_on_cell(self, entry) -> str: def execute_on_cell(self, entry) -> str:
value = entry.value value = entry.value
if value is None: if value is None:
return value if self.match_none:
entry.value = self.replace_with
return entry
if self.matching_group_rearange: if self.matching_group_rearange:
entry.value = self._reorder(value) entry.value = self._reorder(value)

View File

@ -108,7 +108,7 @@ class TableSerializer:
res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration")) \ res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration")) \
.execute_on_row(in_place_working_row, source_cell) .execute_on_row(in_place_working_row, source_cell)
case "REGEX_EDIT_COL": 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]) .execute_on_cell(in_place_working_row[source_cell])
case "REGEX_GROUP_VALUEBASED_CHOOS": case "REGEX_GROUP_VALUEBASED_CHOOS":
res = RegexGroupValuebasedChoose(instruct["match"], instruct["highest"])\ res = RegexGroupValuebasedChoose(instruct["match"], instruct["highest"])\

Binary file not shown.

Binary file not shown.