|
1 | 1 | """ |
2 | 2 | This module contains a class to store _all_ kinds of content evaluation results. |
3 | 3 | """ |
4 | | -from itertools import product |
| 4 | +from itertools import combinations, product |
5 | 5 | from typing import Dict, List, Optional |
6 | 6 | from uuid import UUID |
7 | 7 |
|
@@ -48,7 +48,7 @@ class ContentEvaluationResultSchema(Schema): |
48 | 48 | requirement_constraints = fields.Dict( |
49 | 49 | keys=fields.String(allow_none=False), values=fields.String(allow_none=True), required=True |
50 | 50 | ) |
51 | | - id = fields.UUID(required=False, dump_default=False) |
| 51 | + id = fields.UUID(required=False, dump_default=False, missing=None) |
52 | 52 |
|
53 | 53 | @post_load |
54 | 54 | def deserialize(self, data, **kwargs) -> ContentEvaluationResult: |
@@ -113,23 +113,44 @@ def generate_possible_content_evaluation_results(self) -> List[ContentEvaluation |
113 | 113 | messages, resolving packages. |
114 | 114 | """ |
115 | 115 | 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. |
121 | 144 | result = ContentEvaluationResult( |
122 | 145 | 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 | | - }, |
126 | 146 | 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" |
130 | 150 | }, |
| 151 | + requirement_constraints={rc_kvp[0]: rc_kvp[1] for rc_kvp in fc_rc_tuple[1] if rc_kvp[0] != "rc_dummy"}, |
131 | 152 | ) |
132 | | - result.append(result) |
| 153 | + results.append(result) |
133 | 154 | return results |
134 | 155 |
|
135 | 156 |
|
|
0 commit comments