migrage: Adjust for Weinland

This commit is contained in:
2025-02-20 14:57:17 +01:00
parent 0a1cce63af
commit 351228bf30
3 changed files with 338 additions and 2 deletions

153
tools/wgw-fb-old.py Executable file
View File

@ -0,0 +1,153 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import TypeAlias, Optional
import argparse
import re
import datetime
import xlrd
ExcelRow: TypeAlias = tuple[str, str, int, int, str, float]
ExcelTab: TypeAlias = tuple[str, int, str, str, datetime.date, str, list[ExcelRow]]
AreaCom: TypeAlias = tuple[int, int, str, Optional[str], int, int, str, Optional[int], Optional[int], Optional[int], Optional[str]]
FBNR: int = 0
def extract_table(sheet: xlrd.sheet.Sheet, base_row: int, base_col: int) -> Optional[ExcelTab]:
try:
mgnr = int(sheet.cell_value(base_row - 4, base_col + 1))
loc = sheet.cell_value(base_row - 6, base_col + 1)
name = sheet.cell_value(base_row - 8, base_col + 1)
except ValueError:
print(f'sheet {sheet.name} skipped!')
return None
date = None
bewirt = None
rows: list[ExcelRow] = []
for row_nr in range(base_row + 1, sheet.nrows):
row = sheet.row_slice(row_nr, base_col, base_col + 6)
if row[0].value == 'Gesamtsumme' or (row[0].value == 'Übertrag' and row_nr - base_row > 2):
val = sheet.cell_value(row_nr + 5, base_col + 3)
d = re.sub(r'\. ', '.', val.split(',')[-1].strip()).replace(' ', '.').replace('..', '.')
if d.endswith('204'):
d = d.replace('204', '2014')
if d.startswith(''):
d = d.replace('', '1.1')
if d != '':
date = datetime.datetime.strptime(d, '%d.%m.%Y').date()
else:
date = datetime.date(2023, 1, 1)
try:
bewirt = sheet.cell_value(row_nr + 20, base_col)
except:
bewirt = ''
break
elif row[0].value == 'Übertrag':
continue
rows.append((
str(row[0].value) if row[0].value != '' else None,
str(row[1].value if row[1].ctype == xlrd.XL_CELL_TEXT else
re.sub(r'\.0$', '', str(row[1].value))) if row[1].value != '' else None,
int(row[2].value) if row[2].value != '' else None,
int(row[3].value) if row[3].value != '' else None,
str(row[4].value) if row[4].value != '' else None,
round(float(row[5].value), 2) if row[5].value != '' else None
))
return sheet.name, mgnr, name, loc, date, bewirt, rows
def parse_part(tabs: list[ExcelTab]) -> list[AreaCom]:
global FBNR
area_coms = []
last_gst, last_rd = None, None
first = True
for tab in tabs:
mgnr = tab[1]
if not first:
print('-' * 148)
first = False
for row in tab[-1]:
if row in ((None, None, None, None, None, None),
(None, None, None, None, None, 0.0),
(None, None, None, 0, None, 0.0),
(None, None, 0, 0, None, 0.0)):
continue
if row[2] == '':
last_rd = row[0] or last_rd
last_gst = str(row[1])
rd = row[0] or last_rd
if 'äüßere' in rd:
rd = rd.replace('äüßere', 'Äußere')
gst = row[1]
if last_gst:
gst = last_gst + ', ' + gst
last_gst = None
if gst is not None:
gst = re.sub(r'\s+', ' ', gst.replace(' /', '/').replace('/ ', '/').replace(',', ', ')).strip()
total = row[2]
geb = row[3]
sortid = row[4]
kg = row[5]
if kg is not None:
kg = round(kg, 2)
perc = round(kg / geb, 2) if geb != 0 and geb is not None else None
print(f'{mgnr:4} {rd:24} {gst or "":64} {total or "":8} {geb or "":8} {sortid or "":5} {kg or "":8} {perc or "-":3} {'KIP' if 'KIP' in tab[5] else tab[5]}')
last_rd = rd
sortid = sortid.strip() if sortid is not None else None
if sortid is None:
continue
elif sortid == 'MTH':
sortid = 'MT' # Müller Thurgau
elif sortid == 'GMU':
sortid = 'GL' # Goldmuskateller?
elif ',' in sortid:
sortid = sortid[:2]
gsts = re.split(r' ', gst) if gst is not None else []
kgnr = 0
try:
if int(gsts[0]) in (6128, 6102, 6110):
kgnr = int(gsts[0])
gst = ' '.join(gsts[1:]).strip(',').strip()
except ValueError:
pass
except IndexError:
pass
FBNR += 1
# TODO kgnr, rdnr
area_coms.append((FBNR, mgnr, sortid, 'KIP' if 'KIP' in tab[5] else None, geb, kgnr, gst, None, tab[4].year, None, None))
print('=' * 148)
return area_coms
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('file')
args = parser.parse_args()
area_coms = []
wb = xlrd.open_workbook(args.file)
for name in wb.sheet_names():
if name == 'Vorlage':
continue
sheet = wb.sheet_by_name(name)
tabs = []
for row, cell_1 in enumerate(sheet.col(0)):
if cell_1.value == 'Ried':
for col, cell_2 in enumerate(sheet.row(row)):
if cell_2.value == 'Ried':
tab = extract_table(sheet, 12, col)
if tab:
tabs.append(tab)
area_coms += parse_part(tabs)
wb.unload_sheet(name)
for a in area_coms:
print(f'{a[0]:4} {a[1]:4} {a[2]:2} {a[3] or "":3} {a[4] or "":6} {a[5]:05} {a[6] or "":40} {a[7] or "":2} {a[8]:4} {a[9] or "":4} {a[10]}')
if __name__ == '__main__':
main()

175
tools/wgw-fb.py Executable file
View File

@ -0,0 +1,175 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import openpyxl
KG_MAP = {
'Dobermannsdorf': 6104,
'Gaiselberg': 6109,
'Gösting': 6110,
'Groß Inzersdorf': 6113,
'Groß Krut': 15111,
'Hausbrunn': 15114,
'Hauskirchen': 6111,
'Herrnbaumgarten': 15115,
'Jedenspeigen': 6114,
'Obersiebenbrunn': 6217,
'Loidesthal': 6115,
'Zistersdorf': 6128,
'Maustrenk': 6116,
'Niederabsdorf': 6101,
'Obersulz': 6125,
'Palterndorf': 6119,
'Prinzendorf': 6120,
'Sierndorf': 6123,
'Windisch-Baumgarten': 6102,
}
RD_MAP = {
('Schilling', 6117): 1,
('Kreiten', 6103): 1,
('Feldweingarten', 6103): 2,
('Hausweingarten', 6103): 3,
('Sommerberg', 6103): 4,
('Schilling', 6104): 1,
('Mittlere Bloten', 6104): 2,
('Schotter', 6104): 3,
('Obere Bloten', 6104): 4,
('Oberer Sand', 6104): 5,
('Kirchenried', 6106): 1,
('Steigewanten', 6107): 1,
('Loidesthaler', 6109): 1,
('Tillern', 6109): 2,
('Hintauskreuten', 6109): 3,
('Spitz', 6109): 4,
('Saatzen', 6109): 5,
('Hausberg', 6109): 6,
('Kreiten', 6109): 7,
('Götzenthaler', 6109): 8,
('Kreuten alt', 6109): 9,
('Steinberg', 6110): 1,
('Steinberg Wald', 6110): 2,
('Ebenacker', 6110): 3,
('Junge Reinberger', 6110): 4,
('Flederwisch', 6110): 5,
('Hageln', 6110): 6,
('Alte Kreuten', 6113): 1,
('Bockstaller', 6113): 2,
('Huberischer', 6113): 3,
('Kreiten', 6113): 4,
('Junge Hofäcker', 6113): 5,
('Sommerleiten', 6113): 6,
('Winterleiten', 6113): 7,
('Satz', 6113): 8,
('Hofacker Frohner', 6113): 9,
('Goldberg', 6113): 10,
('Hofacker', 6113): 11,
('Dorfackerl', 6113): 12,
('Altenberg', 6113): 13,
('Weinberg', 6113): 14,
('Zulus', 6113): 15,
('Anger', 6102): 1,
('Winterleiten', 6102): 2,
('Steinstück', 6102): 3,
('Hirschfeld', 6111): 1,
('Kirchberg2', 6111): 2,
('alter Hausberg', 6111): 3,
('Kirchberg oben', 6111): 4,
('Kirchberg unten', 6111): 5,
('Hausweingarten', 6111): 6,
('äußere Kirchenried', 6114): 1,
('Adamsberg', 6114): 2,
('Gießhübl', 6114): 3,
('Hundsberg', 6114): 4,
('Kirchenried', 6114): 5,
('Neusatz', 6114): 6,
('Ebner', 6114): 7,
('Ober der Straße', 6114): 8,
}
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('file')
args = parser.parse_args()
area_coms = []
wb = openpyxl.load_workbook(args.file)
sheet = wb.worksheets[0]
mgnr, ort, ried, gstnr, kgnr = None, None, None, None, None
for row in sheet.rows:
if row[0].value is not None:
mgnr, ort, ried, gstnr, kgnr = row[0].value, row[4].value, None, None, None
if mgnr is None:
continue
rd, gst, total_area, area, sortid = row[5].value, row[6].value, row[7].value, row[8].value, row[9].value
if rd is not None:
if type(rd) == int:
kgnr = rd
else:
ried = rd
gstnr = f'{gstnr}, {gst}' if gstnr else gst
if sortid is not None:
sortid = sortid.strip()
if sortid == 'MTH':
sortid = 'MT' # Müller Thurgau
elif sortid == 'GMU':
sortid = 'MU' # Muskateller?
if area is None:
gstnr = None
continue
kgnr = kgnr or KG_MAP[ort]
gstnr = (str(gstnr).replace(' / ', '/').replace(' ,', ', ').replace(',', ', ')
.replace(' ', ' ').replace(', ,', ',').replace(' - ', '-').replace('.', ', '))
if gstnr == 'None':
gstnr = '-'
if gstnr.startswith('06') or gstnr.startswith('6128,') or gstnr.startswith('6110,'):
kgnr, gstnr = gstnr.split(' ', 1)
kgnr = int(kgnr.strip(','))
gstnr = gstnr.strip(',').strip()
area_coms.append((mgnr, kgnr, ried, gstnr, area, sortid))
gstnr = None
continue
print('\nINSERT INTO area_commitment_type (vtrgid, sortid, attrid, disc, min_kg_per_ha, penalty_per_kg, penalty_amount, penalty_none) VALUES')
first = True
for t in set(a[5] for a in area_coms):
if not first:
print(',')
print(f"('{t}', '{t}', NULL, NULL, NULL, NULL, NULL, NULL)", end='')
first = False
print(';\n')
print('\nINSERT INTO wb_rd (kgnr, rdnr, name) VALUES')
first = True
for n, k in set((a[2], a[1]) for a in area_coms):
try:
rdnr = RD_MAP[(n, k)]
except KeyError:
if not first:
print(',')
keys = [b for (_, a), b in RD_MAP.items() if a == k]
if len(keys) == 0:
rdnr = 1
else:
rdnr = max(keys) + 1
RD_MAP[(n, k)] = rdnr
print(f"({k:5}, {rdnr:3}, '{n}')", end='')
first = False
print(';\n')
fbnr = 0
print('\nINSERT INTO area_commitment (fbnr, mgnr, vtrgid, cultid, area, year_from, year_to, kgnr, rdnr, gstnr, comment) VALUES')
for a in area_coms:
fbnr += 1
if fbnr > 1:
print(',')
rdnr = RD_MAP[(a[2], a[1])]
print(f"({fbnr:3}, {a[0]:3}, '{a[5]}', 'KIP', {a[4]:6}, 2025, NULL, {a[1]:5}, {rdnr:2}, '{a[3]}', NULL)", end='')
print(';\n')
if __name__ == '__main__':
main()

View File

@ -208,6 +208,11 @@ STREET_NAMES: Dict[str, str] = {
'Erzherzogin Isabelle Straße': 'Erzherzogin-Isabelle-Straße',
'E. Penzig Franz Straße': 'Edgar-Penzing-Franz-Straße',
'Hernsteinerstr Straße': 'Hernsteiner Straße',
'Windisch Baumgarten': 'Windisch-Baumgarten',
'Gr.Inzersdorf': 'Groß-Inzersdorf',
'Großinzersdorf': 'Groß-Inzersdorf',
'Kaiser Franz Josef Straße': 'Kaiser-Franz-Josef-Straße',
'Josef Zuntichgasse': 'Josef-Zuntich-Gasse',
}
@ -1151,12 +1156,15 @@ def migrate_members(in_dir: str, out_dir: str) -> None:
continue
pred = m['MGNR-Vorgänger'] if m['MGNR-Vorgänger'] in mgnrs else None
comment = m['Anmerkung']
if str(comment).strip().strip('0') == str(bnr).strip().strip('0'):
comment = None
f_m.row(
mgnr, pred, family_name, prefix, given_name, middle_names, suffix, None,
m['Geburtsjahr'], m['Eintrittsdatum'], m['Austrittsdatum'], m['Geschäftsanteile1'] or 0,
m['BHKontonummer'], zwstid, bnr, ustid_nr,
m['Volllieferant'] or False, m['Buchführend'] or False, False, funktionaer, active, deceased,
iban, bic, AUSTRIA, postal_dest, address or '-', kgnr, m['Anmerkung']
iban, bic, AUSTRIA, postal_dest, address or '-', kgnr, comment
)
phone_1: Optional[str] = m['Telefon']
@ -2002,7 +2010,7 @@ def migrate_parameters(in_dir: str, out_dir: str) -> None:
'CLIENT_NAME_TOKEN': tokens[0],
'CLIENT_NAME_SHORT': tokens[1],
'CLIENT_NAME': name,
'CLIENT_NAME_SUFFIX': None,
'CLIENT_NAME_SUFFIX': 'mit dem Sitz in Groß-Inzersdorf' if 'Weinland' in name else None,
'CLIENT_NAME_TYPE': types[suffix],
'CLIENT_PLZ': PARAMETERS['MANDANTENPLZ'],
'CLIENT_ORT': ort,