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 = {
("Art",): {
"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",
"with_input_iteration": CATCHED_BY, # Moves matching group {{% 0 %}} to "to"
"match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$",
"with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to"
"match": r"^.*({{% 0 %}}),?(?:.*+)*$",
"to": "Fangart"
},
("Anzahl",): {
}
],
("Anzahl",): [{
"command": "REGEX_EDIT_COL",
"match": r"^ *$",
"replace_with": "1"
"replace_with": "1",
"match_none": True
},
("Anzahl",): {
{
"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",

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 = {
"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

View File

@ -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",): {
("Ort",): [
{
"command": "FIND_AND_REPLACE",
"map": CATCHED_BY
},
{
"command": "REGEX_MOVE_TO_COL",
"with_input_iteration": CATCHED_BY, # Moves matching group {{% 1 %}} to "to"
"match": r"^(?:[^ ]* +)*({{% 0 %}}),?(?: .*+)*$",
"with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to"
"match": r"^.*({{% 0 %}}),?(?:.*+)*$",
"to": "Fangart"
}
]
}

View File

@ -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]
bg_color: tuple[str, str, str] = (255,255,255)
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:
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)
}

View File

@ -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)

View File

@ -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"])\

Binary file not shown.

Binary file not shown.