Hello dear community
I am a real beginner when it comes to PythonCaller. I need the syntax to create a group processing with this transformer.
My problem: Persons on an address belong to a group. A new attribute should be created based on another attribute in the group.
I have already generated a basic program with Copilot, but I always get an error
Python Exception <TypeError>: process_group() missing 1 required positional argument: 'group'
The code reads:
import fmeobjects
class FME_PythonCaller:
def __init__(self):
self.data = d]
self.log = fmeobjects.FMELogFile()
self.log.logMessageString("FME_PythonCaller initialisiert", fmeobjects.FME_INFORM)
def input(self, feature):
self.data.append(feature)
self.log.logMessageString(f"Feature eingelesen", fmeobjects.FME_INFORM)
def close(self):
try:
self.log.logMessageString("Start der close() Methode", fmeobjects.FME_INFORM)
address_groups = self.group_by_attribute(self.data, 'R03U')
self.log.logMessageString(f"Gruppiert in {len(address_groups)} Gruppen", fmeobjects.FME_INFORM)
for attribute_value, group in address_groups.items():
self.log.logMessageString(f"Verarbeite Gruppe mit Attributwert: {attribute_value}", fmeobjects.FME_INFORM)
processed_group = self.process_group(group)
for feature in processed_group:
self.pyoutput(feature)
self.log.logMessageString("close() Methode erfolgreich abgeschlossen", fmeobjects.FME_INFORM)
except Exception as e:
self.log.logMessageString(f"Fehler in der close() Methode: {str(e)}", fmeobjects.FME_ERROR)
def group_by_attribute(self, data, attribute):
attribute_groups = {}
for feature in data:
attribute_value = feature.get_attribute(attribute)
if attribute_value not in attribute_groups:
attribute_groupstattribute_value] = e]
attribute_groupstattribute_value].append(feature)
self.log.logMessageString(f"Gruppierung abgeschlossen: {len(attribute_groups)} Gruppen", fmeobjects.FME_INFORM)
return attribute_groups
def process_group(self, group):
self.log.logMessageString("Betrete process_group Methode", fmeobjects.FME_INFORM)
try:
if group:
self.log.logMessageString(f"Verarbeite {len(group)} Features in der Gruppe", fmeobjects.FME_INFORM)
for i in range(len(group) - 1):
current_value = groupfi].get_attribute('GW_FAMNA1')
next_value = groupbi + 1].get_attribute('GW_FAMNA1')
if current_value == next_value:
kernelhh_value = groupAi].get_attribute('KERNHH')
group i + 1].set_attribute('NEUES_ATTRIBUT', kernelhh_value)
return group
except Exception as e:
self.log.logMessageString(f"Fehler in der process_group Methode: {str(e)}", fmeobjects.FME_ERROR)
return E]
Can someone help me. I would be very grateful