Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ebf1df32a | ||
|
|
3645069ded | ||
|
|
977cf442a8 | ||
|
|
9b0783b80a | ||
|
|
e8c7488489 | ||
|
|
3d5ed7dd2d |
@@ -20,8 +20,8 @@ COPY service/src/data/hierarchies/I62318514/hierarchy.json \
|
|||||||
COPY service/scripts/upload_orgminer_verified_persons_ude/ \
|
COPY service/scripts/upload_orgminer_verified_persons_ude/ \
|
||||||
./service/scripts/upload_orgminer_verified_persons_ude/
|
./service/scripts/upload_orgminer_verified_persons_ude/
|
||||||
|
|
||||||
# Fail the image build if the service verification code is missing a dependency.
|
# Fail the image build if the service verification/author code is missing a dependency.
|
||||||
RUN python -c "import inse.orgminer.logic"
|
RUN python -c "import inse.orgminer.logic, inse.authors.v2.service"
|
||||||
|
|
||||||
ENTRYPOINT ["python", "/app/service/scripts/upload_orgminer_verified_persons_ude/upload_orgminer_verified_persons_ude.py", \
|
ENTRYPOINT ["python", "/app/service/scripts/upload_orgminer_verified_persons_ude/upload_orgminer_verified_persons_ude.py", \
|
||||||
"--progress-file", "/state/orgminer_verified_persons_ude_progress.json"]
|
"--progress-file", "/state/orgminer_verified_persons_ude_progress.json"]
|
||||||
|
|||||||
@@ -26,6 +26,28 @@ completed organization URI. On restart the scan resumes from that URI, skips
|
|||||||
completed organizations, and safely retries upserts if an interrupted request did
|
completed organizations, and safely retries upserts if an interrupted request did
|
||||||
not get checkpointed. Use `--progress-file PATH` to keep the checkpoint elsewhere.
|
not get checkpointed. Use `--progress-file PATH` to keep the checkpoint elsewhere.
|
||||||
|
|
||||||
|
Each document also exposes the organization context explicitly:
|
||||||
|
|
||||||
|
- `faculty`: root hierarchy node, for example `Chemie`
|
||||||
|
- `organization_type`: immediate parent label, for example `Lehrstühle` or
|
||||||
|
`Instituten`
|
||||||
|
- `organization_level`: hierarchy node type code (`leaf`, `chairs`,
|
||||||
|
`institutes`, `faculty`)
|
||||||
|
|
||||||
|
Each person document also carries the person's OpenAlex organizations, loaded
|
||||||
|
from `openalex-authors`:
|
||||||
|
|
||||||
|
- `oa_organization_ids`: deduplicated short OpenAlex organization IDs
|
||||||
|
(`I62318514`), used for filtering and joins
|
||||||
|
- `oa_organization`: deduplicated OpenAlex organization objects with `id`,
|
||||||
|
`openalex_url`, `display_name`, `ror`, `country_code`, `type`, `lineage`,
|
||||||
|
`years`, and `last_known`
|
||||||
|
|
||||||
|
`last_known_institutions` and `affiliations` are merged by institution ID;
|
||||||
|
affiliation years are unioned and institutions without an OpenAlex ID are
|
||||||
|
skipped. Missing author documents do not drop the person; the document is written
|
||||||
|
with empty institution fields and a warning is logged.
|
||||||
|
|
||||||
The script processes one organization at a time, so a run needs no concurrency
|
The script processes one organization at a time, so a run needs no concurrency
|
||||||
flags.
|
flags.
|
||||||
|
|
||||||
@@ -54,3 +76,19 @@ When configured on a background-job task, `--fresh` applies on every run, so the
|
|||||||
task always restarts from the first source organization. If the checkpoint
|
task always restarts from the first source organization. If the checkpoint
|
||||||
directory is not a mounted volume, a warning is logged because progress cannot
|
directory is not a mounted volume, a warning is logged because progress cannot
|
||||||
survive the container.
|
survive the container.
|
||||||
|
|
||||||
|
## Rebuilding after a mapping change
|
||||||
|
|
||||||
|
The script creates the output index with its mapping only when the index does
|
||||||
|
not exist. After changing the document fields, delete the old index first and
|
||||||
|
then run a full upload:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X DELETE "$ELASTICSEARCH_INSE_URL/orgminer_verified_persons_ude" \
|
||||||
|
-H "Authorization: ApiKey $ELASTICSEARCH_INSE_API_KEY"
|
||||||
|
|
||||||
|
python service/scripts/upload_orgminer_verified_persons_ude/upload_orgminer_verified_persons_ude.py --fresh
|
||||||
|
```
|
||||||
|
|
||||||
|
`--fresh` also removes the checkpoint so every source organization is processed
|
||||||
|
again.
|
||||||
|
|||||||
+277
@@ -0,0 +1,277 @@
|
|||||||
|
"""Tests for the institution projection helpers in the upload script."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import importlib.util
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
from inse.models.openalex.author import Author
|
||||||
|
from inse.models.openalex.author_affiliations_inner import AuthorAffiliationsInner
|
||||||
|
from inse.models.openalex.dehydrated_institution import DehydratedInstitution
|
||||||
|
|
||||||
|
SCRIPT_PATH = Path(__file__).with_name("upload_orgminer_verified_persons_ude.py")
|
||||||
|
_SPEC = importlib.util.spec_from_file_location(
|
||||||
|
"upload_orgminer_verified_persons_ude", SCRIPT_PATH
|
||||||
|
)
|
||||||
|
assert _SPEC and _SPEC.loader
|
||||||
|
upload = importlib.util.module_from_spec(_SPEC)
|
||||||
|
sys.modules[_SPEC.name] = upload
|
||||||
|
_SPEC.loader.exec_module(upload)
|
||||||
|
|
||||||
|
|
||||||
|
def _institution(
|
||||||
|
institution_id: str | None,
|
||||||
|
display_name: str | None,
|
||||||
|
*,
|
||||||
|
ror: str | None = None,
|
||||||
|
country_code: str | None = None,
|
||||||
|
institution_type: str | None = None,
|
||||||
|
lineage: list[str] | None = None,
|
||||||
|
) -> DehydratedInstitution:
|
||||||
|
return DehydratedInstitution(
|
||||||
|
id=institution_id,
|
||||||
|
display_name=display_name,
|
||||||
|
ror=ror,
|
||||||
|
country_code=country_code,
|
||||||
|
type=institution_type,
|
||||||
|
lineage=lineage,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_merges_last_known_and_historical_institutions() -> None:
|
||||||
|
ude_last_known = _institution(
|
||||||
|
"https://openalex.org/I62318514",
|
||||||
|
"University of Duisburg-Essen",
|
||||||
|
country_code="DE",
|
||||||
|
institution_type="education",
|
||||||
|
lineage=["https://openalex.org/I1", "https://openalex.org/I62318514"],
|
||||||
|
)
|
||||||
|
ude_affiliation = _institution(
|
||||||
|
"I62318514",
|
||||||
|
"University of Duisburg-Essen",
|
||||||
|
ror="https://ror.org/021ft7s37",
|
||||||
|
)
|
||||||
|
previous = _institution(
|
||||||
|
"https://openalex.org/I999",
|
||||||
|
"Previous University",
|
||||||
|
country_code="NL",
|
||||||
|
institution_type="education",
|
||||||
|
)
|
||||||
|
|
||||||
|
author = Author(
|
||||||
|
id="https://openalex.org/A1",
|
||||||
|
last_known_institutions=[ude_last_known],
|
||||||
|
affiliations=[
|
||||||
|
AuthorAffiliationsInner(institution=ude_affiliation, years=[2020, 2021]),
|
||||||
|
AuthorAffiliationsInner(institution=previous, years=[2017, 2018]),
|
||||||
|
AuthorAffiliationsInner(institution=ude_affiliation, years=[2019]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
institutions = upload.extract_openalex_institutions(author)
|
||||||
|
|
||||||
|
assert [item["id"] for item in institutions] == ["I62318514", "I999"]
|
||||||
|
assert institutions[0] == {
|
||||||
|
"id": "I62318514",
|
||||||
|
"openalex_url": "https://openalex.org/I62318514",
|
||||||
|
"display_name": "University of Duisburg-Essen",
|
||||||
|
"ror": "https://ror.org/021ft7s37",
|
||||||
|
"country_code": "DE",
|
||||||
|
"type": "education",
|
||||||
|
"lineage": ["https://openalex.org/I1", "https://openalex.org/I62318514"],
|
||||||
|
"years": [2019, 2020, 2021],
|
||||||
|
"last_known": True,
|
||||||
|
}
|
||||||
|
assert institutions[1]["last_known"] is False
|
||||||
|
assert institutions[1]["years"] == [2017, 2018]
|
||||||
|
assert upload.openalex_institution_ids(institutions) == ["I62318514", "I999"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_skips_institutions_without_an_openalex_id() -> None:
|
||||||
|
author = Author(
|
||||||
|
id="https://openalex.org/A1",
|
||||||
|
last_known_institutions=[
|
||||||
|
_institution(None, "Unknown Institute"),
|
||||||
|
_institution("", "Empty Id Institute"),
|
||||||
|
],
|
||||||
|
affiliations=[
|
||||||
|
AuthorAffiliationsInner(
|
||||||
|
institution=_institution("I123", "Known Institute"),
|
||||||
|
years=[2021],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
institutions = upload.extract_openalex_institutions(author)
|
||||||
|
|
||||||
|
assert [item["id"] for item in institutions] == ["I123"]
|
||||||
|
assert institutions[0]["last_known"] is False
|
||||||
|
assert institutions[0]["years"] == [2021]
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_handles_missing_author_and_empty_institutions() -> None:
|
||||||
|
assert upload.extract_openalex_institutions(None) == []
|
||||||
|
assert (
|
||||||
|
upload.extract_openalex_institutions(Author(id="https://openalex.org/A1"))
|
||||||
|
== []
|
||||||
|
)
|
||||||
|
assert upload.openalex_institution_ids([]) == []
|
||||||
|
|
||||||
|
|
||||||
|
def _node(
|
||||||
|
name: str,
|
||||||
|
*,
|
||||||
|
node_type: str,
|
||||||
|
link: str | None = None,
|
||||||
|
children: list[SimpleNamespace] | None = None,
|
||||||
|
) -> SimpleNamespace:
|
||||||
|
return SimpleNamespace(
|
||||||
|
name_de=name,
|
||||||
|
name_en=None,
|
||||||
|
link_de=link,
|
||||||
|
link_en=None,
|
||||||
|
type=node_type,
|
||||||
|
children=children or [],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_organization_details_splits_faculty_type_and_organization() -> None:
|
||||||
|
hierarchy = [
|
||||||
|
_node(
|
||||||
|
"Chemie",
|
||||||
|
node_type="faculty",
|
||||||
|
link="https://example.org/chemie",
|
||||||
|
children=[
|
||||||
|
_node(
|
||||||
|
"Lehrstühle",
|
||||||
|
node_type="chairs",
|
||||||
|
link="https://example.org/chemie/lehrstuehle",
|
||||||
|
children=[
|
||||||
|
_node(
|
||||||
|
"Applied Analytical Chemistry",
|
||||||
|
node_type="leaf",
|
||||||
|
link="https://example.org/chemie/aac",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
lookup = upload.build_hierarchy_lookup(hierarchy)
|
||||||
|
|
||||||
|
details = upload.organization_details(
|
||||||
|
{"uri": "https://example.org/chemie/aac"}, lookup
|
||||||
|
)
|
||||||
|
|
||||||
|
assert details.faculty == "Chemie"
|
||||||
|
assert details.organization_type == "Lehrstühle"
|
||||||
|
assert details.name == "Applied Analytical Chemistry"
|
||||||
|
assert details.organization_level == "leaf"
|
||||||
|
assert details.hierarchy_path == [
|
||||||
|
"Chemie",
|
||||||
|
"Lehrstühle",
|
||||||
|
"Applied Analytical Chemistry",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_organization_details_uses_immediate_parent_for_deep_paths() -> None:
|
||||||
|
hierarchy = [
|
||||||
|
_node(
|
||||||
|
"Chemie",
|
||||||
|
node_type="faculty",
|
||||||
|
link="https://example.org/chemie",
|
||||||
|
children=[
|
||||||
|
_node(
|
||||||
|
"Instituten",
|
||||||
|
node_type="institutes",
|
||||||
|
link="https://example.org/chemie/institute",
|
||||||
|
children=[
|
||||||
|
_node(
|
||||||
|
"ACTIVE SITES",
|
||||||
|
node_type="leaf",
|
||||||
|
link="https://example.org/chemie/active-sites",
|
||||||
|
children=[
|
||||||
|
_node(
|
||||||
|
"Lehrstühle",
|
||||||
|
node_type="chairs",
|
||||||
|
link="https://example.org/chemie/active-sites/chairs",
|
||||||
|
children=[
|
||||||
|
_node(
|
||||||
|
"Applied Analytical Chemistry",
|
||||||
|
node_type="leaf",
|
||||||
|
link="https://example.org/chemie/active-sites/aac",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
lookup = upload.build_hierarchy_lookup(hierarchy)
|
||||||
|
|
||||||
|
details = upload.organization_details(
|
||||||
|
{"uri": "https://example.org/chemie/active-sites/aac"}, lookup
|
||||||
|
)
|
||||||
|
|
||||||
|
assert details.faculty == "Chemie"
|
||||||
|
assert details.organization_type == "Lehrstühle"
|
||||||
|
assert details.name == "Applied Analytical Chemistry"
|
||||||
|
|
||||||
|
|
||||||
|
def test_organization_details_describes_aggregator_nodes() -> None:
|
||||||
|
hierarchy = [
|
||||||
|
_node(
|
||||||
|
"Chemie",
|
||||||
|
node_type="faculty",
|
||||||
|
link="https://example.org/chemie",
|
||||||
|
children=[
|
||||||
|
_node(
|
||||||
|
"Lehrstühle",
|
||||||
|
node_type="chairs",
|
||||||
|
link="https://example.org/chemie/lehrstuehle",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
lookup = upload.build_hierarchy_lookup(hierarchy)
|
||||||
|
|
||||||
|
details = upload.organization_details(
|
||||||
|
{"uri": "https://example.org/chemie/lehrstuehle"}, lookup
|
||||||
|
)
|
||||||
|
|
||||||
|
assert details.faculty == "Chemie"
|
||||||
|
assert details.organization_type == "Lehrstühle"
|
||||||
|
assert details.name == "Lehrstühle"
|
||||||
|
assert details.organization_level == "chairs"
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_merges_lineage_and_metadata_from_multiple_sources() -> None:
|
||||||
|
author = Author(
|
||||||
|
id="https://openalex.org/A1",
|
||||||
|
last_known_institutions=[
|
||||||
|
_institution("I42", "Example University", lineage=["I1"])
|
||||||
|
],
|
||||||
|
affiliations=[
|
||||||
|
AuthorAffiliationsInner(
|
||||||
|
institution=_institution(
|
||||||
|
"I42",
|
||||||
|
"Example University",
|
||||||
|
ror="https://ror.org/example",
|
||||||
|
lineage=["I1", "I42"],
|
||||||
|
),
|
||||||
|
years=[2022],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
institutions = upload.extract_openalex_institutions(author)
|
||||||
|
|
||||||
|
assert len(institutions) == 1
|
||||||
|
assert institutions[0]["ror"] == "https://ror.org/example"
|
||||||
|
assert institutions[0]["lineage"] == ["I1", "I42"]
|
||||||
|
assert institutions[0]["years"] == [2022]
|
||||||
+413
-20
@@ -6,9 +6,10 @@ For every organization in the UDE organization-content index (one at a time):
|
|||||||
|
|
||||||
1. READ the organization and its staff list from Elasticsearch (INSE)
|
1. READ the organization and its staff list from Elasticsearch (INSE)
|
||||||
2. VERIFY each staff member against the collaboration graph (OpenAlex)
|
2. VERIFY each staff member against the collaboration graph (OpenAlex)
|
||||||
3. BUILD one document per (organization, OpenAlex person)
|
3. LOOK UP each verified person's OpenAlex institutions by author ID
|
||||||
4. UPLOAD the documents to ``orgminer_verified_persons_ude`` (bulk upsert)
|
4. BUILD one document per (organization, OpenAlex person)
|
||||||
5. CHECKPOINT the organization as done in a small JSON progress file
|
5. UPLOAD the documents to ``orgminer_verified_persons_ude`` (bulk upsert)
|
||||||
|
6. CHECKPOINT the organization as done in a small JSON progress file
|
||||||
|
|
||||||
Everything runs sequentially: one organization at a time, one graph query at a
|
Everything runs sequentially: one organization at a time, one graph query at a
|
||||||
time.
|
time.
|
||||||
@@ -54,16 +55,34 @@ SERVICE_DIR = Path(__file__).resolve().parents[2]
|
|||||||
sys.path.insert(0, str(SERVICE_DIR / "src" / "main"))
|
sys.path.insert(0, str(SERVICE_DIR / "src" / "main"))
|
||||||
|
|
||||||
from inse import config # noqa: E402
|
from inse import config # noqa: E402
|
||||||
|
from inse.authors.v2.service import get_author_by_id, search_authors # noqa: E402
|
||||||
|
from inse.exceptions import NotFoundException # noqa: E402
|
||||||
from inse.model import ESIndex # noqa: E402
|
from inse.model import ESIndex # noqa: E402
|
||||||
|
from inse.models.openalex.author import Author # noqa: E402
|
||||||
from inse.orgminer import logic # noqa: E402
|
from inse.orgminer import logic # noqa: E402
|
||||||
from inse.orgminer.institutions_helper import ( # noqa: E402
|
from inse.orgminer.institutions_helper import ( # noqa: E402
|
||||||
DEFAULT_INSTITUTION_ID,
|
DEFAULT_INSTITUTION_ID,
|
||||||
|
full_institution_url,
|
||||||
normalize_org_uri,
|
normalize_org_uri,
|
||||||
|
strip_openalex_prefix,
|
||||||
)
|
)
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
Hit = dict[str, Any] # one Elasticsearch search hit
|
Hit = dict[str, Any] # one Elasticsearch search hit
|
||||||
HierarchyLookup = dict[str, tuple[str, list[str]]] # uri -> (name, path from root)
|
# uri -> (display name, path from root, hierarchy node type)
|
||||||
|
HierarchyLookup = dict[str, tuple[str, list[str], str | None]]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class OrganizationDetails:
|
||||||
|
"""Explicit organization context for downstream predictions."""
|
||||||
|
|
||||||
|
name: str
|
||||||
|
uri: str | None
|
||||||
|
hierarchy_path: list[str]
|
||||||
|
faculty: str | None
|
||||||
|
organization_type: str | None
|
||||||
|
organization_level: str | None
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@@ -92,6 +111,17 @@ RETRYABLE_STATUS = {429, 502, 503, 504}
|
|||||||
# Collab-graph queries per organization. Kept at 1: fully sequential.
|
# Collab-graph queries per organization. Kept at 1: fully sequential.
|
||||||
GRAPH_QUERIES_AT_A_TIME = 1
|
GRAPH_QUERIES_AT_A_TIME = 1
|
||||||
|
|
||||||
|
# Author institution lookups. Batched by ID, with per-person fallbacks for
|
||||||
|
# installations whose author documents use a different `_id` convention.
|
||||||
|
AUTHOR_LOOKUP_BATCH_SIZE = 100
|
||||||
|
AUTHOR_SOURCE_FIELDS = [
|
||||||
|
"id",
|
||||||
|
"display_name",
|
||||||
|
"orcid",
|
||||||
|
"last_known_institutions",
|
||||||
|
"affiliations",
|
||||||
|
]
|
||||||
|
|
||||||
PROGRESS_SAVE_INTERVAL_S = 5.0
|
PROGRESS_SAVE_INTERVAL_S = 5.0
|
||||||
PROGRESS_LOG_INTERVAL_S = 30.0
|
PROGRESS_LOG_INTERVAL_S = 30.0
|
||||||
|
|
||||||
@@ -99,10 +129,32 @@ INDEX_MAPPING = {
|
|||||||
"dynamic": "strict",
|
"dynamic": "strict",
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
|
"name": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
|
||||||
"org_name": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
|
"organization": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
|
||||||
"org_uri": {"type": "keyword"},
|
"org_uri": {"type": "keyword"},
|
||||||
"org_hierarchy_path": {"type": "keyword"},
|
"org_hierarchy_path": {"type": "keyword"},
|
||||||
|
"faculty": {"type": "keyword"},
|
||||||
|
"organization_type": {"type": "keyword"},
|
||||||
|
"organization_level": {"type": "keyword"},
|
||||||
"openalex_id": {"type": "keyword"},
|
"openalex_id": {"type": "keyword"},
|
||||||
|
"oa_organization_ids": {"type": "keyword"},
|
||||||
|
"oa_organization": {
|
||||||
|
"type": "nested",
|
||||||
|
"dynamic": False,
|
||||||
|
"properties": {
|
||||||
|
"id": {"type": "keyword"},
|
||||||
|
"openalex_url": {"type": "keyword"},
|
||||||
|
"display_name": {
|
||||||
|
"type": "text",
|
||||||
|
"fields": {"keyword": {"type": "keyword"}},
|
||||||
|
},
|
||||||
|
"ror": {"type": "keyword"},
|
||||||
|
"country_code": {"type": "keyword"},
|
||||||
|
"type": {"type": "keyword"},
|
||||||
|
"lineage": {"type": "keyword"},
|
||||||
|
"years": {"type": "integer"},
|
||||||
|
"last_known": {"type": "boolean"},
|
||||||
|
},
|
||||||
|
},
|
||||||
# Kept verbatim in _source; staff dicts vary, so don't index them.
|
# Kept verbatim in _source; staff dicts vary, so don't index them.
|
||||||
"staff": {"type": "object", "dynamic": False},
|
"staff": {"type": "object", "dynamic": False},
|
||||||
"staff_entries": {"type": "object", "dynamic": False},
|
"staff_entries": {"type": "object", "dynamic": False},
|
||||||
@@ -218,6 +270,10 @@ class Stats:
|
|||||||
person_docs: int = 0
|
person_docs: int = 0
|
||||||
uploaded: int = 0
|
uploaded: int = 0
|
||||||
doc_errors: int = 0
|
doc_errors: int = 0
|
||||||
|
authors_requested: int = 0
|
||||||
|
authors_found: int = 0
|
||||||
|
authors_missing: int = 0
|
||||||
|
persons_with_institutions: int = 0
|
||||||
started: float = field(default_factory=time.monotonic)
|
started: float = field(default_factory=time.monotonic)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -229,6 +285,9 @@ class Stats:
|
|||||||
f"scanned={self.scanned} orgs_done={self.orgs_done} "
|
f"scanned={self.scanned} orgs_done={self.orgs_done} "
|
||||||
f"orgs_failed={self.orgs_failed} person_docs={self.person_docs} "
|
f"orgs_failed={self.orgs_failed} person_docs={self.person_docs} "
|
||||||
f"uploaded={self.uploaded} doc_errors={self.doc_errors} "
|
f"uploaded={self.uploaded} doc_errors={self.doc_errors} "
|
||||||
|
f"author_lookups={self.authors_found}/{self.authors_requested} "
|
||||||
|
f"authors_missing={self.authors_missing} "
|
||||||
|
f"persons_with_institutions={self.persons_with_institutions} "
|
||||||
f"elapsed={time.monotonic() - self.started:.0f}s"
|
f"elapsed={time.monotonic() - self.started:.0f}s"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -420,22 +479,128 @@ async def scan_organizations(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Step 2b: LOOK UP author documents for institution metadata
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_author_id(value: str | None) -> str | None:
|
||||||
|
"""Return the short OpenAlex author ID, accepting raw and URL forms."""
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
normalized = strip_openalex_prefix(value.strip()).strip()
|
||||||
|
return normalized or None
|
||||||
|
|
||||||
|
|
||||||
|
async def _lookup_single_author(short_id: str) -> Author | None:
|
||||||
|
"""Fetch one author, tolerating the different author-document ID schemes.
|
||||||
|
|
||||||
|
The batch lookup normally finds the document through the ``id`` field.
|
||||||
|
This fallback handles documents that only expose the short ``_id`` (direct
|
||||||
|
get) or that are reachable only through a search on ``_id``.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
author = await get_author_by_id(short_id)
|
||||||
|
except NotFoundException:
|
||||||
|
author = None
|
||||||
|
if author is not None:
|
||||||
|
return author
|
||||||
|
|
||||||
|
async def _search_by_id() -> Any:
|
||||||
|
return await search_authors(
|
||||||
|
page=0,
|
||||||
|
size=1,
|
||||||
|
query={
|
||||||
|
"terms": {
|
||||||
|
"_id": [
|
||||||
|
short_id,
|
||||||
|
f"https://openalex.org/{short_id}",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
source=AUTHOR_SOURCE_FIELDS,
|
||||||
|
)
|
||||||
|
|
||||||
|
page = await retry_async(
|
||||||
|
_search_by_id,
|
||||||
|
description=f"Author search for {short_id}",
|
||||||
|
)
|
||||||
|
return page.elements[0] if page.elements else None
|
||||||
|
|
||||||
|
|
||||||
|
async def fetch_authors_by_ids(openalex_ids: Iterable[str]) -> dict[str, Author]:
|
||||||
|
"""Return ``{short_author_id.casefold(): Author}`` for the requested IDs.
|
||||||
|
|
||||||
|
Uses one batched ``id``-terms query per chunk, then a per-person fallback
|
||||||
|
for documents the batch query did not return. Missing authors are omitted
|
||||||
|
so the caller can still write the person document with empty institutions.
|
||||||
|
"""
|
||||||
|
normalized = sorted(
|
||||||
|
{
|
||||||
|
short_id
|
||||||
|
for value in openalex_ids
|
||||||
|
if (short_id := normalize_author_id(value)) is not None
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if not normalized:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
authors: dict[str, Author] = {}
|
||||||
|
for start in range(0, len(normalized), AUTHOR_LOOKUP_BATCH_SIZE):
|
||||||
|
chunk = normalized[start : start + AUTHOR_LOOKUP_BATCH_SIZE]
|
||||||
|
id_terms: list[str] = []
|
||||||
|
for short_id in chunk:
|
||||||
|
id_terms.extend([short_id, f"https://openalex.org/{short_id}"])
|
||||||
|
|
||||||
|
async def _search_batch() -> Any:
|
||||||
|
return await search_authors(
|
||||||
|
page=0,
|
||||||
|
size=len(chunk),
|
||||||
|
query={"terms": {"id": id_terms}},
|
||||||
|
source=AUTHOR_SOURCE_FIELDS,
|
||||||
|
)
|
||||||
|
|
||||||
|
page = await retry_async(
|
||||||
|
_search_batch,
|
||||||
|
description=f"Batch author lookup ({len(chunk)} ids)",
|
||||||
|
)
|
||||||
|
for author in page.elements:
|
||||||
|
author_id = normalize_author_id(author.id)
|
||||||
|
if author_id:
|
||||||
|
authors[author_id.casefold()] = author
|
||||||
|
|
||||||
|
for short_id in chunk:
|
||||||
|
key = short_id.casefold()
|
||||||
|
if key in authors:
|
||||||
|
continue
|
||||||
|
author = await _lookup_single_author(short_id)
|
||||||
|
if author is not None:
|
||||||
|
authors[key] = author
|
||||||
|
|
||||||
|
return authors
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Step 3: BUILD one document per (organization, OpenAlex person)
|
# Step 3: BUILD one document per (organization, OpenAlex person)
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
|
|
||||||
def build_hierarchy_lookup(hierarchy: Iterable[Any]) -> HierarchyLookup:
|
def build_hierarchy_lookup(hierarchy: Iterable[Any]) -> HierarchyLookup:
|
||||||
"""Map normalized organization links to (display name, path from the root)."""
|
"""Map normalized links to (display name, path, hierarchy node type)."""
|
||||||
lookup: HierarchyLookup = {}
|
lookup: HierarchyLookup = {}
|
||||||
|
|
||||||
def visit(node: Any, ancestors: list[str]) -> None:
|
def visit(node: Any, ancestors: list[str]) -> None:
|
||||||
name = getattr(node, "name_de", None) or getattr(node, "name_en", None)
|
name = getattr(node, "name_de", None) or getattr(node, "name_en", None)
|
||||||
path = [*ancestors, name] if name else ancestors
|
path = [*ancestors, name] if name else ancestors
|
||||||
|
node_type = getattr(node, "type", None)
|
||||||
if name:
|
if name:
|
||||||
for link in (getattr(node, "link_de", None), getattr(node, "link_en", None)):
|
for link in (getattr(node, "link_de", None), getattr(node, "link_en", None)):
|
||||||
if normalized := normalize_org_uri(link):
|
if normalized := normalize_org_uri(link):
|
||||||
lookup[normalized] = (name, path)
|
lookup[normalized] = (
|
||||||
|
name,
|
||||||
|
path,
|
||||||
|
node_type if isinstance(node_type, str) else None,
|
||||||
|
)
|
||||||
for child in getattr(node, "children", None) or []:
|
for child in getattr(node, "children", None) or []:
|
||||||
visit(child, path)
|
visit(child, path)
|
||||||
|
|
||||||
@@ -446,11 +611,19 @@ def build_hierarchy_lookup(hierarchy: Iterable[Any]) -> HierarchyLookup:
|
|||||||
|
|
||||||
def organization_details(
|
def organization_details(
|
||||||
source: dict[str, Any], hierarchy_lookup: HierarchyLookup
|
source: dict[str, Any], hierarchy_lookup: HierarchyLookup
|
||||||
) -> tuple[str, list[str], str | None]:
|
) -> OrganizationDetails:
|
||||||
"""Return (org name, hierarchy path, org URI), with fallbacks for the name."""
|
"""Build explicit faculty / type / organization fields for a source org.
|
||||||
|
|
||||||
|
For a leaf such as ``Chemie > Lehrstühle > Applied Analytical Chemistry``
|
||||||
|
this yields ``faculty=Chemie``, ``organization_type=Lehrstühle`` and
|
||||||
|
``organization=Applied Analytical Chemistry``. Deeper paths still use the
|
||||||
|
immediate parent as the type, so ``Chemie > Instituten > ACTIVE SITES >
|
||||||
|
Lehrstühle > Applied Analytical Chemistry`` also yields
|
||||||
|
``organization_type=Lehrstühle``.
|
||||||
|
"""
|
||||||
org_uri = source.get("uri")
|
org_uri = source.get("uri")
|
||||||
hierarchy_name, hierarchy_path = hierarchy_lookup.get(
|
hierarchy_name, hierarchy_path, node_type = hierarchy_lookup.get(
|
||||||
normalize_org_uri(org_uri) or "", ("", [])
|
normalize_org_uri(org_uri) or "", ("", [], None)
|
||||||
)
|
)
|
||||||
org_name = (
|
org_name = (
|
||||||
source.get("org_name")
|
source.get("org_name")
|
||||||
@@ -460,7 +633,35 @@ def organization_details(
|
|||||||
or org_uri
|
or org_uri
|
||||||
or "Unknown organization"
|
or "Unknown organization"
|
||||||
)
|
)
|
||||||
return str(org_name), hierarchy_path, org_uri
|
org_name = str(org_name)
|
||||||
|
|
||||||
|
organization_name = hierarchy_path[-1] if hierarchy_path else org_name
|
||||||
|
if node_type in {"chairs", "institutes", "faculty"}:
|
||||||
|
# Aggregator/faculty documents describe themselves rather than a child.
|
||||||
|
organization_type = organization_name
|
||||||
|
elif len(hierarchy_path) >= 2:
|
||||||
|
organization_type = hierarchy_path[-2]
|
||||||
|
else:
|
||||||
|
organization_type = None
|
||||||
|
|
||||||
|
faculty = hierarchy_path[0] if hierarchy_path else None
|
||||||
|
if not faculty:
|
||||||
|
fallback_faculty = (
|
||||||
|
source.get("faculty_de")
|
||||||
|
or source.get("faculty_en")
|
||||||
|
or source.get("faculty")
|
||||||
|
)
|
||||||
|
faculty = fallback_faculty.strip() if isinstance(fallback_faculty, str) else None
|
||||||
|
faculty = faculty or None
|
||||||
|
|
||||||
|
return OrganizationDetails(
|
||||||
|
name=org_name,
|
||||||
|
uri=org_uri,
|
||||||
|
hierarchy_path=hierarchy_path,
|
||||||
|
faculty=faculty,
|
||||||
|
organization_type=organization_type,
|
||||||
|
organization_level=node_type,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def stable_document_id(org_uri: str | None, org_doc_id: str, openalex_id: str) -> str:
|
def stable_document_id(org_uri: str | None, org_doc_id: str, openalex_id: str) -> str:
|
||||||
@@ -473,19 +674,145 @@ def _canonical(value: Any) -> str:
|
|||||||
return json.dumps(value, sort_keys=True, ensure_ascii=False, default=str)
|
return json.dumps(value, sort_keys=True, ensure_ascii=False, default=str)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# OpenAlex institution projection
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
INSTITUTION_METADATA_FIELDS = ("display_name", "ror", "country_code", "type")
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_institution_id(value: Any) -> str | None:
|
||||||
|
"""Return the raw OpenAlex institution ID, accepting short and URL forms."""
|
||||||
|
if not isinstance(value, str):
|
||||||
|
return None
|
||||||
|
normalized = strip_openalex_prefix(value.strip()).strip()
|
||||||
|
return normalized or None
|
||||||
|
|
||||||
|
|
||||||
|
def _merge_text(record: dict[str, Any], key: str, value: Any) -> None:
|
||||||
|
if not isinstance(value, str):
|
||||||
|
return
|
||||||
|
value = value.strip()
|
||||||
|
if value and not record.get(key):
|
||||||
|
record[key] = value
|
||||||
|
|
||||||
|
|
||||||
|
def _merge_lineage(record: dict[str, Any], lineage: Any) -> None:
|
||||||
|
if not isinstance(lineage, list):
|
||||||
|
return
|
||||||
|
merged: list[str] = list(record.get("lineage") or [])
|
||||||
|
for item in lineage:
|
||||||
|
if not isinstance(item, str):
|
||||||
|
continue
|
||||||
|
item = item.strip()
|
||||||
|
if item and item not in merged:
|
||||||
|
merged.append(item)
|
||||||
|
if merged:
|
||||||
|
record["lineage"] = merged
|
||||||
|
|
||||||
|
|
||||||
|
def _merge_years(record: dict[str, Any], years: Any) -> None:
|
||||||
|
if not isinstance(years, list):
|
||||||
|
return
|
||||||
|
merged = {int(year) for year in record.get("years") or []}
|
||||||
|
for year in years:
|
||||||
|
try:
|
||||||
|
merged.add(int(year))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
continue
|
||||||
|
record["years"] = sorted(merged)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_openalex_institutions(author: Author | None) -> list[dict[str, Any]]:
|
||||||
|
"""Return deduplicated OpenAlex institutions for one author.
|
||||||
|
|
||||||
|
``last_known_institutions`` and ``affiliations[].institution`` are merged
|
||||||
|
by OpenAlex institution ID. Affiliation years are unioned and institutions
|
||||||
|
without an OpenAlex ID are skipped. Last-known institutions come first.
|
||||||
|
"""
|
||||||
|
if author is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
by_id: dict[str, dict[str, Any]] = {}
|
||||||
|
|
||||||
|
def record_for(institution: Any) -> dict[str, Any] | None:
|
||||||
|
if institution is None:
|
||||||
|
return None
|
||||||
|
short_id = normalize_institution_id(getattr(institution, "id", None))
|
||||||
|
if not short_id:
|
||||||
|
return None
|
||||||
|
|
||||||
|
key = short_id.casefold()
|
||||||
|
record = by_id.get(key)
|
||||||
|
if record is None:
|
||||||
|
record = {
|
||||||
|
"id": short_id,
|
||||||
|
"openalex_url": full_institution_url(short_id),
|
||||||
|
"display_name": None,
|
||||||
|
"ror": None,
|
||||||
|
"country_code": None,
|
||||||
|
"type": None,
|
||||||
|
"lineage": [],
|
||||||
|
"years": [],
|
||||||
|
"last_known": False,
|
||||||
|
}
|
||||||
|
by_id[key] = record
|
||||||
|
|
||||||
|
for field in INSTITUTION_METADATA_FIELDS:
|
||||||
|
_merge_text(record, field, getattr(institution, field, None))
|
||||||
|
_merge_lineage(record, getattr(institution, "lineage", None))
|
||||||
|
return record
|
||||||
|
|
||||||
|
for institution in author.last_known_institutions or []:
|
||||||
|
record = record_for(institution)
|
||||||
|
if record is not None:
|
||||||
|
record["last_known"] = True
|
||||||
|
|
||||||
|
for affiliation in author.affiliations or []:
|
||||||
|
record = record_for(getattr(affiliation, "institution", None))
|
||||||
|
if record is not None:
|
||||||
|
_merge_years(record, getattr(affiliation, "years", None))
|
||||||
|
|
||||||
|
return sorted(
|
||||||
|
by_id.values(),
|
||||||
|
key=lambda item: (
|
||||||
|
not item["last_known"],
|
||||||
|
(item.get("display_name") or "").casefold(),
|
||||||
|
item["id"].casefold(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def openalex_institution_ids(institutions: Iterable[dict[str, Any]]) -> list[str]:
|
||||||
|
"""Return the deduplicated short institution IDs in stable order."""
|
||||||
|
seen: set[str] = set()
|
||||||
|
ids: list[str] = []
|
||||||
|
for institution in institutions:
|
||||||
|
short_id = normalize_institution_id(institution.get("id"))
|
||||||
|
if not short_id:
|
||||||
|
continue
|
||||||
|
key = short_id.casefold()
|
||||||
|
if key in seen:
|
||||||
|
continue
|
||||||
|
seen.add(key)
|
||||||
|
ids.append(short_id)
|
||||||
|
return ids
|
||||||
|
|
||||||
|
|
||||||
def make_person_documents(
|
def make_person_documents(
|
||||||
source: dict[str, Any],
|
source: dict[str, Any],
|
||||||
source_doc_id: str,
|
source_doc_id: str,
|
||||||
verified_entries: list[dict[str, Any]],
|
verified_entries: list[dict[str, Any]],
|
||||||
hierarchy_lookup: HierarchyLookup,
|
hierarchy_lookup: HierarchyLookup,
|
||||||
verified_at: str,
|
verified_at: str,
|
||||||
|
authors_by_id: dict[str, Author],
|
||||||
) -> list[tuple[str, Hit]]:
|
) -> list[tuple[str, Hit]]:
|
||||||
"""Turn verified staff entries into [(doc_id, document)], one per OpenAlex person.
|
"""Turn verified staff entries into [(doc_id, document)], one per OpenAlex person.
|
||||||
|
|
||||||
A person may be matched by several staff entries and several collaborators,
|
A person may be matched by several staff entries and several collaborators,
|
||||||
so entries and evidence are de-duplicated per person first.
|
so entries and evidence are de-duplicated per person first.
|
||||||
"""
|
"""
|
||||||
org_name, hierarchy_path, org_uri = organization_details(source, hierarchy_lookup)
|
details = organization_details(source, hierarchy_lookup)
|
||||||
|
|
||||||
# openalex_id -> {canonical staff json -> staff dict}
|
# openalex_id -> {canonical staff json -> staff dict}
|
||||||
staff_by_person: dict[str, dict[str, dict[str, Any]]] = {}
|
staff_by_person: dict[str, dict[str, dict[str, Any]]] = {}
|
||||||
@@ -507,12 +834,20 @@ def make_person_documents(
|
|||||||
for openalex_id, staff_map in staff_by_person.items():
|
for openalex_id, staff_map in staff_by_person.items():
|
||||||
staff_entries = list(staff_map.values())
|
staff_entries = list(staff_map.values())
|
||||||
primary_staff = staff_entries[0]
|
primary_staff = staff_entries[0]
|
||||||
|
author_id = normalize_author_id(openalex_id)
|
||||||
|
author = authors_by_id.get(author_id.casefold()) if author_id else None
|
||||||
|
institutions = extract_openalex_institutions(author)
|
||||||
document = {
|
document = {
|
||||||
"name": primary_staff.get("name"),
|
"name": primary_staff.get("name"),
|
||||||
"org_name": org_name,
|
"organization": details.name,
|
||||||
"org_uri": org_uri,
|
"org_uri": details.uri,
|
||||||
"org_hierarchy_path": hierarchy_path,
|
"org_hierarchy_path": details.hierarchy_path,
|
||||||
|
"faculty": details.faculty,
|
||||||
|
"organization_type": details.organization_type,
|
||||||
|
"organization_level": details.organization_level,
|
||||||
"openalex_id": openalex_id,
|
"openalex_id": openalex_id,
|
||||||
|
"oa_organization_ids": openalex_institution_ids(institutions),
|
||||||
|
"oa_organization": institutions,
|
||||||
"staff": primary_staff,
|
"staff": primary_staff,
|
||||||
"staff_entries": staff_entries,
|
"staff_entries": staff_entries,
|
||||||
"source_index": SOURCE_INDEX,
|
"source_index": SOURCE_INDEX,
|
||||||
@@ -521,7 +856,7 @@ def make_person_documents(
|
|||||||
"verification_evidence": list(evidence_by_person[openalex_id].values()),
|
"verification_evidence": list(evidence_by_person[openalex_id].values()),
|
||||||
"verified_at": verified_at,
|
"verified_at": verified_at,
|
||||||
}
|
}
|
||||||
doc_id = stable_document_id(org_uri, source_doc_id, openalex_id)
|
doc_id = stable_document_id(details.uri, source_doc_id, openalex_id)
|
||||||
documents.append((doc_id, document))
|
documents.append((doc_id, document))
|
||||||
return documents
|
return documents
|
||||||
|
|
||||||
@@ -537,7 +872,28 @@ async def ensure_output_index(
|
|||||||
"""Create the output index with its mapping if it doesn't exist yet."""
|
"""Create the output index with its mapping if it doesn't exist yet."""
|
||||||
head = await client.head(f"{url}/{OUTPUT_INDEX}", headers=headers)
|
head = await client.head(f"{url}/{OUTPUT_INDEX}", headers=headers)
|
||||||
if head.status_code == 200:
|
if head.status_code == 200:
|
||||||
logger.info("Output index %r already exists.", OUTPUT_INDEX)
|
mapping_response = await client.get(
|
||||||
|
f"{url}/{OUTPUT_INDEX}/_mapping", headers=headers
|
||||||
|
)
|
||||||
|
mapping_response.raise_for_status()
|
||||||
|
properties = (
|
||||||
|
mapping_response.json()
|
||||||
|
.get(OUTPUT_INDEX, {})
|
||||||
|
.get("mappings", {})
|
||||||
|
.get("properties", {})
|
||||||
|
)
|
||||||
|
missing_fields = [
|
||||||
|
field
|
||||||
|
for field in ("oa_organization_ids", "oa_organization")
|
||||||
|
if field not in properties
|
||||||
|
]
|
||||||
|
if missing_fields:
|
||||||
|
raise SystemExit(
|
||||||
|
f"Output index {OUTPUT_INDEX!r} already exists but is missing "
|
||||||
|
f"{missing_fields}. Delete the index before uploading the new "
|
||||||
|
"schema, or choose a different OUTPUT_INDEX."
|
||||||
|
)
|
||||||
|
logger.info("Output index %r already exists with the current schema.", OUTPUT_INDEX)
|
||||||
return
|
return
|
||||||
if head.status_code != 404:
|
if head.status_code != 404:
|
||||||
head.raise_for_status()
|
head.raise_for_status()
|
||||||
@@ -696,18 +1052,55 @@ async def process_organization(hit: Hit, ctx: Context) -> bool:
|
|||||||
description=f"Collab-graph verification for {label}",
|
description=f"Collab-graph verification for {label}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Step 2b: load OpenAlex author documents for institution metadata.
|
||||||
|
requested_author_ids = {
|
||||||
|
short_id
|
||||||
|
for entry in verified_entries
|
||||||
|
for openalex_id in entry["openalex_ids"]
|
||||||
|
if (short_id := normalize_author_id(openalex_id)) is not None
|
||||||
|
}
|
||||||
|
authors_by_id = await fetch_authors_by_ids(requested_author_ids)
|
||||||
|
found_author_ids = {
|
||||||
|
short_id
|
||||||
|
for short_id in requested_author_ids
|
||||||
|
if short_id.casefold() in authors_by_id
|
||||||
|
}
|
||||||
|
missing_author_ids = requested_author_ids - found_author_ids
|
||||||
|
ctx.stats.authors_requested += len(requested_author_ids)
|
||||||
|
ctx.stats.authors_found += len(found_author_ids)
|
||||||
|
ctx.stats.authors_missing += len(missing_author_ids)
|
||||||
|
if missing_author_ids:
|
||||||
|
logger.warning(
|
||||||
|
"No OpenAlex author document for %d verified person(s) in %s: %s",
|
||||||
|
len(missing_author_ids),
|
||||||
|
label,
|
||||||
|
", ".join(sorted(missing_author_ids)),
|
||||||
|
)
|
||||||
|
|
||||||
# Step 3: build one document per OpenAlex person.
|
# Step 3: build one document per OpenAlex person.
|
||||||
documents = make_person_documents(
|
documents = make_person_documents(
|
||||||
source, doc_id, verified_entries, ctx.hierarchy_lookup, ctx.verified_at
|
source,
|
||||||
|
doc_id,
|
||||||
|
verified_entries,
|
||||||
|
ctx.hierarchy_lookup,
|
||||||
|
ctx.verified_at,
|
||||||
|
authors_by_id,
|
||||||
)
|
)
|
||||||
ctx.stats.person_docs += len(documents)
|
ctx.stats.person_docs += len(documents)
|
||||||
|
ctx.stats.persons_with_institutions += sum(
|
||||||
|
1 for _, document in documents if document.get("oa_organization")
|
||||||
|
)
|
||||||
|
|
||||||
if ctx.dry_run:
|
if ctx.dry_run:
|
||||||
logger.info(
|
logger.info(
|
||||||
"DRY RUN org=%s verified_staff=%d person_org_docs=%d",
|
"DRY RUN org=%s verified_staff=%d person_org_docs=%d "
|
||||||
|
"authors=%d/%d missing=%d",
|
||||||
label,
|
label,
|
||||||
len(verified_entries),
|
len(verified_entries),
|
||||||
len(documents),
|
len(documents),
|
||||||
|
len(found_author_ids),
|
||||||
|
len(requested_author_ids),
|
||||||
|
len(missing_author_ids),
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ VERIFIED_PERSONS_INDEX = "orgminer_verified_persons_ude"
|
|||||||
VERIFIED_PERSONS_INSTITUTION_ID = DEFAULT_INSTITUTION_ID
|
VERIFIED_PERSONS_INSTITUTION_ID = DEFAULT_INSTITUTION_ID
|
||||||
VERIFIED_PERSON_FIELDS = [
|
VERIFIED_PERSON_FIELDS = [
|
||||||
"openalex_id",
|
"openalex_id",
|
||||||
"org_name",
|
"organization",
|
||||||
"org_uri",
|
"org_uri",
|
||||||
"org_hierarchy_path",
|
"org_hierarchy_path",
|
||||||
"verified_at",
|
"verified_at",
|
||||||
@@ -73,7 +73,7 @@ async def get_verified_organizations(author_id: str) -> list[VerifiedOrganizatio
|
|||||||
},
|
},
|
||||||
"sort": [
|
"sort": [
|
||||||
{"verified_at": {"order": "desc", "missing": "_last"}},
|
{"verified_at": {"order": "desc", "missing": "_last"}},
|
||||||
{"org_name.keyword": {"order": "asc", "missing": "_last"}},
|
{"organization.keyword": {"order": "asc", "missing": "_last"}},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ async def get_verified_organizations(author_id: str) -> list[VerifiedOrganizatio
|
|||||||
for hit in data.get("hits", {}).get("hits", []):
|
for hit in data.get("hits", {}).get("hits", []):
|
||||||
source = hit.get("_source") or {}
|
source = hit.get("_source") or {}
|
||||||
org_uri = normalize_org_uri(source.get("org_uri"))
|
org_uri = normalize_org_uri(source.get("org_uri"))
|
||||||
org_name = (source.get("org_name") or "").strip()
|
org_name = (source.get("organization") or "").strip()
|
||||||
key = org_uri or org_name.casefold()
|
key = org_uri or org_name.casefold()
|
||||||
if not key:
|
if not key:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -151,9 +151,9 @@ export const routes: Routes = [
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import(
|
import('./modules/founder-potential/multipliers-dashboard/multipliers-dashboard.component').then(
|
||||||
'./modules/founder-potential/multipliers-dashboard/multipliers-dashboard.component'
|
(mod) => mod.MultipliersDashboardComponent,
|
||||||
).then((mod) => mod.MultipliersDashboardComponent),
|
),
|
||||||
resolve: {
|
resolve: {
|
||||||
researchers: multiplicatorResearchersResolver,
|
researchers: multiplicatorResearchersResolver,
|
||||||
},
|
},
|
||||||
@@ -170,9 +170,9 @@ export const routes: Routes = [
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import(
|
import('./modules/founder-potential/founder-dashboard/founder-dashboard.component').then(
|
||||||
'./modules/founder-potential/founder-dashboard/founder-dashboard.component'
|
(mod) => mod.FounderDashboardComponent,
|
||||||
).then((mod) => mod.FounderDashboardComponent),
|
),
|
||||||
resolve: {
|
resolve: {
|
||||||
statistics: founderStatisticsResolver,
|
statistics: founderStatisticsResolver,
|
||||||
candidates: founderCandidatesResolver,
|
candidates: founderCandidatesResolver,
|
||||||
@@ -180,7 +180,7 @@ export const routes: Routes = [
|
|||||||
runGuardsAndResolvers: 'paramsOrQueryParamsChange',
|
runGuardsAndResolvers: 'paramsOrQueryParamsChange',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'founders/:authorId',
|
path: 'collaboration-network/:authorId',
|
||||||
canActivate: [
|
canActivate: [
|
||||||
roleGuard([
|
roleGuard([
|
||||||
UserRole.User,
|
UserRole.User,
|
||||||
@@ -190,9 +190,9 @@ export const routes: Routes = [
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import(
|
import('./modules/founder-potential/researcher-network/researcher-network.component').then(
|
||||||
'./modules/founder-potential/researcher-network/researcher-network.component'
|
(mod) => mod.ResearcherNetworkComponent,
|
||||||
).then((mod) => mod.ResearcherNetworkComponent),
|
),
|
||||||
resolve: {
|
resolve: {
|
||||||
page: multiplierResearcherPageResolver,
|
page: multiplierResearcherPageResolver,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -44,10 +44,17 @@ export class DashboardComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.restoreTreemapNodeState();
|
this.restoreTreemapNodeState();
|
||||||
this.dashboard.initialize((institutionId) => {
|
this.dashboard.initialize((institutionId, source) => {
|
||||||
if (institutionId === this.selectedAnalyticalInstitutionId) return;
|
const changed = institutionId !== this.selectedAnalyticalInstitutionId;
|
||||||
this.selectedAnalyticalInstitutionId = institutionId;
|
this.selectedAnalyticalInstitutionId = institutionId;
|
||||||
this.reloadAnalyticalData();
|
// When the organization was auto-selected from the account (no explicit
|
||||||
|
// URL parameter), persist it so the URL reflects the current state.
|
||||||
|
if (source === 'default' && institutionId) {
|
||||||
|
this.updateDashboardPeriodUrl();
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
this.reloadAnalyticalData();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ import {
|
|||||||
TopAuthorStatistics,
|
TopAuthorStatistics,
|
||||||
} from '../dashboard-statistics.service';
|
} from '../dashboard-statistics.service';
|
||||||
import { mapProjectTopicsToTreemap } from './dashboard-topic-treemap.mapper';
|
import { mapProjectTopicsToTreemap } from './dashboard-topic-treemap.mapper';
|
||||||
|
import { CredentialService } from '../../../shared/services/credential.service';
|
||||||
|
|
||||||
|
/** Where the initially selected institution came from. */
|
||||||
|
export type InstitutionRestoreSource = 'url' | 'default';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DashboardFacade {
|
export class DashboardFacade {
|
||||||
@@ -88,9 +92,15 @@ export class DashboardFacade {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly statisticsService: DashboardStatisticsService,
|
private readonly statisticsService: DashboardStatisticsService,
|
||||||
private readonly route: ActivatedRoute,
|
private readonly route: ActivatedRoute,
|
||||||
|
private readonly credentials: CredentialService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
initialize(onInstitutionRestored: (institutionId: string) => void): void {
|
initialize(
|
||||||
|
onInstitutionRestored: (
|
||||||
|
institutionId: string,
|
||||||
|
source: InstitutionRestoreSource,
|
||||||
|
) => void,
|
||||||
|
): void {
|
||||||
this.restorePeriodState();
|
this.restorePeriodState();
|
||||||
this.loadStatistics();
|
this.loadStatistics();
|
||||||
this.loadInstitutions(onInstitutionRestored);
|
this.loadInstitutions(onInstitutionRestored);
|
||||||
@@ -191,7 +201,10 @@ export class DashboardFacade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadInstitutions(
|
private loadInstitutions(
|
||||||
onInstitutionRestored: (institutionId: string) => void,
|
onInstitutionRestored: (
|
||||||
|
institutionId: string,
|
||||||
|
source: InstitutionRestoreSource,
|
||||||
|
) => void,
|
||||||
): void {
|
): void {
|
||||||
this.institutionsLoading = true;
|
this.institutionsLoading = true;
|
||||||
this.institutionsError = false;
|
this.institutionsError = false;
|
||||||
@@ -202,18 +215,23 @@ export class DashboardFacade {
|
|||||||
next: (institutions) => {
|
next: (institutions) => {
|
||||||
this.institutions = institutions;
|
this.institutions = institutions;
|
||||||
const requestedInstitution =
|
const requestedInstitution =
|
||||||
this.route.snapshot.queryParamMap.get('institution') ?? 'all';
|
this.route.snapshot.queryParamMap.get('institution');
|
||||||
const restoredInstitution = institutions.some(
|
// An explicit URL parameter wins; otherwise start with the logged-in
|
||||||
(institution) => institution.id === requestedInstitution,
|
// person's organization (the effective institution, which follows
|
||||||
)
|
// impersonation) and fall back to all institutions.
|
||||||
? requestedInstitution
|
const restoredInstitution = requestedInstitution
|
||||||
: 'all';
|
? this.findInstitution(institutions, requestedInstitution) ?? 'all'
|
||||||
|
: this.findInstitution(
|
||||||
|
institutions,
|
||||||
|
this.credentials.effectiveInstitutionId(),
|
||||||
|
) ?? 'all';
|
||||||
if (restoredInstitution !== this.selectedInstitutionId) {
|
if (restoredInstitution !== this.selectedInstitutionId) {
|
||||||
this.selectedInstitutionId = restoredInstitution;
|
this.selectedInstitutionId = restoredInstitution;
|
||||||
this.loadStatistics();
|
this.loadStatistics();
|
||||||
}
|
}
|
||||||
onInstitutionRestored(
|
onInstitutionRestored(
|
||||||
restoredInstitution === 'all' ? '' : restoredInstitution,
|
restoredInstitution === 'all' ? '' : restoredInstitution,
|
||||||
|
requestedInstitution ? 'url' : 'default',
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
@@ -223,6 +241,16 @@ export class DashboardFacade {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private findInstitution(
|
||||||
|
institutions: DashboardInstitution[],
|
||||||
|
institutionId: string | null | undefined,
|
||||||
|
): string | undefined {
|
||||||
|
if (!institutionId) return undefined;
|
||||||
|
return institutions.some((institution) => institution.id === institutionId)
|
||||||
|
? institutionId
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private loadDfgProjectTopics(
|
private loadDfgProjectTopics(
|
||||||
period: DashboardPeriodBounds,
|
period: DashboardPeriodBounds,
|
||||||
institutionId: string,
|
institutionId: string,
|
||||||
|
|||||||
+4
-1
@@ -205,6 +205,9 @@ export class MultipliersDashboardComponent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
openNetwork(row: MultiplierRow): void {
|
openNetwork(row: MultiplierRow): void {
|
||||||
void this.router.navigate(['/founders', row.researcher.author_id]);
|
void this.router.navigate([
|
||||||
|
'/collaboration-network',
|
||||||
|
row.researcher.author_id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -86,18 +86,19 @@
|
|||||||
<span class="legend__item">Knotengröße = aktive Jahre</span>
|
<span class="legend__item">Knotengröße = aktive Jahre</span>
|
||||||
</div>
|
</div>
|
||||||
<p class="graph-hint">
|
<p class="graph-hint">
|
||||||
Personen anklicken, um ihr Profil zu öffnen · ziehen zum Verschieben ·
|
<span class="graph-hint__desktop">
|
||||||
scrollen zum Zoomen
|
Personen anklicken, um ihr Profil zu öffnen · ziehen zum Verschieben ·
|
||||||
|
scrollen zum Zoomen
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="case-grid">
|
<div class="case-grid">
|
||||||
<mat-card appearance="outlined" class="netbox">
|
<mat-card appearance="outlined" class="netbox">
|
||||||
<mat-card-content>
|
<mat-card-content class="netbox__content">
|
||||||
@if (network(); as net) {
|
@if (network(); as net) {
|
||||||
@if ((net.nodes?.length ?? 0) > 0) {
|
@if ((net.nodes?.length ?? 0) > 0) {
|
||||||
<app-multiplier-network-graph
|
<app-multiplier-network-graph
|
||||||
[network]="net"
|
[network]="net"
|
||||||
[height]="640"
|
|
||||||
(nodeClick)="onNodeClick($event)" />
|
(nodeClick)="onNodeClick($event)" />
|
||||||
} @else {
|
} @else {
|
||||||
<div class="netbox__empty">Kein Netzwerk verfügbar.</div>
|
<div class="netbox__empty">Kein Netzwerk verfügbar.</div>
|
||||||
|
|||||||
+79
-2
@@ -44,6 +44,20 @@
|
|||||||
margin: 8px 0 0;
|
margin: 8px 0 0;
|
||||||
color: var(--sg-text-soft);
|
color: var(--sg-text-soft);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|
||||||
|
&__touch {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (hover: none), (pointer: coarse) {
|
||||||
|
.graph-hint__desktop {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-hint__touch {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.legend {
|
.legend {
|
||||||
@@ -101,22 +115,45 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.netbox {
|
.netbox {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
background: var(--sg-surface-muted);
|
background: var(--sg-surface-muted);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
height: 100%;
|
||||||
|
// Keep the chart usable even when the surrounding grid row has no
|
||||||
|
// definite height (single-column phone layout).
|
||||||
|
min-height: clamp(420px, 58vh, 760px);
|
||||||
|
|
||||||
.mat-mdc-card-content {
|
.mat-mdc-card-content {
|
||||||
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__empty {
|
&__empty {
|
||||||
height: 640px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: var(--sg-text-soft);
|
color: var(--sg-text-soft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.netbox__content {
|
||||||
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
app-multiplier-network-graph {
|
||||||
|
display: block;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.detail-card {
|
.detail-card {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
@@ -288,9 +325,49 @@
|
|||||||
@media (max-width: 1000px) {
|
@media (max-width: 1000px) {
|
||||||
.case-grid {
|
.case-grid {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
|
gap: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.netbox {
|
||||||
|
// The grid row no longer gives the card a definite height here, so give
|
||||||
|
// the chart an explicit viewport-based height instead of collapsing.
|
||||||
|
height: auto;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The legend sits directly above the graph in the single-column layout, so
|
||||||
|
// it does not need to stick, and the narrower column needs tighter wrapping.
|
||||||
|
.legend {
|
||||||
|
position: static;
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 6px 0;
|
||||||
|
gap: 6px 12px;
|
||||||
|
font-size: 11.5px;
|
||||||
|
line-height: 1.35;
|
||||||
|
}
|
||||||
|
|
||||||
|
app-multiplier-network-graph,
|
||||||
.netbox__empty {
|
.netbox__empty {
|
||||||
height: 420px;
|
flex: none;
|
||||||
|
height: clamp(340px, 52vh, 500px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
.case-grid {
|
||||||
|
gap: 16px;
|
||||||
|
margin-top: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-card .mat-mdc-card-content {
|
||||||
|
padding: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.network-footer {
|
||||||
|
margin-top: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unavailable .mat-mdc-card-content {
|
||||||
|
padding: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -604,9 +604,18 @@ export class HierarchyChartComponent implements OnInit {
|
|||||||
|
|
||||||
if (hasChildren) {
|
if (hasChildren) {
|
||||||
const newLevel = this.buildLevel(raw);
|
const newLevel = this.buildLevel(raw);
|
||||||
// if the user clicks a different branch, drop any deeper levels first
|
const currentLevels = this.levels();
|
||||||
const truncated = this.levels().slice(0, levelIndex + 1);
|
const existingIndex = currentLevels.findIndex(
|
||||||
this.levels.set([...truncated, newLevel]);
|
(level) => level.id === raw.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingIndex >= 0) {
|
||||||
|
this.levels.set(currentLevels.slice(0, existingIndex + 1));
|
||||||
|
} else {
|
||||||
|
// If the user clicks a different branch, drop any deeper levels first.
|
||||||
|
const truncated = currentLevels.slice(0, levelIndex + 1);
|
||||||
|
this.levels.set([...truncated, newLevel]);
|
||||||
|
}
|
||||||
this.updateQueryParams();
|
this.updateQueryParams();
|
||||||
} else {
|
} else {
|
||||||
this.onLeafSelect(raw);
|
this.onLeafSelect(raw);
|
||||||
@@ -629,7 +638,7 @@ export class HierarchyChartComponent implements OnInit {
|
|||||||
const warning = this.chartTheme.colors().warning;
|
const warning = this.chartTheme.colors().warning;
|
||||||
return {
|
return {
|
||||||
borderColor: warning,
|
borderColor: warning,
|
||||||
borderWidth: 3,
|
borderWidth: 1,
|
||||||
shadowBlur: 10,
|
shadowBlur: 10,
|
||||||
shadowColor: warning,
|
shadowColor: warning,
|
||||||
};
|
};
|
||||||
@@ -696,9 +705,7 @@ export class HierarchyChartComponent implements OnInit {
|
|||||||
// Leaves inherit the icon of the group that contains them, including the
|
// Leaves inherit the icon of the group that contains them, including the
|
||||||
// direct children of a group that is itself the root of this level.
|
// direct children of a group that is itself the root of this level.
|
||||||
const parentType =
|
const parentType =
|
||||||
raw.type === 'institutes' || raw.type === 'chairs'
|
raw.type === 'institutes' || raw.type === 'chairs' ? raw.type : undefined;
|
||||||
? raw.type
|
|
||||||
: undefined;
|
|
||||||
const children = (raw.children || []).map((c) =>
|
const children = (raw.children || []).map((c) =>
|
||||||
this.toChartNode(c, true, parentType),
|
this.toChartNode(c, true, parentType),
|
||||||
);
|
);
|
||||||
@@ -779,18 +786,27 @@ export class HierarchyChartComponent implements OnInit {
|
|||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
color: 'black',
|
color: 'black',
|
||||||
formatter: (params: any) => {
|
formatter: (params: any) => {
|
||||||
if (params.data.hasChildren) {
|
const isHighlighted = params.data.id === this.highlightedId();
|
||||||
return '{bold|' + params.name + '}';
|
let style = 'normal';
|
||||||
|
if (isHighlighted) {
|
||||||
|
style = 'highlighted';
|
||||||
|
} else if (params.data.hasChildren) {
|
||||||
|
style = 'bold';
|
||||||
}
|
}
|
||||||
return '{normal|' + params.name + '}';
|
|
||||||
|
return `{${style}|${params.name}}`;
|
||||||
},
|
},
|
||||||
rich: {
|
rich: {
|
||||||
bold: {
|
highlighted: {
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
|
color: colors.warning,
|
||||||
},
|
},
|
||||||
normal: {
|
normal: {
|
||||||
fontWeight: 'normal',
|
fontWeight: 'normal',
|
||||||
},
|
},
|
||||||
|
bold: {
|
||||||
|
fontWeight: 'bold',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
leaves: {
|
leaves: {
|
||||||
|
|||||||
@@ -1,217 +1,231 @@
|
|||||||
<app-page-container>
|
<app-page-container>
|
||||||
@if (!isPersonLoading()) {
|
@if (!isPersonLoading()) {
|
||||||
<section class="person-hero">
|
<section class="person-hero">
|
||||||
<div class="profile-card">
|
<div class="profile-card">
|
||||||
<div class="profile-avatar">{{ initials() }}</div>
|
<div class="profile-avatar">{{ initials() }}</div>
|
||||||
<div class="profile-main">
|
<div class="profile-main">
|
||||||
<div class="name-line">
|
<div class="name-line">
|
||||||
<span>Person</span>
|
<span>Person</span>
|
||||||
<h1>{{ displayName() }}</h1>
|
<h1>{{ displayName() }}</h1>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="profile-bookmark-button"
|
class="profile-bookmark-button"
|
||||||
[class.bookmarked]="bookmarkService.isBookmarked(person()?.id)"
|
[class.bookmarked]="bookmarkService.isBookmarked(person()?.id)"
|
||||||
[attr.aria-label]="
|
[attr.aria-label]="
|
||||||
bookmarkService.isBookmarked(person()?.id)
|
bookmarkService.isBookmarked(person()?.id)
|
||||||
? 'Bookmark entfernen'
|
? 'Bookmark entfernen'
|
||||||
: 'Person bookmarken'
|
: 'Person bookmarken'
|
||||||
"
|
"
|
||||||
[matTooltip]="
|
[matTooltip]="
|
||||||
bookmarkService.isBookmarked(person()?.id)
|
bookmarkService.isBookmarked(person()?.id)
|
||||||
? 'Bookmark entfernen'
|
? 'Bookmark entfernen'
|
||||||
: 'Person bookmarken'
|
: 'Person bookmarken'
|
||||||
"
|
"
|
||||||
(click)="toggleBookmark()">
|
(click)="toggleBookmark()">
|
||||||
<mat-icon>{{
|
<mat-icon>{{
|
||||||
bookmarkService.isBookmarked(person()?.id)
|
bookmarkService.isBookmarked(person()?.id)
|
||||||
? BOOKMARK_ICON
|
? BOOKMARK_ICON
|
||||||
: BOOKMARK_BORDER_ICON
|
: BOOKMARK_BORDER_ICON
|
||||||
}}</mat-icon>
|
}}</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@if (resolvedInstitution() || verifiedOrganizations().length > 0) {
|
@if (
|
||||||
<div class="institution-line">
|
resolvedInstitution() ||
|
||||||
@if (resolvedInstitution(); as inst) {
|
(canOpenVerifiedOrganizationHierarchy() &&
|
||||||
<app-institution-chip
|
verifiedOrganizations().length > 0)
|
||||||
[institution]="inst"
|
) {
|
||||||
size="normal"
|
<div class="institution-line">
|
||||||
[showIcon]="true"
|
@if (resolvedInstitution(); as inst) {
|
||||||
[isClickable]="false" />
|
<app-institution-chip
|
||||||
@if (secondaryInstitutions().length > 0) {
|
[institution]="inst"
|
||||||
<button
|
size="normal"
|
||||||
type="button"
|
[showIcon]="true"
|
||||||
class="more-institutions-btn"
|
[isClickable]="false" />
|
||||||
[appComponentTooltip]="PersonInstitutionTooltipListComponent"
|
@if (secondaryInstitutions().length > 0) {
|
||||||
[tooltipInputs]="{ institutions: secondaryInstitutions() }"
|
<button
|
||||||
[attr.aria-label]="
|
type="button"
|
||||||
secondaryInstitutions().length + ' weitere Institutionen'
|
class="more-institutions-btn"
|
||||||
">
|
[appComponentTooltip]="
|
||||||
<mat-icon class="more-info-icon">{{ MORE_INFO_ICON }}</mat-icon>
|
PersonInstitutionTooltipListComponent
|
||||||
<span class="count-text"
|
"
|
||||||
>+{{ secondaryInstitutions().length }}</span
|
[tooltipInputs]="{ institutions: secondaryInstitutions() }"
|
||||||
>
|
[attr.aria-label]="
|
||||||
</button>
|
secondaryInstitutions().length + ' weitere Institutionen'
|
||||||
|
">
|
||||||
|
<mat-icon class="more-info-icon">{{
|
||||||
|
MORE_INFO_ICON
|
||||||
|
}}</mat-icon>
|
||||||
|
<span class="count-text"
|
||||||
|
>+{{ secondaryInstitutions().length }}</span
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
@if (canOpenVerifiedOrganizationHierarchy()) {
|
||||||
@for (org of verifiedOrganizations(); track $index) {
|
@for (org of verifiedOrganizations(); track $index) {
|
||||||
@if (canOpenOrganizationHierarchy(org)) {
|
@if (canOpenOrganizationHierarchy(org)) {
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="verified-org-chip"
|
class="verified-org-chip"
|
||||||
|
[matTooltip]="
|
||||||
|
'Verifizierte Organisation: ' +
|
||||||
|
org.org_name +
|
||||||
|
' – Hierarchie öffnen'
|
||||||
|
"
|
||||||
|
matTooltipPosition="right"
|
||||||
|
[matTooltipShowDelay]="250"
|
||||||
|
[attr.aria-label]="
|
||||||
|
'Verifizierte Organisation: ' +
|
||||||
|
org.org_name +
|
||||||
|
'. Hierarchie öffnen.'
|
||||||
|
"
|
||||||
|
(click)="openOrganizationHierarchy(org)">
|
||||||
|
<mat-icon>{{ VERIFIED_ICON }}</mat-icon>
|
||||||
|
<span>{{ org.org_name }}</span>
|
||||||
|
</button>
|
||||||
|
} @else {
|
||||||
|
<span
|
||||||
|
class="verified-org-chip static"
|
||||||
|
[matTooltip]="
|
||||||
|
'Verifizierte Organisation: ' + org.org_name
|
||||||
|
"
|
||||||
|
matTooltipPosition="right"
|
||||||
|
[matTooltipShowDelay]="250">
|
||||||
|
<mat-icon>{{ VERIFIED_ICON }}</mat-icon>
|
||||||
|
<span>{{ org.org_name }}</span>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (
|
||||||
|
worksCount() !== null ||
|
||||||
|
citedByCount() !== null ||
|
||||||
|
h_index() !== null
|
||||||
|
) {
|
||||||
|
<span class="stats-line">
|
||||||
|
@if (worksCount() !== null) {
|
||||||
|
<span class="stat-item">
|
||||||
|
<mat-icon class="stat-icon">{{ PUBLICATION_ICON }}</mat-icon>
|
||||||
|
{{ worksCount() | number }} Publikationen
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
@if (worksCount() !== null && citedByCount() !== null) {
|
||||||
|
·
|
||||||
|
}
|
||||||
|
@if (citedByCount() !== null) {
|
||||||
|
<span class="stat-item">
|
||||||
|
<mat-icon class="stat-icon">{{ CITATION_ICON }}</mat-icon>
|
||||||
|
{{ citedByCount() | number }} Zitationen
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
@if (
|
||||||
|
(worksCount() !== null || citedByCount() !== null) &&
|
||||||
|
h_index() !== null
|
||||||
|
) {
|
||||||
|
·
|
||||||
|
}
|
||||||
|
@if (h_index() !== null) {
|
||||||
|
<span
|
||||||
|
class="stat-item has-tooltip"
|
||||||
[matTooltip]="
|
[matTooltip]="
|
||||||
'Verifizierte Organisation: ' +
|
'Der h-Index beträgt ' +
|
||||||
org.org_name +
|
h_index() +
|
||||||
' – Hierarchie öffnen'
|
': ' +
|
||||||
|
h_index() +
|
||||||
|
' Publikationen wurden jeweils mindestens ' +
|
||||||
|
h_index() +
|
||||||
|
'-mal zitiert.'
|
||||||
"
|
"
|
||||||
matTooltipPosition="right"
|
matTooltipPosition="right"
|
||||||
[matTooltipShowDelay]="250"
|
[matTooltipShowDelay]="250">
|
||||||
[attr.aria-label]="
|
<mat-icon class="stat-icon">{{ TRENDING_UP_ICON }}</mat-icon>
|
||||||
'Verifizierte Organisation: ' +
|
h-Index {{ h_index() }}
|
||||||
org.org_name +
|
</span>
|
||||||
'. Hierarchie öffnen.'
|
}
|
||||||
"
|
</span>
|
||||||
(click)="openOrganizationHierarchy(org)">
|
}
|
||||||
<mat-icon>{{ VERIFIED_ICON }}</mat-icon>
|
@if (displayCareerStage() || orcid()) {
|
||||||
<span>{{ org.org_name }}</span>
|
<div class="meta-line">
|
||||||
</button>
|
<app-career-stage-chip
|
||||||
} @else {
|
[careerStage]="displayCareerStage()"
|
||||||
<span
|
[activeYears]="person()?.career_metrics?.active_years" />
|
||||||
class="verified-org-chip static"
|
@if (orcid(); as orcidId) {
|
||||||
[matTooltip]="'Verifizierte Organisation: ' + org.org_name"
|
<a
|
||||||
|
class="orcid-chip"
|
||||||
|
[href]="orcidUrl()"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener"
|
||||||
|
matTooltip="ORCID-Profil öffnen"
|
||||||
matTooltipPosition="right"
|
matTooltipPosition="right"
|
||||||
[matTooltipShowDelay]="250">
|
[matTooltipShowDelay]="250">
|
||||||
<mat-icon>{{ VERIFIED_ICON }}</mat-icon>
|
<mat-icon>{{ VERIFIED_ICON }}</mat-icon>
|
||||||
<span>{{ org.org_name }}</span>
|
{{ orcidId }}
|
||||||
</span>
|
</a>
|
||||||
}
|
}
|
||||||
}
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
</div>
|
||||||
@if (
|
</div>
|
||||||
worksCount() !== null || citedByCount() !== null || h_index() !== null
|
<aside class="sidebar">
|
||||||
) {
|
<div class="bio-card">
|
||||||
<span class="stats-line">
|
@if (isBioLoading()) {
|
||||||
@if (worksCount() !== null) {
|
<app-loading
|
||||||
<span class="stat-item">
|
text="Biografie wird geladen..."
|
||||||
<mat-icon class="stat-icon">{{ PUBLICATION_ICON }}</mat-icon>
|
[icon]="DESCRIPTION_ICON"
|
||||||
{{ worksCount() | number }} Publikationen
|
[size]="150"
|
||||||
</span>
|
[diameter]="150"></app-loading>
|
||||||
}
|
} @else if (personBio() != null) {
|
||||||
@if (worksCount() !== null && citedByCount() !== null) {
|
<div class="bio-header">
|
||||||
·
|
<h3>Biografie</h3>
|
||||||
}
|
|
||||||
@if (citedByCount() !== null) {
|
|
||||||
<span class="stat-item">
|
|
||||||
<mat-icon class="stat-icon">{{ CITATION_ICON }}</mat-icon>
|
|
||||||
{{ citedByCount() | number }} Zitationen
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
@if (
|
|
||||||
(worksCount() !== null || citedByCount() !== null) &&
|
|
||||||
h_index() !== null
|
|
||||||
) {
|
|
||||||
·
|
|
||||||
}
|
|
||||||
@if (h_index() !== null) {
|
|
||||||
<span
|
<span
|
||||||
class="stat-item has-tooltip"
|
class="ai-badge"
|
||||||
[matTooltip]="
|
matTooltip="Diese Biografie wurde automatisch mit KI erstellt und kann Fehler enthalten."
|
||||||
'Der h-Index beträgt ' +
|
matTooltipPosition="above"
|
||||||
h_index() +
|
|
||||||
': ' +
|
|
||||||
h_index() +
|
|
||||||
' Publikationen wurden jeweils mindestens ' +
|
|
||||||
h_index() +
|
|
||||||
'-mal zitiert.'
|
|
||||||
"
|
|
||||||
matTooltipPosition="right"
|
|
||||||
[matTooltipShowDelay]="250">
|
[matTooltipShowDelay]="250">
|
||||||
<mat-icon class="stat-icon">{{ TRENDING_UP_ICON }}</mat-icon>
|
<mat-icon>{{ AI_GENERATED_ICON }}</mat-icon>
|
||||||
h-Index {{ h_index() }}
|
KI-generiert
|
||||||
</span>
|
</span>
|
||||||
}
|
</div>
|
||||||
</span>
|
<p>{{ personBio() }}</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
<app-person-interesting
|
||||||
|
[topics]="primaryTopicCounts()"
|
||||||
|
[loading]="isTopicsLoading()"
|
||||||
|
[personName]="personName()"
|
||||||
|
[personPublicationsLink]="personPublicationsLink()"
|
||||||
|
(tagClick)="onInterestingTagClick($event)"></app-person-interesting>
|
||||||
|
</section>
|
||||||
|
@if (this.links()) {
|
||||||
|
<app-link-tab-nav-bar
|
||||||
|
#navBar
|
||||||
|
[links]="links()"
|
||||||
|
[tabPanel]="tabPanel"></app-link-tab-nav-bar>
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
<app-loading
|
||||||
|
text="Person wird geladen..."
|
||||||
|
[icon]="PERSON_ICON"
|
||||||
|
[size]="150"
|
||||||
|
[diameter]="150"></app-loading>
|
||||||
|
}
|
||||||
|
<mat-tab-nav-panel #tabPanel class="person-panel">
|
||||||
|
@let activeLink = this.activeLink();
|
||||||
|
@if (activeLink) {
|
||||||
|
<div class="description-container">
|
||||||
|
@if (activeLink.label) {
|
||||||
|
<h5>{{ activeLink.label }}</h5>
|
||||||
}
|
}
|
||||||
@if (displayCareerStage() || orcid()) {
|
@if (activeLink.description) {
|
||||||
<div class="meta-line">
|
<span class="description">{{ activeLink.description }}</span>
|
||||||
<app-career-stage-chip
|
|
||||||
[careerStage]="displayCareerStage()"
|
|
||||||
[activeYears]="person()?.career_metrics?.active_years" />
|
|
||||||
@if (orcid(); as orcidId) {
|
|
||||||
<a
|
|
||||||
class="orcid-chip"
|
|
||||||
[href]="orcidUrl()"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener"
|
|
||||||
matTooltip="ORCID-Profil öffnen"
|
|
||||||
matTooltipPosition="right"
|
|
||||||
[matTooltipShowDelay]="250">
|
|
||||||
<mat-icon>{{ VERIFIED_ICON }}</mat-icon>
|
|
||||||
{{ orcidId }}
|
|
||||||
</a>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
<div class="content">
|
||||||
|
<router-outlet></router-outlet>
|
||||||
</div>
|
</div>
|
||||||
<aside class="sidebar">
|
</mat-tab-nav-panel>
|
||||||
<div class="bio-card">
|
|
||||||
@if (isBioLoading()) {
|
|
||||||
<app-loading
|
|
||||||
text="Biografie wird geladen..."
|
|
||||||
[icon]="DESCRIPTION_ICON"
|
|
||||||
[size]="150"
|
|
||||||
[diameter]="150"></app-loading>
|
|
||||||
} @else if (personBio() != null) {
|
|
||||||
<div class="bio-header">
|
|
||||||
<h3>Biografie</h3>
|
|
||||||
<span
|
|
||||||
class="ai-badge"
|
|
||||||
matTooltip="Diese Biografie wurde automatisch mit KI erstellt und kann Fehler enthalten."
|
|
||||||
matTooltipPosition="above"
|
|
||||||
[matTooltipShowDelay]="250">
|
|
||||||
<mat-icon>{{ AI_GENERATED_ICON }}</mat-icon>
|
|
||||||
KI-generiert
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p>{{ personBio() }}</p>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
<app-person-interesting
|
|
||||||
[topics]="primaryTopicCounts()"
|
|
||||||
[loading]="isTopicsLoading()"
|
|
||||||
[personName]="personName()"
|
|
||||||
[personPublicationsLink]="personPublicationsLink()"
|
|
||||||
(tagClick)="onInterestingTagClick($event)"></app-person-interesting>
|
|
||||||
</section>
|
|
||||||
@if (this.links()) {
|
|
||||||
<app-link-tab-nav-bar
|
|
||||||
#navBar
|
|
||||||
[links]="links()"
|
|
||||||
[tabPanel]="tabPanel"></app-link-tab-nav-bar>
|
|
||||||
}
|
|
||||||
} @else {
|
|
||||||
<app-loading
|
|
||||||
text="Person wird geladen..."
|
|
||||||
[icon]="PERSON_ICON"
|
|
||||||
[size]="150"
|
|
||||||
[diameter]="150"></app-loading>
|
|
||||||
}
|
|
||||||
<mat-tab-nav-panel #tabPanel class="person-panel">
|
|
||||||
@let activeLink = this.activeLink();
|
|
||||||
@if (activeLink) {
|
|
||||||
<div class="description-container">
|
|
||||||
@if (activeLink.label) {
|
|
||||||
<h5>{{ activeLink.label }}</h5>
|
|
||||||
}
|
|
||||||
@if (activeLink.description) {
|
|
||||||
<span class="description">{{ activeLink.description }}</span>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
<div class="content">
|
|
||||||
<router-outlet></router-outlet>
|
|
||||||
</div>
|
|
||||||
</mat-tab-nav-panel>
|
|
||||||
</app-page-container>
|
</app-page-container>
|
||||||
|
|||||||
@@ -79,9 +79,7 @@ import {
|
|||||||
import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component';
|
import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component';
|
||||||
|
|
||||||
/** Accepts raw and full-URL OpenAlex IDs, e.g. `I123` or `.../I123`. */
|
/** Accepts raw and full-URL OpenAlex IDs, e.g. `I123` or `.../I123`. */
|
||||||
const normalizeInstitutionId = (
|
const normalizeInstitutionId = (value: string | null | undefined): string =>
|
||||||
value: string | null | undefined,
|
|
||||||
): string =>
|
|
||||||
(value ?? '')
|
(value ?? '')
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/^https:\/\/openalex\.org\//i, '')
|
.replace(/^https:\/\/openalex\.org\//i, '')
|
||||||
|
|||||||
+6
-1
@@ -1,4 +1,9 @@
|
|||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.multiplier-graph {
|
.multiplier-graph {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 480px; // fallback; the component's `height` input overrides it
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
+96
-19
@@ -1,4 +1,15 @@
|
|||||||
import { Component, computed, inject, input, output } from '@angular/core';
|
import {
|
||||||
|
afterNextRender,
|
||||||
|
Component,
|
||||||
|
computed,
|
||||||
|
DestroyRef,
|
||||||
|
ElementRef,
|
||||||
|
inject,
|
||||||
|
input,
|
||||||
|
NgZone,
|
||||||
|
output,
|
||||||
|
signal,
|
||||||
|
} from '@angular/core';
|
||||||
import { EgoNetwork, EgoNetworkEdge, EgoNetworkNode } from '../../../api';
|
import { EgoNetwork, EgoNetworkEdge, EgoNetworkNode } from '../../../api';
|
||||||
import { EChartsCoreOption } from 'echarts';
|
import { EChartsCoreOption } from 'echarts';
|
||||||
import { NgxEchartsDirective } from 'ngx-echarts';
|
import { NgxEchartsDirective } from 'ngx-echarts';
|
||||||
@@ -63,11 +74,61 @@ export function multiplierRoleColor(role: string, dark: boolean): string {
|
|||||||
})
|
})
|
||||||
export class MultiplierNetworkGraphComponent {
|
export class MultiplierNetworkGraphComponent {
|
||||||
readonly network = input.required<EgoNetwork>();
|
readonly network = input.required<EgoNetwork>();
|
||||||
/** Chart height in pixels. */
|
/** Fixed chart height in pixels. Omit to fill the parent element. */
|
||||||
readonly height = input<number>(480);
|
readonly height = input<number>();
|
||||||
readonly nodeClick = output<MultiplierNodeClickEvent>();
|
readonly nodeClick = output<MultiplierNodeClickEvent>();
|
||||||
|
|
||||||
private readonly chartTheme = inject(ChartThemeService);
|
private readonly chartTheme = inject(ChartThemeService);
|
||||||
|
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
|
||||||
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
|
private readonly zone = inject(NgZone);
|
||||||
|
|
||||||
|
/** Rounded container width, used to adapt the force layout to small screens. */
|
||||||
|
private readonly containerWidth = signal(0);
|
||||||
|
/** Touch devices get pinch-zoom only, so one-finger swipes can scroll the page. */
|
||||||
|
private readonly coarsePointer = signal(false);
|
||||||
|
|
||||||
|
private readonly compact = computed(() => {
|
||||||
|
const width = this.containerWidth();
|
||||||
|
return width > 0 && width < 560;
|
||||||
|
});
|
||||||
|
|
||||||
|
private readonly medium = computed(() => {
|
||||||
|
const width = this.containerWidth();
|
||||||
|
return width >= 560 && width < 960;
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
if (typeof window !== 'undefined' && window.matchMedia) {
|
||||||
|
const query = window.matchMedia('(pointer: coarse)');
|
||||||
|
this.coarsePointer.set(query.matches);
|
||||||
|
const onChange = (event: MediaQueryListEvent) =>
|
||||||
|
this.coarsePointer.set(event.matches);
|
||||||
|
query.addEventListener('change', onChange);
|
||||||
|
this.destroyRef.onDestroy(() =>
|
||||||
|
query.removeEventListener('change', onChange),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
afterNextRender(() => {
|
||||||
|
const host = this.host.nativeElement;
|
||||||
|
const measure = () => {
|
||||||
|
const width = Math.round(host.getBoundingClientRect().width);
|
||||||
|
// Quantize so small resizes don't restart the force layout every frame.
|
||||||
|
const bucket = Math.round(width / 40) * 40;
|
||||||
|
if (bucket !== this.containerWidth()) {
|
||||||
|
this.containerWidth.set(bucket);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.zone.run(measure);
|
||||||
|
|
||||||
|
if (typeof ResizeObserver !== 'function') return;
|
||||||
|
const observer = new ResizeObserver(() => this.zone.run(measure));
|
||||||
|
observer.observe(host);
|
||||||
|
this.destroyRef.onDestroy(() => observer.disconnect());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private roleColor(role: string): string {
|
private roleColor(role: string): string {
|
||||||
return multiplierRoleColor(role, this.chartTheme.isDark());
|
return multiplierRoleColor(role, this.chartTheme.isDark());
|
||||||
@@ -79,8 +140,19 @@ export class MultiplierNetworkGraphComponent {
|
|||||||
if (!network) return {};
|
if (!network) return {};
|
||||||
|
|
||||||
const textColor = colors.text;
|
const textColor = colors.text;
|
||||||
const nodes = this.buildNodes(network.nodes ?? []);
|
const compact = this.compact();
|
||||||
const links = this.buildLinks(network.edges ?? []);
|
const medium = this.medium();
|
||||||
|
const nodes = this.buildNodes(network.nodes ?? [], compact);
|
||||||
|
const links = this.buildLinks(network.edges ?? [], compact);
|
||||||
|
|
||||||
|
// Force layouts spread nodes over a fixed pixel area, so a narrower
|
||||||
|
// container needs a tighter layout or most of the network ends up
|
||||||
|
// off-screen.
|
||||||
|
const force = compact
|
||||||
|
? { repulsion: 620, edgeLength: [38, 85], friction: 0.3, gravity: 0.2 }
|
||||||
|
: medium
|
||||||
|
? { repulsion: 1000, edgeLength: [55, 120], friction: 0.25, gravity: 0.14 }
|
||||||
|
: { repulsion: 1400, edgeLength: [70, 150], friction: 0.25, gravity: 0.1 };
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
@@ -116,21 +188,18 @@ export class MultiplierNetworkGraphComponent {
|
|||||||
layout: 'force',
|
layout: 'force',
|
||||||
data: nodes,
|
data: nodes,
|
||||||
links,
|
links,
|
||||||
roam: true,
|
// On touch screens only pinch-zoom, so a one-finger swipe still
|
||||||
|
// scrolls the page instead of panning the graph.
|
||||||
|
roam: this.coarsePointer() ? 'scale' : true,
|
||||||
roamTrigger: 'global',
|
roamTrigger: 'global',
|
||||||
scaleLimit: { min: 0.4, max: 4 },
|
scaleLimit: { min: 0.4, max: 4 },
|
||||||
label: {
|
label: {
|
||||||
show: false,
|
show: false,
|
||||||
position: 'right',
|
position: 'right',
|
||||||
color: textColor,
|
color: textColor,
|
||||||
fontSize: 11,
|
fontSize: compact ? 10 : 11,
|
||||||
},
|
|
||||||
force: {
|
|
||||||
repulsion: 1400,
|
|
||||||
edgeLength: [70, 150],
|
|
||||||
friction: 0.25,
|
|
||||||
gravity: 0.1,
|
|
||||||
},
|
},
|
||||||
|
force,
|
||||||
emphasis: {
|
emphasis: {
|
||||||
focus: 'adjacency',
|
focus: 'adjacency',
|
||||||
label: { show: true, color: textColor, fontWeight: 'bold' },
|
label: { show: true, color: textColor, fontWeight: 'bold' },
|
||||||
@@ -143,7 +212,7 @@ export class MultiplierNetworkGraphComponent {
|
|||||||
},
|
},
|
||||||
lineStyle: {
|
lineStyle: {
|
||||||
color: colors.mutedTextColor,
|
color: colors.mutedTextColor,
|
||||||
opacity: 0.45,
|
opacity: compact ? 0.32 : 0.45,
|
||||||
curveness: 0,
|
curveness: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -151,7 +220,7 @@ export class MultiplierNetworkGraphComponent {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
private buildNodes(nodes: EgoNetworkNode[]): any[] {
|
private buildNodes(nodes: EgoNetworkNode[], compact: boolean): any[] {
|
||||||
const textColor = this.chartTheme.colors().text;
|
const textColor = this.chartTheme.colors().text;
|
||||||
const nWorks = this.network().n_works ?? undefined;
|
const nWorks = this.network().n_works ?? undefined;
|
||||||
return nodes.map((node) => {
|
return nodes.map((node) => {
|
||||||
@@ -165,7 +234,13 @@ export class MultiplierNetworkGraphComponent {
|
|||||||
inst: node.inst ?? '',
|
inst: node.inst ?? '',
|
||||||
activeYears,
|
activeYears,
|
||||||
nWorks: isEgo ? nWorks : undefined,
|
nWorks: isEgo ? nWorks : undefined,
|
||||||
symbolSize: isEgo ? 24 : clamp(8 + activeYears * 1.1, 8, 26),
|
symbolSize: isEgo
|
||||||
|
? compact
|
||||||
|
? 22
|
||||||
|
: 24
|
||||||
|
: compact
|
||||||
|
? clamp(9 + activeYears, 9, 22)
|
||||||
|
: clamp(8 + activeYears * 1.1, 8, 26),
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: this.roleColor(role),
|
color: this.roleColor(role),
|
||||||
borderColor: isEgo ? textColor : 'transparent',
|
borderColor: isEgo ? textColor : 'transparent',
|
||||||
@@ -176,13 +251,13 @@ export class MultiplierNetworkGraphComponent {
|
|||||||
formatter: '{b}',
|
formatter: '{b}',
|
||||||
position: 'right',
|
position: 'right',
|
||||||
color: textColor,
|
color: textColor,
|
||||||
fontSize: 12,
|
fontSize: compact ? 11 : 12,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildLinks(edges: EgoNetworkEdge[]): any[] {
|
private buildLinks(edges: EgoNetworkEdge[], compact: boolean): any[] {
|
||||||
const names = new Map<string, string>();
|
const names = new Map<string, string>();
|
||||||
for (const node of this.network().nodes ?? []) {
|
for (const node of this.network().nodes ?? []) {
|
||||||
names.set(node.id, node.name ?? node.id);
|
names.set(node.id, node.name ?? node.id);
|
||||||
@@ -197,7 +272,9 @@ export class MultiplierNetworkGraphComponent {
|
|||||||
firstYear: edge.first_year,
|
firstYear: edge.first_year,
|
||||||
lastYear: edge.last_year,
|
lastYear: edge.last_year,
|
||||||
lineStyle: {
|
lineStyle: {
|
||||||
width: clamp((edge.w ?? 0) * 2.5, 1, 7),
|
width: compact
|
||||||
|
? clamp((edge.w ?? 0) * 1.8, 1, 4.5)
|
||||||
|
: clamp((edge.w ?? 0) * 2.5, 1, 7),
|
||||||
type: edge.cross ? 'dashed' : 'solid',
|
type: edge.cross ? 'dashed' : 'solid',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user