SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 29d47168 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add country-level nap data

parent 08e88284
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
<thead>
<tr>
<th></th>
<th style="text-align: right;">NAP</th>
<th style="text-align: right;">Expenditures</th>
<th style="text-align: right;">Subsidy income</th>
<th style="text-align: right;">Impact on reserves</th>
......@@ -15,6 +16,7 @@
<tbody>
<tr class="bg-light">
<td>Cumulative</td>
<td style="text-align: right;">{{ cumulative.nap }}</td>
<td style="text-align: right;">&euro;{{ cumulative.expenditures }}</td>
<td style="text-align: right;">&euro;{{ cumulative.subsidy_income }}</td>
<td style="text-align: right;">&euro;{{ cumulative.impact_on_reserves }}</td>
......@@ -22,6 +24,7 @@
{% for year, val in per_year.items %}
<tr>
<td>{{ year }}</td>
<td style="text-align: right;">{{ val.nap }}</td>
<td style="text-align: right;">&euro;{{ val.expenditures }}</td>
<td style="text-align: right;">&euro;{{ val.subsidy_income }}</td>
<td style="text-align: right;">&euro;{{ val.impact_on_reserves }}</td>
......@@ -42,6 +45,7 @@
<tr>
<th></th>
<th></th>
<th style="text-align: right;">NAP</th>
<th style="text-align: right;">Expenditures</th>
<th style="text-align: right;">Subsidy Income</th>
<th style="text-align: right;">Impact on reserves</th>
......@@ -51,6 +55,7 @@
<tr class="bg-light">
<td>Total</td>
<td></td>
<td style="text-align: right;">{{ cumulative.nap }}</td>
<td style="text-align: right;">{{ cumulative.expenditures }}</td>
<td style="text-align: right;">{{ cumulative.subsidy_income }}</td>
<td style="text-align: right;">{{ cumulative.impact_on_reserves }}</td>
......@@ -60,6 +65,7 @@
<tr>
<td><a href="https://{{ request.get_host }}{{ organization.get_absolute_url }}">{{ organization }}</a></td>
<td>{{ organization.get_orgtype_display }}</td>
<td style="text-align: right;">{{ organization.cf_balance_info.cumulative.nap }}</td>
<td style="text-align: right;">{{ organization.cf_balance_info.cumulative.expenditures }}</td>
<td style="text-align: right;">{{ organization.cf_balance_info.cumulative.subsidy_income }}</td>
<td style="text-align: right;">{{ organization.cf_balance_info.cumulative.impact_on_reserves }}</td>
......
......@@ -3,13 +3,13 @@ __license__ = "AGPL v3"
import datetime
from itertools import accumulate
from itertools import accumulate, chain
import mimetypes
from dal import autocomplete
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import Q, Count, OuterRef, Subquery
from django.db.models import Q, Count, Exists, OuterRef, Subquery
from django.db.models.functions import Coalesce
from django.template.response import TemplateResponse
from django.utils.html import format_html
......@@ -17,6 +17,7 @@ import matplotlib
from common.views import HXDynselAutocomplete, HXDynselSelectOptionView
from finances.constants import SUBSIDY_TYPE_SPONSORSHIPAGREEMENT, SUBSIDY_PROMISED
from journals.models.publication import PublicationAuthorsTable
matplotlib.use("Agg")
import matplotlib.pyplot as plt
......@@ -281,14 +282,40 @@ def _hx_country_level_data(request, country):
context = {
"country": country,
"organizations": organizations,
"cumulative": {"subsidy_income": 0, "expenditures": 0, "impact_on_reserves": 0},
"cumulative": {
"subsidy_income": 0,
"expenditures": 0,
"impact_on_reserves": 0,
"nap": len(
set(chain.from_iterable([o.get_publications() for o in organizations]))
),
},
"per_year": {},
}
def get_yearly_nap_of_country(country: str) -> dict[int, int]:
return dict(
Publication.objects.annotate(
has_author_of_country=Exists(
PublicationAuthorsTable.objects.filter(
publication=OuterRef("pk"), affiliations__country=country
)
)
)
.filter(has_author_of_country=True)
.values("publication_date__year")
.annotate(nr=Count("publication_date__year"))
.order_by("publication_date__year")
.values_list("publication_date__year", "nr")
)
country_yearly_nap = get_yearly_nap_of_country(country)
for year in pubyears:
context["per_year"][year] = {
"subsidy_income": 0,
"expenditures": 0,
"impact_on_reserves": 0,
"nap": country_yearly_nap.get(int(year), 0),
}
for organization in organizations.all():
for key in ("subsidy_income", "expenditures", "impact_on_reserves"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment