|
|
|
@@ -1,293 +1,443 @@
|
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
DFG Project Clean Model
|
|
|
|
|
DFG Project Clean Model (v2)
|
|
|
|
|
|
|
|
|
|
Summary model that consolidates all scattered person and institution fields
|
|
|
|
|
from the raw projects_dfg_all index into clean, unified lists.
|
|
|
|
|
Enriched, consolidated model built on top of the structured
|
|
|
|
|
projects_dfg_v2 API models (DFGProject / DFGPerson / DFGInstitute),
|
|
|
|
|
rather than the old flat projects_dfg_all Elasticsearch index.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from typing import Optional, List, Set
|
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
|
|
|
|
from inse.models.projects_dfg_v2.project.dfg_project import DFGProject
|
|
|
|
|
from inse.models.projects_dfg_v2.project.dfg_project_persons_inner import (
|
|
|
|
|
DFGProjectPersonsInner,
|
|
|
|
|
)
|
|
|
|
|
from inse.models.projects_dfg_v2.project.dfg_project_institutions_inner import (
|
|
|
|
|
DFGProjectInstitutionsInner,
|
|
|
|
|
)
|
|
|
|
|
from inse.models.projects_dfg_v2.project.dfg_project_subprojects_inner import (
|
|
|
|
|
DFGProjectSubprojectsInner,
|
|
|
|
|
)
|
|
|
|
|
from inse.models.projects_dfg_v2.project.dfg_project_publications_inner import (
|
|
|
|
|
DFGProjectPublicationsInner,
|
|
|
|
|
)
|
|
|
|
|
from inse.models.projects_dfg_v2.project.dfg_project_fachgebiete_inner import (
|
|
|
|
|
DFGProjectFachgebieteInner,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DfgProjectPersonRole(BaseModel):
|
|
|
|
|
"""A person associated with the project, together with their role."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
|
|
|
|
person_id: Optional[int] = Field(default=None, description="DFG person ID")
|
|
|
|
|
full_name: Optional[str] = Field(default=None, description="Full name of the person")
|
|
|
|
|
orcid_id: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
description=(
|
|
|
|
|
"ORCID iD, if known. Not present on the project's embedded person "
|
|
|
|
|
"record (DFGProjectPersonsInner) -- only populated if the caller "
|
|
|
|
|
"cross-references the full DFGPerson record via person_id and "
|
|
|
|
|
"calls DfgProjectDetails.enrich_orcids afterwards."
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
role_key: Optional[str] = Field(
|
|
|
|
|
default=None, description="Machine-readable role key (e.g. 'antragsteller')"
|
|
|
|
|
)
|
|
|
|
|
role_label_de: Optional[str] = Field(default=None, description="Role label (German)")
|
|
|
|
|
role_label_en: Optional[str] = Field(default=None, description="Role label (English)")
|
|
|
|
|
affiliation_de: Optional[str] = Field(
|
|
|
|
|
default=None, description="Person's affiliation at time of project (German)"
|
|
|
|
|
)
|
|
|
|
|
affiliation_en: Optional[str] = Field(
|
|
|
|
|
default=None, description="Person's affiliation at time of project (English)"
|
|
|
|
|
)
|
|
|
|
|
is_deceased: Optional[bool] = Field(default=None, description="Whether the person is deceased")
|
|
|
|
|
is_head: Optional[bool] = Field(
|
|
|
|
|
default=None, description="Whether this person is highlighted as the project head"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_inner(cls, p: DFGProjectPersonsInner) -> "DfgProjectPersonRole":
|
|
|
|
|
return cls(
|
|
|
|
|
person_id=p.person_id,
|
|
|
|
|
full_name=p.full_name,
|
|
|
|
|
role_key=p.role_key,
|
|
|
|
|
role_label_de=p.role_label_de,
|
|
|
|
|
role_label_en=p.role_label_en,
|
|
|
|
|
affiliation_de=p.affiliation_de,
|
|
|
|
|
affiliation_en=p.affiliation_en,
|
|
|
|
|
is_deceased=p.is_deceased,
|
|
|
|
|
is_head=p.is_head_display,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DfgProjectInstitutionRole(BaseModel):
|
|
|
|
|
"""An institution associated with the project, together with its role."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
|
|
|
|
institute_id: Optional[int] = Field(default=None, description="DFG institute ID")
|
|
|
|
|
name_de: Optional[str] = Field(default=None, description="Institution name (German)")
|
|
|
|
|
name_en: Optional[str] = Field(default=None, description="Institution name (English)")
|
|
|
|
|
role_key: Optional[str] = Field(default=None, description="Machine-readable role key")
|
|
|
|
|
role_label_de: Optional[str] = Field(default=None, description="Role label (German)")
|
|
|
|
|
role_label_en: Optional[str] = Field(default=None, description="Role label (English)")
|
|
|
|
|
is_dissolved: Optional[bool] = Field(
|
|
|
|
|
default=None, description="Whether the institution has since been dissolved"
|
|
|
|
|
)
|
|
|
|
|
is_head: Optional[bool] = Field(
|
|
|
|
|
default=None, description="Whether this institution is highlighted as the lead institution"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_inner(cls, i: DFGProjectInstitutionsInner) -> "DfgProjectInstitutionRole":
|
|
|
|
|
return cls(
|
|
|
|
|
institute_id=i.institute_id,
|
|
|
|
|
name_de=i.institute_name_de,
|
|
|
|
|
name_en=i.institute_name_en,
|
|
|
|
|
role_key=i.role_key,
|
|
|
|
|
role_label_de=i.role_label_de,
|
|
|
|
|
role_label_en=i.role_label_en,
|
|
|
|
|
is_dissolved=i.is_dissolved,
|
|
|
|
|
is_head=i.is_head_display,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DfgProjectSubprojectSummary(BaseModel):
|
|
|
|
|
"""A lightweight reference to a sub-project of this project."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
|
|
|
|
subproject_id: Optional[int] = None
|
|
|
|
|
title_de: Optional[str] = None
|
|
|
|
|
title_en: Optional[str] = None
|
|
|
|
|
short_title: Optional[str] = None
|
|
|
|
|
role_label_de: Optional[str] = Field(
|
|
|
|
|
default=None, description="Role of the sub-project lead within the sub-project"
|
|
|
|
|
)
|
|
|
|
|
person_full_name: Optional[str] = Field(
|
|
|
|
|
default=None, description="Sub-project lead, derived from first/last name fields"
|
|
|
|
|
)
|
|
|
|
|
status_de: Optional[str] = None
|
|
|
|
|
funding_start: Optional[int] = None
|
|
|
|
|
funding_end: Optional[int] = None
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_inner(cls, s: DFGProjectSubprojectsInner) -> "DfgProjectSubprojectSummary":
|
|
|
|
|
person_full_name = None
|
|
|
|
|
if s.person_first_names or s.person_last_name:
|
|
|
|
|
person_full_name = " ".join(
|
|
|
|
|
part for part in [s.person_first_names, s.person_last_name] if part
|
|
|
|
|
).strip() or None
|
|
|
|
|
|
|
|
|
|
return cls(
|
|
|
|
|
subproject_id=s.subproject_id,
|
|
|
|
|
title_de=s.title_de,
|
|
|
|
|
title_en=s.title_en,
|
|
|
|
|
short_title=s.short_title,
|
|
|
|
|
role_label_de=s.role_label_de,
|
|
|
|
|
person_full_name=person_full_name,
|
|
|
|
|
status_de=s.status_de,
|
|
|
|
|
funding_start=s.funding_start,
|
|
|
|
|
funding_end=s.funding_end,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DfgProjectPublicationSummary(BaseModel):
|
|
|
|
|
"""A lightweight reference to a publication resulting from the project."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
|
|
|
|
publication_id: Optional[int] = None
|
|
|
|
|
title: Optional[str] = None
|
|
|
|
|
authors_editors: Optional[str] = None
|
|
|
|
|
doi: Optional[str] = None
|
|
|
|
|
publication_year: Optional[int] = None
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_inner(cls, p: DFGProjectPublicationsInner) -> "DfgProjectPublicationSummary":
|
|
|
|
|
return cls(
|
|
|
|
|
publication_id=p.publication_id,
|
|
|
|
|
title=p.title,
|
|
|
|
|
authors_editors=p.authors_editors,
|
|
|
|
|
doi=p.doi,
|
|
|
|
|
publication_year=p.publication_year,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DfgProjectSubjectArea(BaseModel):
|
|
|
|
|
"""A single subject-area classification entry (DFG 'Fachsystematik')."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
|
|
|
|
fach: Optional[str] = None
|
|
|
|
|
fachgebiet: Optional[str] = None
|
|
|
|
|
fachkollegium: Optional[str] = None
|
|
|
|
|
wissenschaftsbereich: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_inner(cls, f: DFGProjectFachgebieteInner) -> "DfgProjectSubjectArea":
|
|
|
|
|
return cls(
|
|
|
|
|
fach=f.fach,
|
|
|
|
|
fachgebiet=f.fachgebiet,
|
|
|
|
|
fachkollegium=f.fachkollegium,
|
|
|
|
|
wissenschaftsbereich=f.wissenschaftsbereich,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DfgProjectDetails(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
Clean summary model for a DFG project, consolidating all person roles
|
|
|
|
|
and institution references into unified lists.
|
|
|
|
|
Clean, enriched summary model for a DFG project.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(
|
|
|
|
|
populate_by_name=True,
|
|
|
|
|
validate_assignment=True,
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(populate_by_name=True, validate_assignment=True)
|
|
|
|
|
|
|
|
|
|
id: Optional[int] = Field(default=None, description="The DFG project ID")
|
|
|
|
|
link: Optional[str] = Field(default=None, description="Canonical DFG link to the project")
|
|
|
|
|
page_url: Optional[str] = Field(default=None, description="DFG GEPRIS page URL")
|
|
|
|
|
external_link: Optional[str] = Field(
|
|
|
|
|
default=None, description="External project website/link, if provided"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
id: str = Field(description="The ID of the DFG project")
|
|
|
|
|
link: Optional[str] = Field(default=None, description="The link to the DFG project")
|
|
|
|
|
title: Optional[str] = Field(
|
|
|
|
|
default=None, description="The title of the DFG project"
|
|
|
|
|
title_de: Optional[str] = Field(default=None, description="Project title (German)")
|
|
|
|
|
title_en: Optional[str] = Field(default=None, description="Project title (English)")
|
|
|
|
|
description_de: Optional[str] = Field(default=None, description="Project abstract (German)")
|
|
|
|
|
description_en: Optional[str] = Field(default=None, description="Project abstract (English)")
|
|
|
|
|
final_report_abstract_de: Optional[str] = Field(
|
|
|
|
|
default=None, description="Final report abstract (German), if the project has concluded"
|
|
|
|
|
)
|
|
|
|
|
description: Optional[str] = Field(
|
|
|
|
|
default=None, description="The description of the DFG project"
|
|
|
|
|
final_report_abstract_en: Optional[str] = Field(
|
|
|
|
|
default=None, description="Final report abstract (English), if the project has concluded"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
project_identifier: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
description="The project identifier of the DFG project",
|
|
|
|
|
)
|
|
|
|
|
project_identifier_de: Optional[str] = Field(default=None, description="DFG project identifier (German)")
|
|
|
|
|
project_identifier_en: Optional[str] = Field(default=None, description="DFG project identifier (English)")
|
|
|
|
|
|
|
|
|
|
funding_start_date: Optional[str] = Field(
|
|
|
|
|
default=None, description="The funding start date of the DFG project"
|
|
|
|
|
)
|
|
|
|
|
funding_end_date: Optional[str] = Field(
|
|
|
|
|
default=None, description="The funding end date of the DFG project"
|
|
|
|
|
)
|
|
|
|
|
funding_start: Optional[int] = Field(default=None, description="Funding start year")
|
|
|
|
|
funding_end: Optional[int] = Field(default=None, description="Funding end year")
|
|
|
|
|
funding_period_de: Optional[str] = Field(default=None, description="Human-readable funding period (German)")
|
|
|
|
|
funding_period_en: Optional[str] = Field(default=None, description="Human-readable funding period (English)")
|
|
|
|
|
|
|
|
|
|
funding_type_de: Optional[str] = Field(default=None, description="Funding type / programme (German)")
|
|
|
|
|
funding_type_en: Optional[str] = Field(default=None, description="Funding type / programme (English)")
|
|
|
|
|
funding_type_key: Optional[str] = Field(default=None, description="Machine-readable funding type key")
|
|
|
|
|
|
|
|
|
|
dfg_procedure: Optional[str] = Field(
|
|
|
|
|
default=None, description="The DFG procedure"
|
|
|
|
|
)
|
|
|
|
|
subject_area: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
description="The subject area classification",
|
|
|
|
|
)
|
|
|
|
|
funding_type: Optional[str] = Field(
|
|
|
|
|
default=None, description="The type of funding"
|
|
|
|
|
)
|
|
|
|
|
international_reference: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
|
|
|
|
|
description="International reference",
|
|
|
|
|
default=None, description="DFG procedure / template type (e.g. Sachbeihilfe, SFB, GRK)"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
website: Optional[str] = Field(
|
|
|
|
|
default=None, description="The project website"
|
|
|
|
|
is_transfer_project: Optional[bool] = Field(
|
|
|
|
|
default=None, description="Whether this is a transfer project"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Unified person list: all person names from any role
|
|
|
|
|
website_html_de: Optional[str] = Field(
|
|
|
|
|
default=None, description="Raw project website HTML content (German), as served by DFG"
|
|
|
|
|
)
|
|
|
|
|
website_html_en: Optional[str] = Field(
|
|
|
|
|
default=None, description="Raw project website HTML content (English), as served by DFG"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
equipment_group: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
description="Large-equipment (Großgerät) group, for equipment-funding projects",
|
|
|
|
|
)
|
|
|
|
|
equipment_name: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
description="Large-equipment (Großgerät) name, for equipment-funding projects",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
subject_area_de: Optional[str] = Field(default=None, description="Subject area, summary text (German)")
|
|
|
|
|
subject_area_en: Optional[str] = Field(default=None, description="Subject area, summary text (English)")
|
|
|
|
|
subject_classifications: List[DfgProjectSubjectArea] = Field(
|
|
|
|
|
default_factory=list,
|
|
|
|
|
description="Detailed DFG subject-area classification entries (Fachsystematik)",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
international_relation_de: Optional[str] = Field(
|
|
|
|
|
default=None, description="International reference/cooperation (German)"
|
|
|
|
|
)
|
|
|
|
|
international_relation_en: Optional[str] = Field(
|
|
|
|
|
default=None, description="International reference/cooperation (English)"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Structured, role-aware person and institution lists
|
|
|
|
|
persons: List[DfgProjectPersonRole] = Field(
|
|
|
|
|
default_factory=list,
|
|
|
|
|
description="All persons associated with the project, each with their role",
|
|
|
|
|
)
|
|
|
|
|
institutions: List[DfgProjectInstitutionRole] = Field(
|
|
|
|
|
default_factory=list,
|
|
|
|
|
description="All institutions associated with the project, each with their role",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Convenience flat views, derived from the structured lists above
|
|
|
|
|
associated_persons: List[str] = Field(
|
|
|
|
|
default_factory=list,
|
|
|
|
|
description="All persons associated with the DFG project (any role)",
|
|
|
|
|
description="Flat, de-duplicated list of all person full names (convenience view)",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Unified institution list: all institutions involved
|
|
|
|
|
institutions: List[str] = Field(
|
|
|
|
|
associated_institutions: List[str] = Field(
|
|
|
|
|
default_factory=list,
|
|
|
|
|
description="All institutions associated with the DFG project",
|
|
|
|
|
description="Flat, de-duplicated list of all institution names (convenience view)",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Sub-project reference
|
|
|
|
|
subproject_of: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
description="Parent project this is a sub-project of",
|
|
|
|
|
# Parent / sub-project structure
|
|
|
|
|
parent_project_id: Optional[int] = Field(default=None, description="Parent project ID, if this is a sub-project")
|
|
|
|
|
parent_title_de: Optional[str] = Field(default=None, description="Parent project title (German)")
|
|
|
|
|
parent_title_en: Optional[str] = Field(default=None, description="Parent project title (English)")
|
|
|
|
|
subprojects: List[DfgProjectSubprojectSummary] = Field(
|
|
|
|
|
default_factory=list, description="Sub-projects of this project, if any"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
publications: List[DfgProjectPublicationSummary] = Field(
|
|
|
|
|
default_factory=list, description="Publications resulting from the project"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_dfg_project(cls, project: DFGProject) -> "DfgProjectDetails":
|
|
|
|
|
"""
|
|
|
|
|
Build a DfgProjectDetails from a fully-typed DFGProject instance
|
|
|
|
|
(e.g. as returned by the projects_dfg_v2 API client).
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
persons = [DfgProjectPersonRole.from_inner(p) for p in (project.persons or [])]
|
|
|
|
|
institutions = [
|
|
|
|
|
DfgProjectInstitutionRole.from_inner(i) for i in (project.institutions or [])
|
|
|
|
|
]
|
|
|
|
|
subprojects = [
|
|
|
|
|
DfgProjectSubprojectSummary.from_inner(s) for s in (project.subprojects or [])
|
|
|
|
|
]
|
|
|
|
|
publications = [
|
|
|
|
|
DfgProjectPublicationSummary.from_inner(p) for p in (project.publications or [])
|
|
|
|
|
]
|
|
|
|
|
subject_classifications = [
|
|
|
|
|
DfgProjectSubjectArea.from_inner(f) for f in (project.fachgebiete or [])
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# De-duplicated flat views, order-preserving
|
|
|
|
|
seen_persons = set()
|
|
|
|
|
associated_persons = []
|
|
|
|
|
for p in persons:
|
|
|
|
|
if p.full_name and p.full_name not in seen_persons:
|
|
|
|
|
seen_persons.add(p.full_name)
|
|
|
|
|
associated_persons.append(p.full_name)
|
|
|
|
|
|
|
|
|
|
seen_institutions = set()
|
|
|
|
|
associated_institutions = []
|
|
|
|
|
for i in institutions:
|
|
|
|
|
name = i.name_de or i.name_en
|
|
|
|
|
if name and name not in seen_institutions:
|
|
|
|
|
seen_institutions.add(name)
|
|
|
|
|
associated_institutions.append(name)
|
|
|
|
|
|
|
|
|
|
return cls(
|
|
|
|
|
id=project.id or project.project_id,
|
|
|
|
|
link=project.link,
|
|
|
|
|
page_url=project.page_url,
|
|
|
|
|
external_link=project.external_link,
|
|
|
|
|
title_de=project.title_de,
|
|
|
|
|
title_en=project.title_en,
|
|
|
|
|
description_de=project.abstract_de,
|
|
|
|
|
description_en=project.abstract_en,
|
|
|
|
|
final_report_abstract_de=project.final_report_abstract_de,
|
|
|
|
|
final_report_abstract_en=project.final_report_abstract_en,
|
|
|
|
|
project_identifier_de=project.project_identifier_de,
|
|
|
|
|
project_identifier_en=project.project_identifier_en,
|
|
|
|
|
funding_start=project.funding_start,
|
|
|
|
|
funding_end=project.funding_end,
|
|
|
|
|
funding_period_de=project.funding_period_de,
|
|
|
|
|
funding_period_en=project.funding_period_en,
|
|
|
|
|
funding_type_de=project.funding_type_de,
|
|
|
|
|
funding_type_en=project.funding_type_en,
|
|
|
|
|
funding_type_key=project.funding_type_key,
|
|
|
|
|
dfg_procedure=project.template_type,
|
|
|
|
|
is_transfer_project=project.is_transfer_project,
|
|
|
|
|
website_html_de=project.website_html_de,
|
|
|
|
|
website_html_en=project.website_html_en,
|
|
|
|
|
equipment_group=project.equipment_group,
|
|
|
|
|
equipment_name=project.equipment_name,
|
|
|
|
|
subject_area_de=project.subject_area_de,
|
|
|
|
|
subject_area_en=project.subject_area_en,
|
|
|
|
|
subject_classifications=subject_classifications,
|
|
|
|
|
international_relation_de=project.international_relation_de,
|
|
|
|
|
international_relation_en=project.international_relation_en,
|
|
|
|
|
persons=persons,
|
|
|
|
|
institutions=institutions,
|
|
|
|
|
associated_persons=associated_persons,
|
|
|
|
|
associated_institutions=associated_institutions,
|
|
|
|
|
parent_project_id=project.parent_project_id,
|
|
|
|
|
parent_title_de=project.parent_title_de,
|
|
|
|
|
parent_title_en=project.parent_title_en,
|
|
|
|
|
subprojects=subprojects,
|
|
|
|
|
publications=publications,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_dict(cls, obj: dict) -> "DfgProjectDetails":
|
|
|
|
|
"""Convenience constructor from a raw dict (e.g. a JSON API response body)."""
|
|
|
|
|
obj = cls._sanitize_raw_project_dict(obj)
|
|
|
|
|
return cls.from_dfg_project(DFGProject.from_dict(obj))
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _sanitize_raw_project_dict(obj: dict) -> dict:
|
|
|
|
|
"""
|
|
|
|
|
Work around known mismatches between the generated DFGProject model
|
|
|
|
|
and the actual shape of API/index data, before handing off to
|
|
|
|
|
DFGProject.from_dict (which would otherwise raise a ValidationError
|
|
|
|
|
and abort the whole parse).
|
|
|
|
|
|
|
|
|
|
Known issue: `subject_classifications` is generated as a single
|
|
|
|
|
`DFGProjectFachgebieteInner`, but the real data returns a list (the
|
|
|
|
|
same shape as `fachgebiete`). We don't use this field ourselves --
|
|
|
|
|
our own `subject_classifications` is built from `fachgebiete` -- so
|
|
|
|
|
it's simply dropped here rather than fixed up, to avoid crashing on
|
|
|
|
|
a field we never read. The proper long-term fix is correcting the
|
|
|
|
|
OpenAPI spec/generator so this field is typed as a list.
|
|
|
|
|
"""
|
|
|
|
|
if isinstance(obj.get("subject_classifications"), list):
|
|
|
|
|
obj = dict(obj)
|
|
|
|
|
obj.pop("subject_classifications", None)
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_elastic_hit(cls, hit: dict) -> "DfgProjectDetails":
|
|
|
|
|
"""
|
|
|
|
|
Create a DfgProject from an Elasticsearch hit, consolidating all
|
|
|
|
|
person and institution fields into unified lists.
|
|
|
|
|
Compatibility constructor for callers still reading from an
|
|
|
|
|
Elasticsearch hit (e.g. `{"_id": ..., "_source": {...}}`), matching
|
|
|
|
|
the old model's from_elastic_hit signature.
|
|
|
|
|
|
|
|
|
|
Assumes `_source` is already shaped like a DFGProject document
|
|
|
|
|
(flat fields, persons/institutions/etc. as lists) rather than the
|
|
|
|
|
old scattered-German-fields Elasticsearch schema. If `_source`
|
|
|
|
|
doesn't itself carry an id/project_id, the ES `_id` is injected so
|
|
|
|
|
`DfgProjectDetails.id` is never left empty.
|
|
|
|
|
"""
|
|
|
|
|
source = dict(hit.get("_source", {}))
|
|
|
|
|
|
|
|
|
|
source = hit.get("_source", {})
|
|
|
|
|
if source.get("id") is None and source.get("project_id") is None:
|
|
|
|
|
raw_id = hit.get("_id")
|
|
|
|
|
if raw_id is not None:
|
|
|
|
|
try:
|
|
|
|
|
source["id"] = int(raw_id)
|
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
|
# Non-numeric _id (e.g. a composite/legacy key) - leave
|
|
|
|
|
# id unset rather than fail the whole parse.
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
associated_persons: Set[str] = set()
|
|
|
|
|
institutions: Set[str] = set()
|
|
|
|
|
return cls.from_dict(source)
|
|
|
|
|
|
|
|
|
|
# --- Collect all persons and institutions from nested persons array ---
|
|
|
|
|
persons_list = source.get("persons", [])
|
|
|
|
|
if isinstance(persons_list, list):
|
|
|
|
|
for p in persons_list:
|
|
|
|
|
if isinstance(p, dict):
|
|
|
|
|
full_name = p.get("full_name")
|
|
|
|
|
if full_name:
|
|
|
|
|
associated_persons.add(full_name.strip())
|
|
|
|
|
|
|
|
|
|
aff_de = p.get("affiliation_de")
|
|
|
|
|
if aff_de:
|
|
|
|
|
institutions.add(aff_de.strip())
|
|
|
|
|
|
|
|
|
|
aff_en = p.get("affiliation_en")
|
|
|
|
|
if aff_en:
|
|
|
|
|
institutions.add(aff_en.strip())
|
|
|
|
|
|
|
|
|
|
# --- Collect all persons from every person-related field ---
|
|
|
|
|
|
|
|
|
|
# Applicant fields
|
|
|
|
|
_add_persons(source, associated_persons, "Antragsteller") # semicolon-separated
|
|
|
|
|
_add_person(source, associated_persons, "Antragstellerin")
|
|
|
|
|
_add_persons(
|
|
|
|
|
source, associated_persons, "Antragstellerinnen"
|
|
|
|
|
) # semicolon-separated
|
|
|
|
|
_add_persons(
|
|
|
|
|
source, associated_persons, "Antragstellerinnen / Antragsteller"
|
|
|
|
|
) # semicolon-separated
|
|
|
|
|
|
|
|
|
|
# Co-applicant fields
|
|
|
|
|
_add_persons(source, associated_persons, "Mitantragsteller")
|
|
|
|
|
_add_person(source, associated_persons, "Mitantragstellerin")
|
|
|
|
|
_add_persons(source, associated_persons, "Mitantragstellerinnen")
|
|
|
|
|
_add_persons(
|
|
|
|
|
source, associated_persons, "Mitantragstellerinnen / Mitantragsteller"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Former applicant fields
|
|
|
|
|
_add_persons(source, associated_persons, "Ehemalige Antragsteller")
|
|
|
|
|
_add_person(source, associated_persons, "Ehemalige Antragstellerin")
|
|
|
|
|
_add_persons(source, associated_persons, "Ehemalige Antragstellerinnen")
|
|
|
|
|
_add_persons(
|
|
|
|
|
source,
|
|
|
|
|
associated_persons,
|
|
|
|
|
"Ehemalige Antragstellerinnen / Ehemalige Antragsteller",
|
|
|
|
|
)
|
|
|
|
|
_add_person(source, associated_persons, "Ehemaliger Antragsteller")
|
|
|
|
|
|
|
|
|
|
# Speaker / coordinator fields
|
|
|
|
|
_add_person(source, associated_persons, "Sprecher")
|
|
|
|
|
_add_person(source, associated_persons, "Sprecherin")
|
|
|
|
|
_add_persons(source, associated_persons, "Sprecherinnen")
|
|
|
|
|
_add_persons(source, associated_persons, "Sprecherinnen / Sprecher")
|
|
|
|
|
_add_person(source, associated_persons, "Co-Sprecher")
|
|
|
|
|
_add_persons(source, associated_persons, "Co-Sprecherinnen / Co-Sprecher")
|
|
|
|
|
|
|
|
|
|
# IGK partner speaker fields
|
|
|
|
|
_add_person(source, associated_persons, "Sprecher (IGK-Partner)")
|
|
|
|
|
_add_person(source, associated_persons, "Sprecherin (IGK-Partner)")
|
|
|
|
|
_add_persons(
|
|
|
|
|
source,
|
|
|
|
|
associated_persons,
|
|
|
|
|
"Sprecherinnen (IGK-Partner) / Sprecher (IGK-Partner)",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Leader fields
|
|
|
|
|
_add_person(source, associated_persons, "Leiter")
|
|
|
|
|
_add_person(source, associated_persons, "Leiterin")
|
|
|
|
|
_add_persons(source, associated_persons, "Leiterinnen")
|
|
|
|
|
_add_persons(source, associated_persons, "Leiterinnen / Leiter")
|
|
|
|
|
|
|
|
|
|
# Sub-project leader fields
|
|
|
|
|
_add_persons(source, associated_persons, "Teilprojektleiter")
|
|
|
|
|
_add_person(source, associated_persons, "Teilprojektleiterin")
|
|
|
|
|
_add_persons(source, associated_persons, "Teilprojektleiterinnen")
|
|
|
|
|
_add_persons(
|
|
|
|
|
source, associated_persons, "Teilprojektleiterinnen / Teilprojektleiter"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Participating scientist fields
|
|
|
|
|
_add_persons(source, associated_persons, "beteiligte Wissenschaftler")
|
|
|
|
|
_add_person(source, associated_persons, "beteiligte Wissenschaftlerin")
|
|
|
|
|
_add_persons(source, associated_persons, "beteiligte Wissenschaftlerinnen")
|
|
|
|
|
_add_persons(
|
|
|
|
|
source,
|
|
|
|
|
associated_persons,
|
|
|
|
|
"beteiligte Wissenschaftlerinnen / beteiligte Wissenschaftler",
|
|
|
|
|
)
|
|
|
|
|
_add_person(source, associated_persons, "beteiligter Wissenschaftler")
|
|
|
|
|
|
|
|
|
|
# Participating person fields
|
|
|
|
|
_add_person(source, associated_persons, "Beteiligte Person")
|
|
|
|
|
_add_persons(source, associated_persons, "Beteiligte Personen")
|
|
|
|
|
|
|
|
|
|
# Host fields (for guest researchers)
|
|
|
|
|
_add_person(source, associated_persons, "Gastgeber")
|
|
|
|
|
_add_person(source, associated_persons, "Gastgeberin")
|
|
|
|
|
_add_persons(source, associated_persons, "Gastgeberinnen")
|
|
|
|
|
_add_persons(source, associated_persons, "Gastgeberinnen / Gastgeber")
|
|
|
|
|
|
|
|
|
|
# Cooperation partner fields
|
|
|
|
|
_add_person(source, associated_persons, "Kooperationspartner")
|
|
|
|
|
_add_person(source, associated_persons, "Kooperationspartnerin")
|
|
|
|
|
_add_persons(source, associated_persons, "Kooperationspartnerinnen")
|
|
|
|
|
_add_persons(
|
|
|
|
|
source, associated_persons, "Kooperationspartnerinnen / Kooperationspartner"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Co-responsible fields
|
|
|
|
|
_add_person(source, associated_persons, "Mitverantwortlich")
|
|
|
|
|
_add_person(source, associated_persons, "Mitverantwortlich(e)")
|
|
|
|
|
_add_persons(source, associated_persons, "Mitverantwortliche")
|
|
|
|
|
|
|
|
|
|
# Application partner
|
|
|
|
|
_add_person(source, associated_persons, "Anwendungspartner")
|
|
|
|
|
|
|
|
|
|
# Foreign co-applicant fields
|
|
|
|
|
_add_persons(source, associated_persons, "ausländische Mitantragsteller")
|
|
|
|
|
_add_person(source, associated_persons, "ausländischer Mitantragsteller")
|
|
|
|
|
|
|
|
|
|
# Person creator (from nested fields)
|
|
|
|
|
if "person_creater_name" in source and source["person_creater_name"]:
|
|
|
|
|
associated_persons.add(source["person_creater_name"].strip())
|
|
|
|
|
|
|
|
|
|
# Deputy (stellvertr) - nested object
|
|
|
|
|
stellvertr = source.get("stellvertr")
|
|
|
|
|
if stellvertr and isinstance(stellvertr, dict):
|
|
|
|
|
for field in ["stellvertreter", "stellvertreterin"]:
|
|
|
|
|
if field in stellvertr and stellvertr[field]:
|
|
|
|
|
associated_persons.add(stellvertr[field].strip())
|
|
|
|
|
|
|
|
|
|
# --- Collect all institutions ---
|
|
|
|
|
|
|
|
|
|
_add_institution(source, institutions, "Antragstellende Institution")
|
|
|
|
|
_add_institution(source, institutions, "Mitantragstellende Institution")
|
|
|
|
|
_add_institution(source, institutions, "Beteiligte Einrichtung")
|
|
|
|
|
_add_institution(source, institutions, "Beteiligte Hochschule")
|
|
|
|
|
_add_institution(source, institutions, "Beteiligte Institution")
|
|
|
|
|
_add_institution(source, institutions, "IGK-Partnerinstitution")
|
|
|
|
|
_add_institution(source, institutions, "Partnerorganisation")
|
|
|
|
|
_add_institution(source, institutions, "Unternehmen")
|
|
|
|
|
|
|
|
|
|
# Foreign institution (nested object)
|
|
|
|
|
auslaend = source.get("ausländ")
|
|
|
|
|
if auslaend and isinstance(auslaend, dict):
|
|
|
|
|
for field in [
|
|
|
|
|
"auslaendischeInstitution",
|
|
|
|
|
"auslaendischeInstitution2",
|
|
|
|
|
"auslaendischesUnternehmen",
|
|
|
|
|
"auslaendischesUnternehmen2",
|
|
|
|
|
]:
|
|
|
|
|
if field in auslaend and auslaend[field]:
|
|
|
|
|
institutions.add(auslaend[field].strip())
|
|
|
|
|
|
|
|
|
|
return cls(
|
|
|
|
|
id=hit["_id"],
|
|
|
|
|
link=source.get("link") or source.get("page_url"),
|
|
|
|
|
title=source.get("title") or source.get("title_de") or source.get("title_en"),
|
|
|
|
|
description=source.get("description") or source.get("abstract_de") or source.get("abstract_en"),
|
|
|
|
|
project_identifier=source.get("Projektkennung") or source.get("project_identifier_de") or source.get("project_identifier_en"),
|
|
|
|
|
funding_start_date=str(source.get("funding_start")) if source.get("funding_start") is not None else None,
|
|
|
|
|
funding_end_date=str(source.get("funding_end")) if source.get("funding_end") is not None else None,
|
|
|
|
|
dfg_procedure=source.get("DFG-Verfahren") or source.get("template_type"),
|
|
|
|
|
subject_area=source.get("Fachliche Zuordnung") or source.get("subject_area_de") or source.get("subject_area_en"),
|
|
|
|
|
funding_type=source.get("Förderung") or source.get("funding_type_sort"),
|
|
|
|
|
international_reference=source.get("Internationaler Bezug") or source.get("international_relation_de") or source.get("international_relation_en"),
|
|
|
|
|
website=source.get("Webseite"),
|
|
|
|
|
associated_persons=sorted(associated_persons), # sorted for consistency
|
|
|
|
|
institutions=sorted(institutions),
|
|
|
|
|
subproject_of=source.get("Teilprojekt zu") or source.get("parent_project_id"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --- Helper functions for parsing source fields ---
|
|
|
|
|
|
|
|
|
|
def _add_person(source: dict, persons: Set[str], field: str) -> None:
|
|
|
|
|
"""Add a single person value from a field."""
|
|
|
|
|
if field in source and source[field]:
|
|
|
|
|
value = source[field].strip()
|
|
|
|
|
if value:
|
|
|
|
|
persons.add(value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _add_persons(source: dict, persons: Set[str], field: str) -> None:
|
|
|
|
|
"""Add persons from a semicolon-separated field."""
|
|
|
|
|
if field in source and source[field]:
|
|
|
|
|
for person in source[field].split(";"):
|
|
|
|
|
cleaned = person.strip()
|
|
|
|
|
if cleaned:
|
|
|
|
|
persons.add(cleaned)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _add_institution(source: dict, institutions: Set[str], field: str) -> None:
|
|
|
|
|
"""Add a single institution value from a field."""
|
|
|
|
|
if field in source and source[field]:
|
|
|
|
|
value = source[field].strip()
|
|
|
|
|
if value:
|
|
|
|
|
institutions.add(value)
|
|
|
|
|
def enrich_orcids(self, persons_by_id: dict) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Fill in orcid_id on each entry in `self.persons`, given a mapping of
|
|
|
|
|
person_id -> DFGPersonPerson (or DFGPerson) for the persons involved
|
|
|
|
|
in this project
|
|
|
|
|
"""
|
|
|
|
|
for person in self.persons:
|
|
|
|
|
record = persons_by_id.get(person.person_id)
|
|
|
|
|
if record is not None:
|
|
|
|
|
person.orcid_id = getattr(record, "orcid_id", None)
|