Skip to content

Commit 2891432

Browse files
committed
wip
the feature
1 parent 09429d6 commit 2891432

File tree

4 files changed

+4082
-18
lines changed

4 files changed

+4082
-18
lines changed

src/ahbicht/content_evaluation/content_evaluation_result.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
This module contains a class to store _all_ kinds of content evaluation results.
33
"""
4-
from itertools import product
4+
from itertools import combinations, product
55
from typing import Dict, List, Optional
66
from uuid import UUID
77

@@ -48,7 +48,7 @@ class ContentEvaluationResultSchema(Schema):
4848
requirement_constraints = fields.Dict(
4949
keys=fields.String(allow_none=False), values=fields.String(allow_none=True), required=True
5050
)
51-
id = fields.UUID(required=False, dump_default=False)
51+
id = fields.UUID(required=False, dump_default=False, missing=None)
5252

5353
@post_load
5454
def deserialize(self, data, **kwargs) -> ContentEvaluationResult:
@@ -113,23 +113,44 @@ def generate_possible_content_evaluation_results(self) -> List[ContentEvaluation
113113
messages, resolving packages.
114114
"""
115115
results: List[ContentEvaluationResult] = []
116-
for rcfc_tuple in product(
117-
[x for x in product(["dummy"] + self.requirement_constraint_keys, ConditionFulfilledValue)],
118-
[x for x in product(["dummy"] + self.format_constraint_keys, [True, False])],
119-
):
120-
# we need the dummys to run into this loop even if one of either fc_keys or rc_keys is empty
116+
if len(self.format_constraint_keys) == 0 and len(self.requirement_constraint_keys) == 0:
117+
return results
118+
# for easier debugging below, replace the generators "(" with a materialized lists "["
119+
if len(self.format_constraint_keys) > 0:
120+
possible_fcs = (
121+
z
122+
for z in combinations(
123+
product(self.format_constraint_keys, [True, False]), len(self.format_constraint_keys)
124+
)
125+
if len({y[0] for y in z}) == len(self.format_constraint_keys)
126+
)
127+
else:
128+
possible_fcs = [(("fc_dummy", True),)] # type:ignore[assignment]
129+
130+
if len(self.requirement_constraint_keys) > 0:
131+
possible_rcs = (
132+
z
133+
for z in combinations(
134+
product(self.requirement_constraint_keys, ConditionFulfilledValue),
135+
len(self.requirement_constraint_keys),
136+
)
137+
if len({y[0] for y in z}) == len(self.requirement_constraint_keys)
138+
)
139+
else:
140+
possible_rcs = [(("rc_dummy", ConditionFulfilledValue.NEUTRAL),)] # type:ignore[assignment]
141+
for fc_rc_tuple in product(possible_fcs, possible_rcs):
142+
# This product would have length 0 if one of the "factors" had length 0.
143+
# In order to prevent 'results' to be empty if either the RC or FC list is empty, we added the the 'dummy's.
121144
result = ContentEvaluationResult(
122145
hints={hint_key: f"Hinweis {hint_key}" for hint_key in self.hint_keys},
123-
requirement_constraints={
124-
rc_tuple[0][0]: rc_tuple[1] for rc_tuple in rcfc_tuple[0] if rc_tuple[0] != "dummy"
125-
},
126146
format_constraints={
127-
fc_tuple[0]: EvaluatedFormatConstraint(format_constraint_fulfilled=fc_tuple[1])
128-
for fc_tuple in rcfc_tuple[1]
129-
if fc_tuple[0] != "dummy"
147+
fc_kvp[0]: EvaluatedFormatConstraint(format_constraint_fulfilled=fc_kvp[1])
148+
for fc_kvp in fc_rc_tuple[0]
149+
if fc_kvp[0] != "fc_dummy"
130150
},
151+
requirement_constraints={rc_kvp[0]: rc_kvp[1] for rc_kvp in fc_rc_tuple[1] if rc_kvp[0] != "rc_dummy"},
131152
)
132-
result.append(result)
153+
results.append(result)
133154
return results
134155

135156

0 commit comments

Comments
 (0)