@@ -440,47 +440,38 @@ def _ParseSegmentAggregators(self):
440440 self ._segmentAggregators [attName ] = funcName
441441 self ._nodeAggregators [attName ] = funcName
442442
443- def fix_key_end (dictionary , end_sequency ):
444- to_change = []
445- for key in six .iterkeys (dictionary ):
446- if key .endswith (end_sequency ):
447- to_change .append (key )
448- for key in to_change :
449- newKey = key .replace (end_sequency , "" )
450- val = dictionary .pop (key )
451- dictionary [newKey ] = val
443+ for key in list (six .iterkeys (self ._linkAggregators )):
444+ if key .endswith ("_l" ):
445+ newKey = key .replace ("_l" , "" )
446+ val = self ._linkAggregators .pop (key )
447+ self ._linkAggregators [newKey ] = val
448+
449+ for key in list (six .iterkeys (self ._segmentAggregators )):
450+ if key .endswith ("_s" ):
451+ newKey = key .replace ("_s" , "" )
452+ val = self ._segmentAggregators .pop (key )
453+ self ._segmentAggregators [newKey ] = val
454+
455+ for key in list (six .iterkeys (self ._nodeAggregators )):
456+ if key .endswith ("_n" ):
457+ newKey = key .replace ("_n" , "" )
458+ val = self ._nodeAggregators .pop (key )
459+ self ._nodeAggregators [newKey ] = val
460+
461+ for att , funcName in list (six .iteritems (self ._linkAggregators )):
462+ if funcName == 'avg_by_length' :
463+ self ._linkAggregators [att ] = self .AVERAGE_BY_LENGTH_LINKS
464+ else :
465+ self ._linkAggregators [att ] = _editing .NAMED_AGGREGATORS [funcName ]
452466
453- fix_key_end (self ._linkAggregators , "_l" )
454- fix_key_end (self ._segmentAggregators , "_s" )
455- fix_key_end (self ._nodeAggregators , "_n" )
467+ for att , funcName in list (six .iteritems (self ._segmentAggregators )):
468+ if funcName == 'avg_by_length' :
469+ self ._segmentAggregators [att ] = self .AVERAGE_BY_LENGTH_SEGMENTS
470+ else :
471+ self ._segmentAggregators [att ] = _editing .NAMED_AGGREGATORS [funcName ]
456472
457- def assign_function (dictionary , func_name , func_type ):
458- to_change = []
459- for att , funcName in six .iteritems (dictionary ):
460- if funcName == func_name :
461- to_change .append ((att , func_type ))
462- else :
463- try :
464- to_change .append ((att , _editing .NAMED_AGGREGATORS [funcName ]))
465- except KeyError as ke :
466- print ("Error assigning function: %s from _editing" % funcName )
467- print (dictionary )
468- raise
469-
470-
471- for key , to_assign in to_change :
472- try :
473- dictionary [key ] = to_assign
474- except KeyError as ke :
475- print ("Error assigning function: %s" % key )
476- print (dictionary )
477- raise
478-
479-
480- assign_function (self ._linkAggregators , 'avg_by_length' , self .AVERAGE_BY_LENGTH_LINKS )
481- assign_function (self ._segmentAggregators , 'avg_by_length' , self .AVERAGE_BY_LENGTH_LINKS )
482- # This one should only set the func type to the _editing.NAMED_AGGREGATORS.
483- assign_function (self ._nodeAggregators , None , None )
473+ for att , funcName in list (six .iteritems (self ._nodeAggregators )):
474+ self ._nodeAggregators [att ] = _editing .NAMED_AGGREGATORS [funcName ]
484475
485476 def _GetCandidateNodes (self , network ):
486477
0 commit comments