generated from MinBZK/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a4824b
commit db65852
Showing
12 changed files
with
321 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,57 @@ | ||
import logging | ||
|
||
from amt.schema.measure import MeasureTask | ||
from amt.schema.requirement import RequirementTask | ||
from amt.schema.requirement import Requirement, RequirementTask | ||
from amt.schema.system_card import AiActProfile | ||
from amt.services.measures import create_measures_service | ||
from amt.services.requirements import create_requirements_service | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_requirements(ai_act_profile: AiActProfile) -> list[RequirementTask]: | ||
requirements: list[RequirementTask] = [] | ||
def is_requirement_applicable(requirement: Requirement, ai_act_profile: AiActProfile) -> bool: | ||
if requirement.always_applicable == 1: | ||
return True | ||
|
||
return requirements | ||
# We can assume the ai_act_profile field always is of length 1. | ||
requirement_profile = requirement.ai_act_profile[0] | ||
comparison_attrs = ["type", "risk_category", "type", "open_source", "systemic_risk", "transparency_obligations"] | ||
|
||
for attr in comparison_attrs: | ||
requirement_attr_values = getattr(requirement_profile, attr, []) | ||
|
||
def get_requirements_and_measures( | ||
if not requirement_attr_values: | ||
continue | ||
|
||
# In the system card the field role has values "gebruiksverantwoordelijke", "aanbieder" and | ||
# "gebruiksverantwoordelijke + aanbieder", so we need to split the latter into a list of two | ||
# strings. | ||
raw_input_value = getattr(ai_act_profile, attr) | ||
input_value = {raw_input_value} if attr != "role" else {s.strip() for s in raw_input_value.split("+")} | ||
|
||
if not input_value & {attr_value.value for attr_value in requirement_attr_values}: | ||
return False | ||
|
||
return True | ||
|
||
|
||
async def get_requirements_and_measures( | ||
ai_act_profile: AiActProfile, | ||
) -> tuple[ | ||
list[RequirementTask], | ||
list[MeasureTask], | ||
]: | ||
# TODO (Robbert): the body of this method will be added later (another ticket) | ||
measure_card: list[MeasureTask] = [] | ||
requirements_card: list[RequirementTask] = [] | ||
|
||
return requirements_card, measure_card | ||
) -> tuple[list[RequirementTask], list[MeasureTask]]: | ||
requirements_service = create_requirements_service() | ||
measure_service = create_measures_service() | ||
all_requirements = await requirements_service.fetch_requirements() | ||
|
||
applicable_requirements: list[RequirementTask] = [] | ||
applicable_measures: dict[str, MeasureTask] = {} | ||
|
||
for requirement in all_requirements: | ||
if is_requirement_applicable(requirement, ai_act_profile): | ||
applicable_requirements.append(RequirementTask(urn=requirement.urn, version=requirement.schema_version)) | ||
|
||
for measure_urn in requirement.links: | ||
if measure_urn not in applicable_measures: | ||
measure = await measure_service.fetch_measures(measure_urn) | ||
applicable_measures[measure_urn] = MeasureTask(urn=measure_urn, version=measure[0].schema_version) | ||
|
||
return applicable_requirements, [*applicable_measures.values()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.