Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
the feature
  • Loading branch information
hf-kklein committed Nov 27, 2021
1 parent 09429d6 commit 2891432
Show file tree
Hide file tree
Showing 4 changed files with 4,082 additions and 18 deletions.
49 changes: 35 additions & 14 deletions src/ahbicht/content_evaluation/content_evaluation_result.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This module contains a class to store _all_ kinds of content evaluation results.
"""
from itertools import product
from itertools import combinations, product
from typing import Dict, List, Optional
from uuid import UUID

Expand Down Expand Up @@ -48,7 +48,7 @@ class ContentEvaluationResultSchema(Schema):
requirement_constraints = fields.Dict(
keys=fields.String(allow_none=False), values=fields.String(allow_none=True), required=True
)
id = fields.UUID(required=False, dump_default=False)
id = fields.UUID(required=False, dump_default=False, missing=None)

@post_load
def deserialize(self, data, **kwargs) -> ContentEvaluationResult:
Expand Down Expand Up @@ -113,23 +113,44 @@ def generate_possible_content_evaluation_results(self) -> List[ContentEvaluation
messages, resolving packages.
"""
results: List[ContentEvaluationResult] = []
for rcfc_tuple in product(
[x for x in product(["dummy"] + self.requirement_constraint_keys, ConditionFulfilledValue)],
[x for x in product(["dummy"] + self.format_constraint_keys, [True, False])],
):
# we need the dummys to run into this loop even if one of either fc_keys or rc_keys is empty
if len(self.format_constraint_keys) == 0 and len(self.requirement_constraint_keys) == 0:
return results
# for easier debugging below, replace the generators "(" with a materialized lists "["
if len(self.format_constraint_keys) > 0:
possible_fcs = (
z
for z in combinations(
product(self.format_constraint_keys, [True, False]), len(self.format_constraint_keys)
)
if len({y[0] for y in z}) == len(self.format_constraint_keys)
)
else:
possible_fcs = [(("fc_dummy", True),)] # type:ignore[assignment]

if len(self.requirement_constraint_keys) > 0:
possible_rcs = (
z
for z in combinations(
product(self.requirement_constraint_keys, ConditionFulfilledValue),
len(self.requirement_constraint_keys),
)
if len({y[0] for y in z}) == len(self.requirement_constraint_keys)
)
else:
possible_rcs = [(("rc_dummy", ConditionFulfilledValue.NEUTRAL),)] # type:ignore[assignment]
for fc_rc_tuple in product(possible_fcs, possible_rcs):
# This product would have length 0 if one of the "factors" had length 0.
# In order to prevent 'results' to be empty if either the RC or FC list is empty, we added the the 'dummy's.
result = ContentEvaluationResult(
hints={hint_key: f"Hinweis {hint_key}" for hint_key in self.hint_keys},
requirement_constraints={
rc_tuple[0][0]: rc_tuple[1] for rc_tuple in rcfc_tuple[0] if rc_tuple[0] != "dummy"
},
format_constraints={
fc_tuple[0]: EvaluatedFormatConstraint(format_constraint_fulfilled=fc_tuple[1])
for fc_tuple in rcfc_tuple[1]
if fc_tuple[0] != "dummy"
fc_kvp[0]: EvaluatedFormatConstraint(format_constraint_fulfilled=fc_kvp[1])
for fc_kvp in fc_rc_tuple[0]
if fc_kvp[0] != "fc_dummy"
},
requirement_constraints={rc_kvp[0]: rc_kvp[1] for rc_kvp in fc_rc_tuple[1] if rc_kvp[0] != "rc_dummy"},
)
result.append(result)
results.append(result)
return results


Expand Down
Loading

0 comments on commit 2891432

Please sign in to comment.