Skip to content

Commit

Permalink
229 mock up maatregelen and vereisten in task registry connected to p…
Browse files Browse the repository at this point in the history
…rofile based on labels (#249)
  • Loading branch information
ChristopherSpelt authored Oct 14, 2024
2 parents f1165ae + 654b0d1 commit b4c8b51
Show file tree
Hide file tree
Showing 77 changed files with 2,719 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
exclude: "^amt/static/vendor/.*|amt/locale/.*"
- id: trailing-whitespace
- id: check-yaml
exclude: ^(example|example_system_card)/
exclude: "^(example|example_system_card|example_registry)/"
- id: check-json
exclude: 'tsconfig\.json'
- id: check-added-large-files
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ webpack.config.prod.js
tsconfig.json

amt/site/static/vendor/
example_registry/
48 changes: 46 additions & 2 deletions amt/api/routes/project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import logging
from pathlib import Path
from typing import Annotated, Any
Expand All @@ -19,9 +20,10 @@
from amt.models import Project
from amt.schema.system_card import SystemCard
from amt.schema.task import MovedTask
from amt.services.instruments_state import InstrumentStateService
from amt.services.instruments_and_requirements_state import InstrumentStateService, RequirementsStateService
from amt.services.projects import ProjectsService
from amt.services.storage import StorageFactory
from amt.services.task_registry import fetch_measures, fetch_requirements
from amt.services.tasks import TasksService
from amt.utils.storage import get_include_content

Expand All @@ -36,6 +38,7 @@ def get_system_card_data() -> SystemCard:
return SystemCard(**system_card)


@functools.lru_cache
def get_instrument_state() -> dict[str, Any]:
system_card_data = get_system_card_data()
instrument_state = InstrumentStateService(system_card_data)
Expand All @@ -47,6 +50,18 @@ def get_instrument_state() -> dict[str, Any]:
}


def get_requirements_state(system_card: SystemCard) -> dict[str, Any]:
requirements = fetch_requirements([requirement.urn for requirement in system_card.requirements])
requirements_state_service = RequirementsStateService(system_card)
requirements_state = requirements_state_service.get_requirements_state(requirements)

return {
"states": requirements_state,
"count_0": requirements_state_service.get_amount_completed_requirements(),
"count_1": requirements_state_service.get_amount_total_requirements(),
}


def get_project_or_error(project_id: int, projects_service: ProjectsService, request: Request) -> Project:
try:
logger.debug(f"getting project with id {project_id}")
Expand Down Expand Up @@ -88,6 +103,7 @@ async def get_tasks(
) -> HTMLResponse:
project = get_project_or_error(project_id, projects_service, request)
instrument_state = get_instrument_state()
requirements_state = get_requirements_state(project.system_card)
tab_items = get_project_details_tabs(request)

breadcrumbs = resolve_base_navigation_items(
Expand All @@ -101,9 +117,11 @@ async def get_tasks(

context = {
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"tasks_service": tasks_service,
"statuses": Status,
"project": project,
"project_id": project.id,
"breadcrumbs": breadcrumbs,
"tab_items": tab_items,
}
Expand Down Expand Up @@ -158,6 +176,7 @@ async def get_project_details(

system_card_data = get_system_card_data()
instrument_state = get_instrument_state()
requirements_state = get_requirements_state(project.system_card)

tab_items = get_project_details_tabs(request)

Expand All @@ -166,7 +185,9 @@ async def get_project_details(
"last_edited": project.last_edited,
"system_card": system_card_data,
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"project": project,
"project_id": project.id,
"breadcrumbs": breadcrumbs,
"tab_items": tab_items,
}
Expand All @@ -187,6 +208,7 @@ async def get_system_card(
) -> HTMLResponse:
project = get_project_or_error(project_id, projects_service, request)
instrument_state = get_instrument_state()
requirements_state = get_requirements_state(project.system_card)

tab_items = get_project_details_tabs(request)

Expand All @@ -209,6 +231,7 @@ async def get_system_card(
context = {
"system_card": system_card_data,
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"last_edited": project.last_edited,
"project": project,
"project_id": project.id,
Expand All @@ -232,7 +255,8 @@ async def get_system_card_requirements(
) -> HTMLResponse:
project = get_project_or_error(project_id, projects_service, request)
instrument_state = get_instrument_state()

requirements_state = get_requirements_state(project.system_card)
# TODO: This tab is fairly slow, fix in later releases
tab_items = get_project_details_tabs(request)

breadcrumbs = resolve_base_navigation_items(
Expand All @@ -244,12 +268,23 @@ async def get_system_card_requirements(
request,
)

# TODO: This is only for the demo of 18 Oct. In reality one would load the requirements from the requirement
# field in the system card, but one would load the AI Act Profile and determine the requirements from
# the labels in this field.
system_card = project.system_card
requirements = fetch_requirements([requirement.urn for requirement in system_card.requirements])

# Get measures that correspond to the requirements.
requirements_and_measures = [(requirement, fetch_measures(requirement.links)) for requirement in requirements]

context = {
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"project": project,
"project_id": project.id,
"tab_items": tab_items,
"breadcrumbs": breadcrumbs,
"requirements_and_measures": requirements_and_measures,
}

return templates.TemplateResponse(request, "projects/details_requirements.html.j2", context)
Expand All @@ -268,6 +303,7 @@ async def get_system_card_data_page(
) -> HTMLResponse:
project = get_project_or_error(project_id, projects_service, request)
instrument_state = get_instrument_state()
requirements_state = get_requirements_state(project.system_card)

tab_items = get_project_details_tabs(request)

Expand All @@ -282,6 +318,7 @@ async def get_system_card_data_page(

context = {
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"project": project,
"project_id": project.id,
"tab_items": tab_items,
Expand All @@ -304,6 +341,7 @@ async def get_system_card_instruments(
) -> HTMLResponse:
project = get_project_or_error(project_id, projects_service, request)
instrument_state = get_instrument_state()
requirements_state = get_requirements_state(project.system_card)

tab_items = get_project_details_tabs(request)

Expand All @@ -318,6 +356,7 @@ async def get_system_card_instruments(

context = {
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"project": project,
"project_id": project.id,
"tab_items": tab_items,
Expand All @@ -341,6 +380,7 @@ async def get_assessment_card(
) -> HTMLResponse:
project = get_project_or_error(project_id, projects_service, request)
instrument_state = get_instrument_state()
requirements_state = get_requirements_state(project.system_card)

request.state.path_variables.update({"assessment_card": assessment_card})

Expand All @@ -365,6 +405,7 @@ async def get_assessment_card(

context = {
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"assessment_card": assessment_card_data,
"last_edited": project.last_edited,
"sub_menu_items": sub_menu_items,
Expand All @@ -388,6 +429,7 @@ async def get_model_card(
) -> HTMLResponse:
project = get_project_or_error(project_id, projects_service, request)
instrument_state = get_instrument_state()
requirements_state = get_requirements_state(project.system_card)

# TODO: This now loads an example system card independent of the project ID.
filepath = Path("example_system_card/system_card.yaml")
Expand All @@ -411,10 +453,12 @@ async def get_model_card(

context = {
"instrument_state": instrument_state,
"requirements_state": requirements_state,
"model_card": model_card_data,
"last_edited": project.last_edited,
"breadcrumbs": breadcrumbs,
"project": project,
"project_id": project.id,
"tab_items": tab_items,
}

Expand Down
9 changes: 9 additions & 0 deletions amt/api/routes/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ async def post_new(
project_new: ProjectNew,
projects_service: Annotated[ProjectsService, Depends(ProjectsService)],
) -> HTMLResponse:
# TODO: FOR DEMO 18 OCT
# Override AI Act Profile for demo purposes to values:
project_new.type = "AI-systeem"
project_new.publication_category = "hoog-risico AI"
project_new.transparency_obligations = "geen transparantieverplichtingen"
project_new.role = "gebruiksverantwoordelijke"
project_new.systemic_risk = "geen systeemrisico"
project_new.open_source = "open-source"

project = projects_service.create(project_new)
response = templates.Redirect(request, f"/project/{project.id}/details/tasks")
return response
2 changes: 1 addition & 1 deletion amt/cli/check_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from amt.schema.instrument import Instrument
from amt.schema.system_card import SystemCard
from amt.services.instruments import InstrumentsService
from amt.services.instruments_state import all_lifecycles, get_all_next_tasks
from amt.services.instruments_and_requirements_state import all_lifecycles, get_all_next_tasks
from amt.services.storage import StorageFactory

logger = logging.getLogger(__name__)
Expand Down
24 changes: 14 additions & 10 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-12 21:16+0200\n"
"POT-Creation-Date: 2024-10-14 12:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -224,10 +224,10 @@ msgid "Reviewing"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:32
#: amt/site/templates/projects/details_base.html.j2:21
#: amt/site/templates/projects/details_base.html.j2:22
#: amt/site/templates/projects/details_base.html.j2:43
#: amt/site/templates/projects/details_base.html.j2:76
#: amt/site/templates/projects/details_base.html.j2:98
#: amt/site/templates/projects/details_base.html.j2:69
#: amt/site/templates/projects/details_base.html.j2:91
msgid "Done"
msgstr ""

Expand Down Expand Up @@ -323,24 +323,24 @@ msgstr ""
msgid "AMT Placeholder information page"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:19
#: amt/site/templates/projects/details_base.html.j2:20
msgid "Does the algorithm meet the requirements?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:32
#: amt/site/templates/projects/details_base.html.j2:96
#: amt/site/templates/projects/details_base.html.j2:41
#: amt/site/templates/projects/details_base.html.j2:89
msgid "To do"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:63
#: amt/site/templates/projects/details_base.html.j2:55
msgid "Go to all requirements"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:73
#: amt/site/templates/projects/details_base.html.j2:66
msgid "Which instruments are executed?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:110
#: amt/site/templates/projects/details_base.html.j2:103
msgid "Go to all instruments"
msgstr ""

Expand All @@ -364,6 +364,10 @@ msgstr ""
msgid "Labels"
msgstr ""

#: amt/site/templates/projects/details_requirements.html.j2:22
msgid "measures executed"
msgstr ""

#: amt/site/templates/projects/index.html.j2:12
msgid "New project"
msgstr ""
Expand Down
Binary file modified amt/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
24 changes: 14 additions & 10 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-10-12 21:16+0200\n"
"POT-Creation-Date: 2024-10-14 12:11+0200\n"
"PO-Revision-Date: 2024-07-25 21:01+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
Expand Down Expand Up @@ -225,10 +225,10 @@ msgid "Reviewing"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:32
#: amt/site/templates/projects/details_base.html.j2:21
#: amt/site/templates/projects/details_base.html.j2:22
#: amt/site/templates/projects/details_base.html.j2:43
#: amt/site/templates/projects/details_base.html.j2:76
#: amt/site/templates/projects/details_base.html.j2:98
#: amt/site/templates/projects/details_base.html.j2:69
#: amt/site/templates/projects/details_base.html.j2:91
msgid "Done"
msgstr ""

Expand Down Expand Up @@ -324,24 +324,24 @@ msgstr ""
msgid "AMT Placeholder information page"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:19
#: amt/site/templates/projects/details_base.html.j2:20
msgid "Does the algorithm meet the requirements?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:32
#: amt/site/templates/projects/details_base.html.j2:96
#: amt/site/templates/projects/details_base.html.j2:41
#: amt/site/templates/projects/details_base.html.j2:89
msgid "To do"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:63
#: amt/site/templates/projects/details_base.html.j2:55
msgid "Go to all requirements"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:73
#: amt/site/templates/projects/details_base.html.j2:66
msgid "Which instruments are executed?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:110
#: amt/site/templates/projects/details_base.html.j2:103
msgid "Go to all instruments"
msgstr ""

Expand All @@ -365,6 +365,10 @@ msgstr ""
msgid "Labels"
msgstr ""

#: amt/site/templates/projects/details_requirements.html.j2:22
msgid "measures executed"
msgstr ""

#: amt/site/templates/projects/index.html.j2:12
msgid "New project"
msgstr ""
Expand Down
Binary file modified amt/locale/nl_NL/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit b4c8b51

Please sign in to comment.