Commit 90706ea4 authored by Nicolas Dumazet's avatar Nicolas Dumazet

getAggregatedAmountList: stack up filters and walk only once the candidates

Pile up a list of filters to apply, and filter the transformation_line_list
only once, instead of walking the list for each filter.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31475 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1ea3b431
...@@ -250,6 +250,7 @@ class Transformation(XMLObject, Predicate, Variated): ...@@ -250,6 +250,7 @@ class Transformation(XMLObject, Predicate, Variated):
# At this moment, we only consider 1 dependency # At this moment, we only consider 1 dependency
template_transformation_list = self.getSpecialiseValueList() template_transformation_list = self.getSpecialiseValueList()
result = AggregatedAmountList() result = AggregatedAmountList()
# Browse all involved transformations and create one line per # Browse all involved transformations and create one line per
# line of transformation # line of transformation
# Currently, we do not consider abstractions, we just add # Currently, we do not consider abstractions, we just add
...@@ -257,31 +258,49 @@ class Transformation(XMLObject, Predicate, Variated): ...@@ -257,31 +258,49 @@ class Transformation(XMLObject, Predicate, Variated):
transformation_line_list = [] transformation_line_list = []
for transformation in ([self]+template_transformation_list): for transformation in ([self]+template_transformation_list):
transformation_line_list.extend(transformation.objectValues()) transformation_line_list.extend(transformation.objectValues())
# A list of functions taking a transformation_line as sole argument
# and returning True iif the line should be kept in the result
filter_list = []
# Get only lines related to a precise trade_phase # Get only lines related to a precise trade_phase
if trade_phase_list is not None: if trade_phase_list is not None:
transformation_line_list = filter( def trade_phase_filter(line):
lambda line: line.getTradePhase() in trade_phase_list, return line.getTradePhase() in trade_phase_list
transformation_line_list)
filter_list.append(trade_phase_filter)
# Get only lines related to a precise industrial_phase # Get only lines related to a precise industrial_phase
if ind_phase_url_list is not None: if ind_phase_url_list is not None:
LOG("Transformation", WARNING, "ind_phase_list is obsolete") LOG("Transformation", WARNING, "ind_phase_list is obsolete")
new_transf_line_list = [] def industrial_phase_filter(line):
for line in transformation_line_list:
ind_ph = line.getIndustrialPhaseValue() ind_ph = line.getIndustrialPhaseValue()
if ind_ph is not None: if ind_ph is not None:
if ind_ph.getRelativeUrl() in ind_phase_url_list: return ind_ph.getRelativeUrl() in ind_phase_url_list
new_transf_line_list.append(line) return False
transformation_line_list = new_transf_line_list
filter_list.append(industrial_phase_filter)
# Filter lines with resource we do not want to see # Filter lines with resource we do not want to see
if rejected_resource_uid_list is not None: if rejected_resource_uid_list is not None:
transformation_line_list = filter( def rejected_uid_filter(line):
lambda x: x.getResourceUid() not in\ return line.getResourceUid() not in rejected_resource_uid_list
rejected_resource_uid_list,
transformation_line_list) filter_list.append(rejected_uid_filter)
def line_is_included(line):
# XXX > 2.5 : all(f(line) for f in filter_list)
for filterr in filter_list:
if not filterr(line):
return False
return True
for transformation_line in transformation_line_list: for transformation_line in transformation_line_list:
# Browse each transformed or assorted resource of the current # Browse each transformed or assorted resource of the current
# transformation # transformation
if line_is_included(transformation_line):
result.extend(transformation_line.getAggregatedAmountList(context)) result.extend(transformation_line.getAggregatedAmountList(context))
if context_quantity: if context_quantity:
result.multiplyQuantity(context=context) result.multiplyQuantity(context=context)
return result return result
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment