fix publications
This commit is contained in:
@@ -30,6 +30,7 @@ from inse.projects.model import (
|
||||
ProjectsFilteringProperties,
|
||||
ProjectType,
|
||||
)
|
||||
from inse.works.v2 import service as works_v2_service
|
||||
|
||||
from .institute_helper import get_openalex_institution
|
||||
from .model import (
|
||||
@@ -241,25 +242,32 @@ async def get_dashboard_publications(
|
||||
) -> DashboardStatisticValue:
|
||||
normalized_id = _normalize_institution_id(institution_id)
|
||||
period = _dashboard_period(from_year, to_year)
|
||||
institution = await institutions_v2_service.get_institution_by_id_or_raise(
|
||||
raw_oa_institution_id=_raw_institution_id(normalized_id),
|
||||
source=["id", "works_count", "counts_by_year"],
|
||||
)
|
||||
if period == (None, None):
|
||||
value = int(institution.works_count or 0)
|
||||
else:
|
||||
value = sum(
|
||||
int(entry.works_count or 0)
|
||||
for entry in institution.counts_by_year or []
|
||||
if (
|
||||
(period[0] is None or int(entry.year or 0) >= period[0])
|
||||
and (period[1] is None or int(entry.year or 0) <= period[1])
|
||||
)
|
||||
institution = await institutions_v2_service.get_institution_by_id_or_raise(
|
||||
raw_oa_institution_id=_raw_institution_id(normalized_id),
|
||||
source=["id", "works_count"],
|
||||
)
|
||||
return DashboardStatisticValue(
|
||||
institution_id=normalized_id,
|
||||
organization_name=organization_name,
|
||||
value=int(institution.works_count or 0),
|
||||
)
|
||||
|
||||
first_year = period[0] if period[0] is not None else 1900
|
||||
last_year = period[1] if period[1] is not None else 2100
|
||||
publication_years = list(range(first_year, last_year + 1))
|
||||
|
||||
works = await works_v2_service.get_institution_works(
|
||||
raw_oa_institution_id=_raw_institution_id(normalized_id),
|
||||
page=0,
|
||||
size=1,
|
||||
publication_years=publication_years,
|
||||
)
|
||||
|
||||
return DashboardStatisticValue(
|
||||
institution_id=normalized_id,
|
||||
organization_name=organization_name,
|
||||
value=value,
|
||||
value=works.total,
|
||||
)
|
||||
|
||||
|
||||
@@ -339,16 +347,8 @@ async def get_dashboard_eu_projects(
|
||||
topic_ids=None,
|
||||
filter_topic_ids=None,
|
||||
title=None,
|
||||
funding_start_years=(
|
||||
[str(year) for year in range(1900, period[1] + 1)]
|
||||
if period[1] is not None
|
||||
else None
|
||||
),
|
||||
funding_end_years=(
|
||||
[str(year) for year in range(period[0], 2101)]
|
||||
if period[0] is not None
|
||||
else None
|
||||
),
|
||||
funding_start_years=[str(period[0])] if period[0] is not None else None,
|
||||
funding_end_years=[str(period[1])] if period[1] is not None else None,
|
||||
countries=None,
|
||||
framework_programmes=None,
|
||||
funding_schemes=None,
|
||||
@@ -515,16 +515,8 @@ async def get_dashboard_bmbf_projects(
|
||||
funding_arts=None,
|
||||
topic_ids=None,
|
||||
filter_topic_ids=None,
|
||||
funding_start_years=(
|
||||
[str(year) for year in range(1900, period[1] + 1)]
|
||||
if period[1] is not None
|
||||
else None
|
||||
),
|
||||
funding_end_years=(
|
||||
[str(year) for year in range(period[0], 2101)]
|
||||
if period[0] is not None
|
||||
else None
|
||||
),
|
||||
funding_start_years=[str(period[0])] if period[0] is not None else None,
|
||||
funding_end_years=[str(period[1])] if period[1] is not None else None,
|
||||
countries=None,
|
||||
page=0,
|
||||
size=1,
|
||||
@@ -632,16 +624,8 @@ async def get_dashboard_dfg_projects(
|
||||
topic_ids=None,
|
||||
filter_topic_ids=None,
|
||||
title=None,
|
||||
funding_start_years=(
|
||||
[str(year) for year in range(1900, period[1] + 1)]
|
||||
if period[1] is not None
|
||||
else None
|
||||
),
|
||||
funding_end_years=(
|
||||
[str(year) for year in range(period[0], 2101)]
|
||||
if period[0] is not None
|
||||
else None
|
||||
),
|
||||
funding_start_years=[str(period[0])] if period[0] is not None else None,
|
||||
funding_end_years=[str(period[1])] if period[1] is not None else None,
|
||||
page=0,
|
||||
size=1,
|
||||
sort_by="id",
|
||||
|
||||
@@ -25,7 +25,6 @@ from inse.dashboard.service import (
|
||||
get_topic_word_cloud,
|
||||
)
|
||||
from inse.model import ESCluster, ESIndex
|
||||
from inse.models.openalex.author_counts_by_year_inner import AuthorCountsByYearInner
|
||||
from inse.models.openalex.institution import Institution
|
||||
from inse.models.openalex.meta import Meta
|
||||
from inse.persons.model import CustomAuthorsListResponse
|
||||
@@ -229,22 +228,18 @@ async def test_dashboard_statistics_counts_organization_data_and_all_projects():
|
||||
"bmbf_projects": 5,
|
||||
}
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_dashboard_publications_uses_institutions_v2_counts():
|
||||
institution = Institution(
|
||||
id=ORG_INSTITUTION_ID,
|
||||
works_count=250,
|
||||
counts_by_year=[
|
||||
AuthorCountsByYearInner(year=2021, works_count=10),
|
||||
AuthorCountsByYearInner(year=2022, works_count=12),
|
||||
AuthorCountsByYearInner(year=2023, works_count=14),
|
||||
],
|
||||
)
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_dashboard_publications_uses_works_v2_only_for_period():
|
||||
with patch(
|
||||
"inse.dashboard.service.institutions_v2_service.get_institution_by_id_or_raise",
|
||||
new=AsyncMock(return_value=institution),
|
||||
) as mocked_get_institution:
|
||||
new=AsyncMock(
|
||||
return_value=Institution(id=ORG_INSTITUTION_ID, works_count=250)
|
||||
),
|
||||
) as mocked_get_institution, patch(
|
||||
"inse.dashboard.service.works_v2_service.get_institution_works",
|
||||
new=AsyncMock(return_value=SimpleNamespace(elements=[], total=22)),
|
||||
) as mocked_get_works:
|
||||
all_time = await get_dashboard_publications(
|
||||
ORG_INSTITUTION_ID,
|
||||
"Example Org",
|
||||
@@ -258,9 +253,15 @@ async def test_dashboard_publications_uses_institutions_v2_counts():
|
||||
|
||||
assert all_time.value == 250
|
||||
assert selected_period.value == 22
|
||||
assert mocked_get_institution.await_args_list[0].kwargs == {
|
||||
mocked_get_institution.assert_awaited_once_with(
|
||||
raw_oa_institution_id="I123",
|
||||
source=["id", "works_count"],
|
||||
)
|
||||
assert mocked_get_works.await_args_list[0].kwargs == {
|
||||
"raw_oa_institution_id": "I123",
|
||||
"source": ["id", "works_count", "counts_by_year"],
|
||||
"page": 0,
|
||||
"size": 1,
|
||||
"publication_years": [2021, 2022],
|
||||
}
|
||||
|
||||
|
||||
@@ -362,8 +363,8 @@ async def test_dashboard_eu_projects_uses_projects_service_total():
|
||||
mocked_get_projects.assert_awaited_once()
|
||||
call = mocked_get_projects.await_args
|
||||
assert call.kwargs["raw_oa_institution_id"] == "I123"
|
||||
assert call.kwargs["funding_start_years"][-1] == "2021"
|
||||
assert call.kwargs["funding_end_years"][0] == "2019"
|
||||
assert call.kwargs["funding_start_years"] == ["2019"]
|
||||
assert call.kwargs["funding_end_years"] == ["2021"]
|
||||
assert call.kwargs["project_types"] == list(EuCordisProjectType)
|
||||
assert call.kwargs["page"] == 0
|
||||
assert call.kwargs["size"] == 1
|
||||
|
||||
Reference in New Issue
Block a user