Compare commits

...
Author SHA1 Message Date
farajollahi ecf7a6f905 Merge branch 'dev' into eu-top-authors
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev Build queued...
2026-07-28 12:09:16 +02:00
farajollahi 7b912196e9 Merge pull request 'implement keyword select and dfg status diagramm' (#250) from dfg-status-dashboard into dev
LocationBasedServices/smartguide/pipeline/head This commit looks good
Reviewed-on: #250
2026-07-28 11:06:24 +02:00
farajollahi 0dd2023224 Restrict EU top authors to user institution
LocationBasedServices/smartguide/pipeline/head This commit looks good
2026-07-21 09:41:27 +02:00
farajollahi d4880b417b Align dashboard EU authors with person details 2026-07-21 09:33:18 +02:00
farajollahi a7ced052dd Verify EU author counts by unique project 2026-07-21 09:20:07 +02:00
farajollahi 9ac618ebec Revert "Align EU project author counts with person details"
This reverts commit 167913aa85.
2026-07-21 01:05:55 +02:00
farajollahi de6339586f Remove DFG top authors from dashboard 2026-07-21 00:59:34 +02:00
farajollahi 97c9e2eec3 Merge branch 'dev' into eu-top-authors
# Conflicts:
#	service/src/main/inse/dashboard/service.py
#	service/src/main/inse/dashboard/test_service.py
#	webapp/src/app/api/model/topAuthorStatistics.ts
2026-07-21 00:51:45 +02:00
farajollahi 167913aa85 Align EU project author counts with person details 2026-07-21 00:48:28 +02:00
farajollahi 18c9785325 change index
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
2026-07-20 23:59:08 +02:00
farajollahi f4e0888ce2 fix organsaition id
LocationBasedServices/smartguide/pipeline/head This commit looks good
2026-07-20 22:50:31 +02:00
spsaefan d3266ee50e Use EU project index for top authors
LocationBasedServices/smartguide/pipeline/head This commit looks good
2026-07-20 20:37:40 +02:00
spsaefan 410bcdec4b Use OpenAlex IDs for EU authors
LocationBasedServices/smartguide/pipeline/head This commit looks good
2026-07-17 13:32:59 +02:00
3 changed files with 617 additions and 545 deletions
+189 -35
View File
@@ -1,6 +1,8 @@
import asyncio
import logging
import re
from types import SimpleNamespace
from collections import defaultdict
from datetime import datetime
from typing import Any, Literal
@@ -38,6 +40,14 @@ from .model import (
TopicWordCloud,
TopicWordCloudWord,
)
from inse.projects.eu_cordis_projects_client import (
get_eu_project_ids_by_organization_filters,
)
from inse.projects.model import (
EuCordisProjectType,
ProjectType,
ProjectsFilteringProperties,
)
TOP_AUTHOR_LIMIT = 10
TOPIC_HEATMAP_LIMIT = 25
@@ -49,6 +59,30 @@ DashboardPeriod = tuple[int | None, int | None]
logger = logging.getLogger(__name__)
async def get_eu_organization_project_contributions(
organization_names: list[str],
projects_filtering_properties: ProjectsFilteringProperties,
) -> SimpleNamespace:
project_ids_by_type = await get_eu_project_ids_by_organization_filters(
project_types=list(EuCordisProjectType),
organization_names=organization_names,
)
project_ids = {
str(project_id)
for ids in project_ids_by_type.values()
for project_id in ids
}
return SimpleNamespace(
elements=[
SimpleNamespace(project_id=project_id)
for project_id in sorted(project_ids)
],
total=len(project_ids),
page=projects_filtering_properties.page,
size=projects_filtering_properties.size,
)
ACADEMIC_TITLE_RE = re.compile(
r"^(?:(?:professor(?:in)?|prof|dr)(?:\.-[a-z]+)?\.?|rer\.|nat\.|med\.|ing\.)\s+",
re.IGNORECASE,
@@ -940,6 +974,7 @@ async def get_top_authors(
from_year = datetime.now().year - 4
to_year = datetime.now().year
period = _dashboard_period(from_year, to_year)
aliases = await _institution_aliases(normalized_id, organization_name)
authors = await _safe_institution_authors(normalized_id)
works = _top_work_authors(authors, period)
projects = await _safe_top_authors(
@@ -953,8 +988,9 @@ async def get_top_authors(
)
eu_projects = await _safe_top_authors(
"eu_projects",
_top_eu_project_publication_authors(),
_top_eu_project_publication_authors(normalized_id, aliases, authors),
)
patents = await _safe_top_authors(
"patents",
_top_patent_authors(
@@ -963,10 +999,12 @@ async def get_top_authors(
to_year=period[1],
),
)
news = await _safe_top_authors(
"news",
_top_news_authors(authors),
)
return TopAuthorStatistics(
institution_id=normalized_id,
works=works,
@@ -1921,52 +1959,168 @@ async def _top_patent_authors(
]
async def _top_eu_project_publication_authors() -> list[TopAuthor]:
response = await elasticsearch.search(
index=ESIndex.CORDIS_EU_FP7_PUBLICATIONS,
async def _top_eu_project_publication_authors(
institution_id: str,
organization_names: list[str],
institution_authors: list[dict[str, Any]],
) -> list[TopAuthor]:
institution_author_ids = {
author_id
for author in institution_authors
if (author_id := _normalize_author_id(author.get("id")))
}
if not institution_author_ids:
return []
project_page = await get_eu_organization_project_contributions(
organization_names=organization_names,
projects_filtering_properties=ProjectsFilteringProperties(
project_type=ProjectType.EU,
page=0,
size=10000,
),
)
project_ids = [project.project_id for project in project_page.elements]
if not project_ids:
return []
publication_response = await elasticsearch.search(
index=ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD,
body={
"size": 0,
"aggs": {
"authors": {
"terms": {
"script": {
"lang": "painless",
"source": _cordis_publication_authors_script(),
},
"size": TOP_AUTHOR_LIMIT,
"order": {"_count": "desc"},
}
"size": 10000,
"_source": ["projectID", "qaProcessedDoi"],
"query": {
"terms": {
"projectID": project_ids,
}
},
},
cluster=ESCluster.INSE,
)
doi_project_ids = _cordis_publication_doi_project_ids(
publication_response,
set(project_ids),
)
if not doi_project_ids:
return []
works_response = await elasticsearch.search(
index="openalex-works",
body={
"size": 10000,
"_source": [
"doi",
"authorships.author.id",
"authorships.author.display_name",
"authorships.institutions.id",
],
"query": {
"bool": {
"filter": [
{"terms": {"doi": sorted(doi_project_ids)}},
_institution_works_query(institution_id),
]
}
},
},
cluster=ESCluster.NES,
)
return _openalex_work_authors_by_eu_projects(
works_response,
doi_project_ids,
institution_id,
institution_author_ids,
)
def _cordis_publication_doi_project_ids(
response: dict[str, Any],
allowed_project_ids: set[str],
) -> dict[str, set[str]]:
doi_project_ids: dict[str, set[str]] = defaultdict(set)
for hit in response.get("hits", {}).get("hits", []):
source = hit.get("_source", {})
project_id = str(source.get("projectID") or "").strip()
if not project_id or project_id not in allowed_project_ids:
continue
doi = _normalize_doi(source.get("qaProcessedDoi"))
if doi:
doi_project_ids[doi].add(project_id)
return dict(doi_project_ids)
def _normalize_doi(value: Any) -> str | None:
if not isinstance(value, str) or not value.strip():
return None
doi = value.strip().lower()
if doi.startswith("https://doi.org/"):
return doi
if doi.startswith("http://doi.org/"):
return "https://" + doi.removeprefix("http://")
if doi.startswith("doi.org/"):
return f"https://{doi}"
return f"https://doi.org/{doi}"
def _openalex_work_authors_by_eu_projects(
response: dict[str, Any],
doi_project_ids: dict[str, set[str]],
institution_id: str,
institution_author_ids: set[str],
) -> list[TopAuthor]:
# Count unique CORDIS projects per author, not publications. Multiple works
# (and therefore multiple DOIs) can belong to the same project ID.
author_project_ids: dict[str, set[str]] = defaultdict(set)
author_names: dict[str, str] = {}
for hit in response.get("hits", {}).get("hits", []):
source = hit.get("_source", {})
project_ids = doi_project_ids.get(_normalize_doi(source.get("doi")) or "")
if not project_ids:
continue
for authorship in source.get("authorships") or []:
if not any(
institution.get("id") == institution_id
for institution in authorship.get("institutions") or []
):
continue
author = authorship.get("author") or {}
author_id = _normalize_author_id(author.get("id"))
author_name = str(author.get("display_name") or "").strip()
if (
not author_id
or author_id not in institution_author_ids
or not author_name
):
continue
author_project_ids[author_id].update(project_ids)
author_names.setdefault(author_id, author_name)
ranked_authors = sorted(
author_project_ids.items(),
key=lambda item: (-len(item[1]), author_names.get(item[0], ""), item[0]),
)
return [
TopAuthor(
name=str(bucket["key"]),
count=int(bucket.get("doc_count", 0)),
id=_short_author_id(author_id),
name=author_names[author_id],
count=len(project_ids),
)
for bucket in (
response.get("aggregations", {}).get("authors", {}).get("buckets", [])
)
if str(bucket.get("key", "")).strip()
for author_id, project_ids in ranked_authors[:TOP_AUTHOR_LIMIT]
]
def _cordis_publication_authors_script() -> str:
return (
"def names = new HashSet(); "
"def source = params['_source']; "
"def value = source.containsKey('authors') ? source['authors'] "
" : (source.containsKey('Authors') ? source['Authors'] : null); "
"if (value instanceof String && value.length() > 0) { "
" for (name in value.splitOnToken(';')) { "
" def trimmed = name.trim(); "
" if (trimmed.length() > 0) { names.add(trimmed); } "
" } "
"} "
"return new ArrayList(names);"
)
def _normalize_author_id(value: Any) -> str | None:
if not isinstance(value, str) or not value.strip():
return None
short_id = value.replace("https://openalex.org/", "").strip().upper()
return f"https://openalex.org/{short_id}"
async def _top_news_authors(authors: list[dict[str, Any]]) -> list[TopAuthor]:
File diff suppressed because it is too large Load Diff
@@ -1,7 +1,7 @@
/**
* Innovation Search Engine API
*
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech