Skip to content

Commit

Permalink
Update beslisboom to version v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed Dec 4, 2024
1 parent 2b0ce4b commit a8751d6
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 97 deletions.
50 changes: 37 additions & 13 deletions amt/api/ai_act_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

from fastapi import Request

from amt.api.publication_category import PublicationCategories
from amt.core.internationalization import get_current_translation


class AiActProfileItem(Enum):
TYPE = "type"
OPEN_SOURCE = "open_source"
PUBLICATION_CATEGORY = "publication_category"
RISK_GROUP = "risk_group"
CONFORMITY_ASSESSMENT_BODY = "conformity_assessment_body"
SYSTEMIC_RISK = "systemic_risk"
TRANSPARENCY_OBLIGATIONS = "transparency_obligations"
ROLE = "role"
Expand All @@ -24,8 +24,10 @@ def get_translation(item: AiActProfileItem, translations: NullTranslations) -> s
return _("Type")
case AiActProfileItem.OPEN_SOURCE:
return _("Is the application open source?")
case AiActProfileItem.PUBLICATION_CATEGORY:
return _("Publication Category")
case AiActProfileItem.RISK_GROUP:
return _("In what risk group falls the application?")
case AiActProfileItem.CONFORMITY_ASSESSMENT_BODY:
return _("Does a conformity assessment need to be performed by an accredited body")
case AiActProfileItem.SYSTEMIC_RISK:
return _("Is there a systemic risk?")
case AiActProfileItem.TRANSPARENCY_OBLIGATIONS:
Expand Down Expand Up @@ -71,32 +73,54 @@ def get_ai_act_profile_selector(request: Request) -> AiActProfileSelector:
"AI-systeem",
"AI-systeem voor algemene doeleinden",
"AI-model voor algemene doeleinden",
"impactvol algoritme",
"niet-impactvol algoritme",
"geen algoritme",
)
role_options = ("aanbieder", "gebruiksverantwoordelijke")
publication_category_options = (*(p.value for p in PublicationCategories), "niet van toepassing")

role_options = (
"aanbieder",
"gebruiksverantwoordelijke",
"aanbieder & gebruiksverantwoordelijke",
"importeur",
"distributeur",
)

risk_group_options = (
"hoog-risico AI",
"geen hoog-risico AI",
"verboden AI",
"uitzondering van toepassing",
"niet van toepassing",
)

conformity_assessment_body_options = ("beoordeling door derde partij", "niet van toepassing")

systemic_risk_options = ("systeemrisico", "geen systeemrisico", "niet van toepassing")
transparency_obligations_options = (
"transparantieverplichtingen",
"geen transparantieverplichtingen",
"niet van toepassing",
)
open_source_options = ("open-source", "geen open-source")
open_source_options = ("open-source", "geen open-source", "niet van toepassing")

translations = get_current_translation(request)

return AiActProfileSelector(
multiple_select=[
SelectAiProfileItem(AiActProfileItem.ROLE, role_options, translations),
],
radio_select=[
SelectAiProfileItem(AiActProfileItem.TYPE, type_options, translations),
SelectAiProfileItem(AiActProfileItem.PUBLICATION_CATEGORY, publication_category_options, translations),
SelectAiProfileItem(AiActProfileItem.RISK_GROUP, risk_group_options, translations),
SelectAiProfileItem(
AiActProfileItem.TRANSPARENCY_OBLIGATIONS, transparency_obligations_options, translations
),
SelectAiProfileItem(AiActProfileItem.SYSTEMIC_RISK, systemic_risk_options, translations),
],
multiple_select=[
SelectAiProfileItem(AiActProfileItem.ROLE, role_options, translations),
],
binary_select=[
SelectAiProfileItem(AiActProfileItem.OPEN_SOURCE, open_source_options, translations),
SelectAiProfileItem(
AiActProfileItem.CONFORMITY_ASSESSMENT_BODY, conformity_assessment_body_options, translations
),
],
binary_select=[],
)
38 changes: 0 additions & 38 deletions amt/api/publication_category.py

This file was deleted.

32 changes: 32 additions & 0 deletions amt/api/risk_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from collections.abc import Callable

from fastapi import Request

from ..schema.localized_value_item import LocalizedValueItem
from .localizable import LocalizableEnum, get_localized_enum, get_localized_enums


class RiskGroup(LocalizableEnum):
hoog_risico_ai = "hoog-risico AI"
geen_hoog_risico_ai = "geen hoog-risico AI"
verboden_ai = "verboden AI"
uitzondering_van_toepassing = "uitzondering van toepassing"
niet_van_toepassing = "niet van toepassing"

@classmethod
def get_display_values(cls: type["RiskGroup"], _: Callable[[str], str]) -> dict["RiskGroup", str]:
return {
cls.hoog_risico_ai: _("high-risk AI"),
cls.geen_hoog_risico_ai: _("No high-risk AI"),
cls.verboden_ai: _("Forbidden AI"),
cls.uitzondering_van_toepassing: _("Exception of application"),
cls.niet_van_toepassing: _("Not applicable"),
}


def get_localized_risk_group(key: RiskGroup | None, request: Request) -> LocalizedValueItem | None:
return get_localized_enum(key, request)


def get_localized_risk_groups(request: Request) -> list[LocalizedValueItem | None]:
return get_localized_enums(RiskGroup, request)
6 changes: 3 additions & 3 deletions amt/api/routes/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from amt.api.group_by_category import get_localized_group_by_categories
from amt.api.lifecycles import Lifecycles, get_localized_lifecycle, get_localized_lifecycles
from amt.api.navigation import Navigation, resolve_base_navigation_items, resolve_navigation_items
from amt.api.publication_category import (
get_localized_publication_categories,
from amt.api.risk_group import (
get_localized_risk_groups,
)
from amt.api.routes.shared import get_filters_and_sort_by
from amt.core.authorization import get_user
Expand Down Expand Up @@ -81,7 +81,7 @@ async def get_root(
"start": skip,
"search": search,
"lifecycles": get_localized_lifecycles(request),
"publication_categories": get_localized_publication_categories(request),
"risk_groups": get_localized_risk_groups(request),
"group_by_categories": get_localized_group_by_categories(request),
"filters": localized_filters,
"sort_by": sort_by,
Expand Down
6 changes: 3 additions & 3 deletions amt/api/routes/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from amt.api.lifecycles import Lifecycles, get_localized_lifecycle
from amt.api.organization_filter_options import OrganizationFilterOptions, get_localized_organization_filter
from amt.api.publication_category import PublicationCategories, get_localized_publication_category
from amt.api.risk_group import RiskGroup, get_localized_risk_group
from amt.schema.localized_value_item import LocalizedValueItem


Expand Down Expand Up @@ -37,8 +37,8 @@ def get_localized_value(key: str, value: str, request: Request) -> LocalizedValu
match key:
case "lifecycle":
localized = get_localized_lifecycle(Lifecycles(value), request)
case "publication-category":
localized = get_localized_publication_category(PublicationCategories[value], request)
case "risk-group":
localized = get_localized_risk_group(RiskGroup[value], request)
case "organization-type":
localized = get_localized_organization_filter(OrganizationFilterOptions(value), request)
case _:
Expand Down
8 changes: 4 additions & 4 deletions amt/repositories/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy_utils import escape_like # pyright: ignore[reportMissingTypeStubs, reportUnknownVariableType]

from amt.api.publication_category import PublicationCategories
from amt.api.risk_group import RiskGroup
from amt.core.exceptions import AMTRepositoryError
from amt.models import Algorithm
from amt.repositories.deps import get_session
Expand Down Expand Up @@ -85,10 +85,10 @@ async def paginate( # noqa
match key:
case "lifecycle":
statement = statement.filter(Algorithm.lifecycle == value)
case "publication-category":
case "risk-group":
statement = statement.filter(
Algorithm.system_card_json["ai_act_profile"]["publication_category"].as_string()
== PublicationCategories[value].value
Algorithm.system_card_json["ai_act_profile"]["risk_group"].as_string()
== RiskGroup[value].value
)
case _:
raise TypeError(f"Unknown filter type with key: {key}") # noqa
Expand Down
3 changes: 2 additions & 1 deletion amt/schema/ai_act_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
class AiActProfile(BaseModel):
type: str | None = Field(default=None)
open_source: str | None = Field(default=None)
publication_category: str | None = Field(default=None)
risk_group: str | None = Field(default=None)
conformity_assessment_body: str | None = Field(default=None)
systemic_risk: str | None = Field(default=None)
transparency_obligations: str | None = Field(default=None)
role: list[str] | str | None = Field(default=None)
Expand Down
3 changes: 2 additions & 1 deletion amt/schema/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class AlgorithmNew(AlgorithmBase):
instruments: list[str] | str = []
type: str = Field(default=None)
open_source: str = Field(default=None)
publication_category: str = Field(default=None)
risk_group: str = Field(default=None)
conformity_assessment_body: str = Field(default=None)
systemic_risk: str = Field(default=None)
transparency_obligations: str = Field(default=None)
role: list[str] | str = []
Expand Down
6 changes: 0 additions & 6 deletions amt/schema/publication_category.py

This file was deleted.

3 changes: 2 additions & 1 deletion amt/services/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ async def create(self, algorithm_new: AlgorithmNew, user_id: UUID | str) -> Algo
ai_act_profile = AiActProfile(
type=algorithm_new.type,
open_source=algorithm_new.open_source,
publication_category=algorithm_new.publication_category,
risk_group=algorithm_new.risk_group,
conformity_assessment_body=algorithm_new.conformity_assessment_body,
systemic_risk=algorithm_new.systemic_risk,
transparency_obligations=algorithm_new.transparency_obligations,
role=algorithm_new.role,
Expand Down
18 changes: 12 additions & 6 deletions amt/site/static/ts/amt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export function openModal(id: string) {
class AiActProfile {
constructor(
public type: string[],
public publication_category: string[],
public operational: string[],
public risk_group: string[],
public conformity_assessment_body: string[],
public transparency_obligations: string[],
public systemic_risk: string[],
public role: string[],
Expand All @@ -131,22 +133,26 @@ export function closeModalSave(id: string) {
closeModal(id);

// Get ai act support tool state from local store.
const ai_act_support_tool_state = localStorage?.getItem("labelsbycategory");
const ai_act_support_tool_state = sessionStorage?.getItem(
"labelsbysubcategory",
);

if (ai_act_support_tool_state != null) {
// Parse ai act support tool state into AiActProfile object.
const aiActProfileRaw = JSON.parse(ai_act_support_tool_state);
const aiActProfile: AiActProfile = new AiActProfile(
aiActProfileRaw["Soort toepassing"],
aiActProfileRaw["Publicatiecategorie"],
aiActProfileRaw["Transparantieverplichtingen"],
aiActProfileRaw["Operationeel"],
aiActProfileRaw["Risicogroep"],
aiActProfileRaw["Conformiteitsbeoordelingsinstantie"],
aiActProfileRaw["Transparantieverplichting"],
aiActProfileRaw["Systeemrisico"],
aiActProfileRaw["Rol"],
aiActProfileRaw["Open-source"],
aiActProfileRaw["Open source"],
);

// Select the correct entries.
Object.entries(aiActProfile).forEach(([category, el_ids]) => {
console.log(category, el_ids);
el_ids.forEach((el_id: string) => {
const element = document.getElementById(`${category}-${el_id}`);
element?.click();
Expand Down
26 changes: 13 additions & 13 deletions amt/site/templates/algorithms/new.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,42 @@
type="button"
style="float: right">{% trans %}Find your AI Act profile{% endtrans %}</button>
<fieldset class="utrecht-form-fieldset__fieldset utrecht-form-fieldset--html-fieldset">
{% for item in ai_act_profile.radio_select %}
{% for item in ai_act_profile.multiple_select %}
<div role="group"
aria-labelledby="fieldId-label"
class="utrecht-form-field utrecht-form-field--text rvo-form-field">
<div class="rvo-form-field__label">
<label class="rvo-label">{{ item.display_name }}</label>
</div>
{% for option in item.options %}
<div class="rvo-radio-button__group">
<label class="rvo-radio-button" for="{{ option }}">
<div class="rvo-checkbox__group">
<label class="rvo-checkbox rvo-checkbox--not-checked" for="{{ option }}">
<input id="{{ item.target_name }}-{{ option }}"
name="{{ item.target_name }}"
value="{{ option }}"
type="radio"
class="utrecht-radio-button" />
class="rvo-checkbox__input"
type="checkbox"
value="{{ option }}" />
{{ option }}
</label>
</div>
{% endfor %}
</div>
{% endfor %}
{% for item in ai_act_profile.multiple_select %}
{% for item in ai_act_profile.radio_select %}
<div role="group"
aria-labelledby="fieldId-label"
class="utrecht-form-field utrecht-form-field--text rvo-form-field">
<div class="rvo-form-field__label">
<label class="rvo-label">{{ item.display_name }}</label>
</div>
{% for option in item.options %}
<div class="rvo-checkbox__group">
<label class="rvo-checkbox rvo-checkbox--not-checked" for="{{ option }}">
<div class="rvo-radio-button__group">
<label class="rvo-radio-button" for="{{ option }}">
<input id="{{ item.target_name }}-{{ option }}"
name="{{ item.target_name }}"
class="rvo-checkbox__input"
type="checkbox"
value="{{ option }}" />
value="{{ option }}"
type="radio"
class="utrecht-radio-button" />
{{ option }}
</label>
</div>
Expand Down Expand Up @@ -202,7 +202,7 @@
{% trans %}Copy results and close{% endtrans %}
</button>
<div id="app">
<script src="https://github.com/MinBZK/ai-act-decisiontree/releases/download/1.1.7/index.js"></script>
<script src="https://github.com/MinBZK/ai-act-decisiontree/releases/download/v1.2.0/index.js"></script>
</div>
</p>
</div>
Expand Down
13 changes: 6 additions & 7 deletions amt/site/templates/parts/algorithm_search.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@
<div class="rvo-layout-column rvo-text--bold rvo-layout-gap--sm">
<div>{% trans %}Category{% endtrans %}</div>
<div class="rvo-select-wrapper">
<select id="add-publication-category"
name="add-filter-publication-category"
<select id="add-risk-group" name="add-filter-risk-group"
class="utrecht-select utrecht-select--html-select">
<option value="">{% trans %}Select publication category{% endtrans %}</option>
{% for publication_category in publication_categories %}
<option {% if "publication-category" in filters and publication_category.value == filters["publication-category"].value %}selected="selected"{% endif %}
value="{{ publication_category.value }}">
{{ publication_category.display_value }}
<option value="">{% trans %}Select risk group{% endtrans %}</option>
{% for risk_group in risk_groups %}
<option {% if "risk-group" in filters and risk_group.value==filters["risk-group"].value %}selected="selected" {% endif
%} value="{{ risk_group.value }}">
{{ risk_group.display_value }}
</option>
{% endfor %}
</select>
Expand Down
Loading

0 comments on commit a8751d6

Please sign in to comment.