add analysis for author with publication in the future

This commit is contained in:
Steven Tischer
2026-08-17 19:59:42 +02:00
parent 1f2636b95d
commit 2f90d8f16a
+55 -1
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import argparse
import re
from collections import Counter
from datetime import date
import requests
@@ -275,6 +276,44 @@ def fetch_analysis_6_data(
return rows
def fetch_analysis_7_data(institution_id: str | None = None) -> list[dict]:
current_year = date.today().year
query = with_institution_filter({"match_all": {}}, institution_id)
sort = [{"id": "asc"}]
page_size = 1000
rows = []
search_after = None
while True:
result = search(
query=query,
size=page_size,
sort=sort,
source=["id", "counts_by_year"],
search_after=search_after,
)
hits = result["hits"]["hits"]
if not hits:
break
for hit in hits:
author_id = hit["_source"]["id"].rsplit("/", 1)[-1]
for entry in hit["_source"].get("counts_by_year", []):
year = entry.get("year")
if year is not None and year > current_year:
rows.append({"author_id": author_id, "year": year})
if len(hits) < page_size:
break
search_after = hits[-1]["sort"]
return rows
def print_table(headers: list[str], rows: list[list[str]]) -> None:
widths = [
max(len(str(cell)) for cell in [header, *(row[i] for row in rows)])
@@ -387,6 +426,20 @@ def run_analysis_6(institution_id: str | None = None) -> None:
)
def run_analysis_7(institution_id: str | None = None) -> None:
current_year = date.today().year
print(
f"Analyse 7: Publikationsjahre aus counts_by_year in der Zukunft "
f"(> {current_year})."
)
analysis_7_data = fetch_analysis_7_data(institution_id)
analysis_7_data.sort(key=lambda entry: entry["year"], reverse=True)
print_table(
["OpenAlexID", "Jahr"],
[[entry["author_id"], entry["year"]] for entry in analysis_7_data],
)
ANALYSES = {
1: run_analysis_1,
2: run_analysis_2,
@@ -394,6 +447,7 @@ ANALYSES = {
4: run_analysis_4,
5: run_analysis_5,
6: run_analysis_6,
7: run_analysis_7,
}
@@ -405,7 +459,7 @@ def parse_args() -> argparse.Namespace:
"--analysis",
type=int,
choices=sorted(ANALYSES),
help="Nur diese Analyse ausführen (1-6). Ohne Angabe werden alle ausgeführt.",
help="Nur diese Analyse ausführen (1-7). Ohne Angabe werden alle ausgeführt.",
)
parser.add_argument(
"--filter-uni",