Merge pull request 'analysis/researcher-career-stage' (#221) from analysis/researcher-career-stage into dev
LocationBasedServices/smartguide/pipeline/head This commit looks good
Reviewed-on: #221
@@ -0,0 +1,59 @@
|
||||
# Career-Stage-Analyse
|
||||
|
||||
Diese Analyse untersucht, wie sich der Karrierestatus von Forschenden (Professor vs.
|
||||
Researcher) aus deren Publikationshistorie in OpenAlex ableiten lässt. Das Ergebnis ist die
|
||||
Grundlage für die Career-Stage-Klassifikation im SmartGuide-Backend.
|
||||
|
||||
## Vorgehen
|
||||
|
||||
- **Stichprobe:** 60 Forschende der UDE mit manuell recherchiertem, bekanntem Status
|
||||
(31 Professor, 29 Researcher inkl. Doctoral Researcher) aus fünf Disziplingruppen:
|
||||
Biology, Computer Science, Engineering, Medicine, Sociology
|
||||
([career_stage_sample.csv](career_stage_sample.csv)).
|
||||
- **Datenerhebung:** Für jede Person wurden alle Werke über die OpenAlex-API geladen
|
||||
([openalex_client.py](openalex_client.py)) und daraus pro Person Metriken berechnet
|
||||
([career_stage_analysis.py](career_stage_analysis.py) →
|
||||
[career_stage_results.csv](career_stage_results.csv)):
|
||||
- `career_span`: Jahre vom ersten bis zum letzten Publikationsjahr (inklusiv)
|
||||
- `active_years`: Anzahl **unterschiedlicher** Jahre mit mindestens einer Publikation
|
||||
- `publication_count`, `publications_per_active_year`, `publications_per_career_year`,
|
||||
`years_since_last_publication`
|
||||
- **Auswertung:** Vergleich der Metriken zwischen den bekannten Status-Gruppen, auch je
|
||||
Disziplingruppe ([career_stage_visualization.py](career_stage_visualization.py) →
|
||||
[plots/](plots/), [summaries/](summaries/)).
|
||||
|
||||
## Ergebnisse
|
||||
|
||||
Die Gruppen trennen sich deutlich (Median Professor vs. Researcher):
|
||||
|
||||
| Metrik | Professor | Researcher |
|
||||
| ----------------------------- | --------- | ---------- |
|
||||
| Aktive Publikationsjahre | 28 | 5 |
|
||||
| Career Span (Jahre) | 31 | 7 |
|
||||
| Publikationen | 224 | 11 |
|
||||
| Publikationen je aktivem Jahr | 7,6 | 1,8 |
|
||||
|
||||
Wichtigste Erkenntnis: **`career_span` ist unzuverlässig.** Fehlerhafte Autorenzuordnungen in
|
||||
OpenAlex führen zu unplausibel frühen Erstpublikationen (z. B. 1893/1906 bei aktiven
|
||||
Professor:innen) und blähen die Spannweite massiv auf (Mittelwert 45 Jahre bei Median 31).
|
||||
**`active_years` ist dagegen robust:** Ein einzelnes falsch zugeordnetes altes Werk erhöht die
|
||||
Spannweite um Jahrzehnte, die aktiven Jahre aber nur um 1. Die Trennung zwischen den Gruppen
|
||||
ist bei `active_years` zudem über alle Disziplingruppen hinweg konsistent.
|
||||
|
||||
## Fazit: finale Entscheidungskriterien im Projekt
|
||||
|
||||
Die Career Stage wird im Backend ausschließlich über die **aktiven Publikationsjahre**
|
||||
(`active_years`) bestimmt (siehe `_classify_career_stage` in
|
||||
`service/src/main/inse/persons/logic.py`):
|
||||
|
||||
| Aktive Jahre | Career Stage |
|
||||
| ------------ | ------------ |
|
||||
| 0 | unknown |
|
||||
| 1–4 | Early |
|
||||
| 5–9 | Emerging |
|
||||
| 10–14 | Established |
|
||||
| ≥ 15 | Senior |
|
||||
|
||||
Zusätzlich wird `has_suspicious_publication_years` gesetzt (Erstpublikation vor 1970 oder
|
||||
Career Span > 60 Jahre), um Personen mit vermutlich fehlerhafter OpenAlex-Zuordnung zu
|
||||
kennzeichnen.
|
||||
@@ -0,0 +1,195 @@
|
||||
import csv
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from openalex_client import get_all_author_works
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
INPUT_FILE = BASE_DIR / "career_stage_sample.csv"
|
||||
OUTPUT_FILE = BASE_DIR / "career_stage_results.csv"
|
||||
|
||||
|
||||
def extract_publication_years(works: list[dict[str, Any]]) -> list[int]:
|
||||
"""
|
||||
Extracts all valid publication years from the OpenAlex works response.
|
||||
|
||||
One entry in the returned list represents one publication.
|
||||
Therefore, duplicate years are intentionally kept.
|
||||
Example:
|
||||
[2020, 2020, 2021] means 3 publications in 2 active years.
|
||||
"""
|
||||
years: list[int] = []
|
||||
|
||||
for work in works:
|
||||
year = work.get("publication_year")
|
||||
|
||||
if isinstance(year, int):
|
||||
years.append(year)
|
||||
elif isinstance(year, str) and year.isdigit():
|
||||
years.append(int(year))
|
||||
|
||||
return years
|
||||
|
||||
|
||||
def normalize_known_status(known_status: str) -> str:
|
||||
"""
|
||||
Normalizes manually assigned status labels.
|
||||
|
||||
The analysis compares Professor vs Researcher. Doctoral Researcher is therefore
|
||||
mapped to Researcher to keep the groups consistent.
|
||||
"""
|
||||
cleaned_status = known_status.strip()
|
||||
|
||||
if cleaned_status == "Doctoral Researcher":
|
||||
return "Researcher"
|
||||
|
||||
return cleaned_status
|
||||
|
||||
|
||||
def compute_metrics(publication_years: list[int]) -> dict[str, int | float | None]:
|
||||
"""
|
||||
Computes publication-history-based career metrics.
|
||||
|
||||
Important distinction:
|
||||
- publication_count counts all publications
|
||||
- active_years counts distinct years with at least one publication
|
||||
- career_span counts the full inclusive span from first to last publication year
|
||||
"""
|
||||
current_year = datetime.now().year
|
||||
|
||||
if not publication_years:
|
||||
return {
|
||||
"first_publication_year": None,
|
||||
"last_publication_year": None,
|
||||
"career_age": None,
|
||||
"career_span": None,
|
||||
"active_years": 0,
|
||||
"publication_count": 0,
|
||||
"publications_per_active_year": None,
|
||||
"publications_per_career_year": None,
|
||||
"years_since_last_publication": None,
|
||||
}
|
||||
|
||||
sorted_years = sorted(publication_years)
|
||||
unique_years = sorted(set(publication_years))
|
||||
|
||||
first_year = sorted_years[0]
|
||||
last_year = sorted_years[-1]
|
||||
|
||||
publication_count = len(sorted_years)
|
||||
active_years = len(unique_years)
|
||||
|
||||
career_age = last_year - first_year
|
||||
career_span = last_year - first_year + 1
|
||||
|
||||
publications_per_active_year = (
|
||||
publication_count / active_years if active_years > 0 else None
|
||||
)
|
||||
|
||||
publications_per_career_year = (
|
||||
publication_count / career_span if career_span > 0 else None
|
||||
)
|
||||
|
||||
years_since_last_publication = current_year - last_year
|
||||
|
||||
return {
|
||||
"first_publication_year": first_year,
|
||||
"last_publication_year": last_year,
|
||||
"career_age": career_age,
|
||||
"career_span": career_span,
|
||||
"active_years": active_years,
|
||||
"publication_count": publication_count,
|
||||
"publications_per_active_year": publications_per_active_year,
|
||||
"publications_per_career_year": publications_per_career_year,
|
||||
"years_since_last_publication": years_since_last_publication,
|
||||
}
|
||||
|
||||
|
||||
def create_empty_metrics() -> dict[str, int | float | None]:
|
||||
return {
|
||||
"first_publication_year": None,
|
||||
"last_publication_year": None,
|
||||
"career_age": None,
|
||||
"career_span": None,
|
||||
"active_years": 0,
|
||||
"publication_count": 0,
|
||||
"publications_per_active_year": None,
|
||||
"publications_per_career_year": None,
|
||||
"years_since_last_publication": None,
|
||||
}
|
||||
|
||||
|
||||
def analyze_sample() -> None:
|
||||
if not INPUT_FILE.exists():
|
||||
raise FileNotFoundError(f"Input file not found: {INPUT_FILE}")
|
||||
|
||||
results: list[dict[str, Any]] = []
|
||||
|
||||
with INPUT_FILE.open(mode="r", encoding="utf-8", newline="") as input_file:
|
||||
reader = csv.DictReader(input_file)
|
||||
|
||||
for row in reader:
|
||||
name = row.get("name", "").strip()
|
||||
discipline = row.get("discipline", "").strip()
|
||||
discipline_group = row.get("discipline_group", "").strip()
|
||||
known_status = normalize_known_status(row.get("known_status", ""))
|
||||
openalex_author_id = row.get("openalex_author_id", "").strip()
|
||||
|
||||
if not discipline_group:
|
||||
discipline_group = discipline
|
||||
|
||||
if not openalex_author_id:
|
||||
print(f"Skipping {name}: missing OpenAlex author ID")
|
||||
continue
|
||||
|
||||
print(f"Fetching works for {name} ({openalex_author_id})...")
|
||||
|
||||
try:
|
||||
works = get_all_author_works(openalex_author_id)
|
||||
publication_years = extract_publication_years(works)
|
||||
metrics = compute_metrics(publication_years)
|
||||
|
||||
except Exception as error:
|
||||
print(f"Error while processing {name}: {error}")
|
||||
metrics = create_empty_metrics()
|
||||
|
||||
results.append(
|
||||
{
|
||||
"name": name,
|
||||
"discipline": discipline,
|
||||
"discipline_group": discipline_group,
|
||||
"known_status": known_status,
|
||||
"openalex_author_id": openalex_author_id,
|
||||
**metrics,
|
||||
}
|
||||
)
|
||||
|
||||
fieldnames = [
|
||||
"name",
|
||||
"discipline",
|
||||
"discipline_group",
|
||||
"known_status",
|
||||
"openalex_author_id",
|
||||
"first_publication_year",
|
||||
"last_publication_year",
|
||||
"career_age",
|
||||
"career_span",
|
||||
"active_years",
|
||||
"publication_count",
|
||||
"publications_per_active_year",
|
||||
"publications_per_career_year",
|
||||
"years_since_last_publication",
|
||||
]
|
||||
|
||||
with OUTPUT_FILE.open(mode="w", encoding="utf-8", newline="") as output_file:
|
||||
writer = csv.DictWriter(output_file, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
writer.writerows(results)
|
||||
|
||||
print(f"Analysis finished. Results written to {OUTPUT_FILE}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
analyze_sample()
|
||||
@@ -0,0 +1,61 @@
|
||||
name,discipline,discipline_group,known_status,openalex_author_id,first_publication_year,last_publication_year,career_age,career_span,active_years,publication_count,publications_per_active_year,publications_per_career_year,years_since_last_publication
|
||||
Barbara Saccà,Biology,Biology,Professor,A5075803366,1997,2024,27,28,26,91,3.5,3.25,2
|
||||
Bernd Sures,Biology,Biology,Professor,A5088631999,1994,2026,32,33,32,410,12.8125,12.424242424242424,0
|
||||
Daniel Hering,Biology,Biology,Professor,A5031147249,1893,2026,133,134,37,326,8.81081081081081,2.4328358208955225,0
|
||||
Daniel Hoffmann,Biology,Biology,Professor,A5074555350,1966,2026,60,61,35,332,9.485714285714286,5.442622950819672,0
|
||||
Peter Bayer,Biology,Biology,Professor,A5060566345,1969,2026,57,58,37,358,9.675675675675675,6.172413793103448,0
|
||||
Bianca Kamba,Biology,Biology,Researcher,A5036363877,2017,2025,8,9,4,9,2.25,1.0,1
|
||||
Daniel Grabner,Biology,Biology,Researcher,A5063959731,1980,2026,46,47,19,95,5.0,2.021276595744681,0
|
||||
Farnusch Kaschani,Biology,Biology,Researcher,A5078099512,2005,2026,21,22,21,182,8.666666666666666,8.272727272727273,0
|
||||
Kathrin Januschke,Biology,Biology,Researcher,A5064225981,2011,2026,15,16,15,36,2.4,2.25,0
|
||||
Richard Kosinski,Biology,Biology,Researcher,A5014403509,1986,2022,36,37,4,6,1.5,0.16216216216216217,4
|
||||
Jens Krüger,Computer Graphics and Visualization,Computer Science,Professor,A5087449583,1964,2025,61,62,20,67,3.35,1.0806451612903225,1
|
||||
Torben Weis,Distributed Systems,Computer Science,Professor,A5016729057,1980,2026,46,47,43,197,4.5813953488372094,4.191489361702128,0
|
||||
Stefan Schneegaß,Human Computer Interaction,Computer Science,Professor,A5024328962,2008,2026,18,19,17,224,13.176470588235293,11.789473684210526,0
|
||||
Gregor Schiele,Intelligent Embedded Systems,Computer Science,Professor,A5028943371,1999,2026,27,28,22,155,7.045454545454546,5.535714285714286,0
|
||||
Pedro José Marrón,Networked Embedded Systems,Computer Science,Professor,A5047117780,1996,2026,30,31,28,285,10.178571428571429,9.193548387096774,0
|
||||
Lucas Davi,Secure Software Systems,Computer Science,Professor,A5089242868,2009,2026,17,18,18,137,7.611111111111111,7.611111111111111,0
|
||||
Volker Gruhn,Software Engineering,Computer Science,Professor,A5049739067,1989,2025,36,37,36,410,11.38888888888889,11.08108108108108,1
|
||||
Andreas Metzger,Software Systems Engineering,Computer Science,Professor,A5082025709,1992,2026,34,35,28,202,7.214285714285714,5.771428571428571,0
|
||||
Andreas Vogelsang,Software Systems Engineering,Computer Science,Professor,A5022998651,2005,2026,21,22,20,225,11.25,10.227272727272727,0
|
||||
Barbara König,Theoretical Computer Science,Computer Science,Professor,A5103103785,1906,2026,120,121,36,230,6.388888888888889,1.9008264462809918,0
|
||||
Alexandra Dmitrienko,Vertrauenswürdige Systeme,Computer Science,Professor,A5042835341,2010,2026,16,17,17,110,6.470588235294118,6.470588235294118,0
|
||||
Carina Liebers,Human Computer Interaction,Computer Science,Researcher,A5004350173,2022,2026,4,5,5,11,2.2,2.2,0
|
||||
Jonas Keppel,Human Computer Interaction,Computer Science,Researcher,A5015767175,2022,2026,4,5,5,11,2.2,2.2,0
|
||||
Carlos Medina Sánchez,Networked Embedded Systems,Computer Science,Researcher,A5093479876,2023,2025,2,3,2,2,1.0,0.6666666666666666,1
|
||||
Marcus Handte,Networked Embedded Systems,Computer Science,Researcher,A5007170803,2004,2026,22,23,23,107,4.6521739130434785,4.6521739130434785,0
|
||||
Simon Janzon,Networked Embedded Systems,Computer Science,Researcher,A5044472300,2020,2025,5,6,5,6,1.2,1.0,1
|
||||
Christian Niesler,Secure Software Systems,Computer Science,Researcher,A5069184110,2021,2026,5,6,5,9,1.8,1.5,0
|
||||
Christian Scholz,Secure Software Systems,Computer Science,Researcher,A5120610207,2025,2026,1,2,2,2,1.0,1.0,0
|
||||
Pascal Winkler,Secure Software Systems,Computer Science,Researcher,A5081189339,2009,2026,17,18,6,22,3.6666666666666665,1.2222222222222223,0
|
||||
Stefan Hanenberg,Software Engineering,Computer Science,Researcher,A5027034338,2000,2025,25,26,25,105,4.2,4.038461538461538,1
|
||||
Wilhelm Koop,Software Engineering,Computer Science,Researcher,A5019228221,2016,2022,6,7,6,14,2.3333333333333335,2.0,4
|
||||
Venkata Marella,Vertrauenswürdige Systeme,Computer Science,Researcher,A5082156768,2017,2026,9,10,8,11,1.375,1.1,0
|
||||
Burak Atakan,Engineering,Engineering,Professor,A5041521847,1989,2026,37,38,35,202,5.771428571428571,5.315789473684211,0
|
||||
Corina Andronescu,Engineering,Engineering,Professor,A5082583063,2008,2026,18,19,19,137,7.2105263157894735,7.2105263157894735,0
|
||||
Gerd Bacher,Engineering,Engineering,Professor,A5056038758,1985,2026,41,42,38,385,10.131578947368421,9.166666666666666,0
|
||||
Miriam Böhm,Engineering,Engineering,Researcher,A5037448457,2011,2021,10,11,8,12,1.5,1.0909090909090908,5
|
||||
Soheil Salighe,Steuerung Regelung und Systemdynamik,Engineering,Researcher,A5041884757,2017,2024,7,8,5,7,1.4,0.875,2
|
||||
Tobias Mikolas,Engineering,Engineering,Researcher,A5002909977,2021,2023,2,3,2,2,1.0,0.6666666666666666,3
|
||||
Boris Hadaschik,Medicine,Medicine,Professor,A5077243123,2001,2026,25,26,24,791,32.958333333333336,30.423076923076923,0
|
||||
Hartmut Schmidt,Medicine,Medicine,Professor,A5015932441,1910,2026,116,117,63,1024,16.253968253968253,8.752136752136753,0
|
||||
Matthias Gunzer,Medicine,Medicine,Professor,A5020520632,1997,2026,29,30,29,343,11.827586206896552,11.433333333333334,0
|
||||
Oliver Witzke,Medicine,Medicine,Professor,A5087456839,1954,2026,72,73,34,615,18.08823529411765,8.424657534246576,0
|
||||
Stephan Lang,Medicine,Medicine,Professor,A5030649192,1929,2026,97,98,44,859,19.522727272727273,8.76530612244898,0
|
||||
Tienush Rassaf,Medicine,Medicine,Professor,A5048609556,2002,2025,23,24,19,62,3.263157894736842,2.5833333333333335,1
|
||||
Ulrike Bingel,Medicine,Medicine,Professor,A5002281474,1998,2026,28,29,27,315,11.666666666666666,10.862068965517242,0
|
||||
Birte Möhlendick,Medicine,Medicine,Researcher,A5030635588,2010,2025,15,16,14,48,3.4285714285714284,3.0,1
|
||||
Julia Schwichtenberg,Medicine,Medicine,Researcher,A5119372151,2025,2026,1,2,2,3,1.5,1.5,0
|
||||
Katrin Schuldt,Medicine,Medicine,Researcher,A5002003996,2000,2026,26,27,7,12,1.7142857142857142,0.4444444444444444,0
|
||||
Sabrina Guckenbiehl,Medicine,Medicine,Researcher,A5008120333,2021,2026,5,6,6,31,5.166666666666667,5.166666666666667,0
|
||||
Zülal Cibir,Medicine,Medicine,Researcher,A5035081158,2019,2025,6,7,7,21,3.0,3.0,1
|
||||
Frank Kleemann,Sociology,Sociology,Professor,A5041694590,1999,2025,26,27,22,106,4.818181818181818,3.925925925925926,1
|
||||
Gregor Bongaerts,Sociology,Sociology,Professor,A5012265262,2000,2025,25,26,18,55,3.0555555555555554,2.1153846153846154,1
|
||||
Helen Baykara-Krumme,Sociology,Sociology,Professor,A5010111732,2007,2026,19,20,19,71,3.736842105263158,3.55,0
|
||||
Marcel Erlinghagen,Sociology,Sociology,Professor,A5021715937,1970,2026,56,57,29,131,4.517241379310345,2.2982456140350878,0
|
||||
Ute Klammer,Sociology,Sociology,Professor,A5055077517,1997,2026,29,30,25,146,5.84,4.866666666666666,0
|
||||
Andreas Jansen,Sociology,Sociology,Researcher,A5030957194,1991,2026,35,36,12,15,1.25,0.4166666666666667,0
|
||||
Antonia Görtz,Sociology,Sociology,Researcher,A5066776558,2022,2025,3,4,2,2,1.0,0.5,1
|
||||
Friedrich Scheller,Sociology,Sociology,Researcher,A5072565080,2014,2020,6,7,2,2,1.0,0.2857142857142857,6
|
||||
Lara Altenstädter,Sociology,Sociology,Researcher,A5070117981,2019,2023,4,5,5,15,3.0,3.0,3
|
||||
Lisa Mansfeld,Sociology,Sociology,Researcher,A5018318930,2021,2026,5,6,5,9,1.8,1.5,0
|
||||
|
@@ -0,0 +1,61 @@
|
||||
name,discipline,discipline_group,known_status,openalex_author_id
|
||||
Barbara Saccà,Biology,Biology,Professor,A5075803366
|
||||
Bernd Sures,Biology,Biology,Professor,A5088631999
|
||||
Daniel Hering,Biology,Biology,Professor,A5031147249
|
||||
Daniel Hoffmann,Biology,Biology,Professor,A5074555350
|
||||
Peter Bayer,Biology,Biology,Professor,A5060566345
|
||||
Bianca Kamba,Biology,Biology,Researcher,A5036363877
|
||||
Daniel Grabner,Biology,Biology,Researcher,A5063959731
|
||||
Farnusch Kaschani,Biology,Biology,Researcher,A5078099512
|
||||
Kathrin Januschke,Biology,Biology,Researcher,A5064225981
|
||||
Richard Kosinski,Biology,Biology,Researcher,A5014403509
|
||||
Jens Krüger,Computer Graphics and Visualization,Computer Science,Professor,A5087449583
|
||||
Torben Weis,Distributed Systems,Computer Science,Professor,A5016729057
|
||||
Stefan Schneegaß,Human Computer Interaction,Computer Science,Professor,A5024328962
|
||||
Gregor Schiele,Intelligent Embedded Systems,Computer Science,Professor,A5028943371
|
||||
Pedro José Marrón,Networked Embedded Systems,Computer Science,Professor,A5047117780
|
||||
Lucas Davi,Secure Software Systems,Computer Science,Professor,A5089242868
|
||||
Volker Gruhn,Software Engineering,Computer Science,Professor,A5049739067
|
||||
Andreas Metzger,Software Systems Engineering,Computer Science,Professor,A5082025709
|
||||
Andreas Vogelsang,Software Systems Engineering,Computer Science,Professor,A5022998651
|
||||
Barbara König,Theoretical Computer Science,Computer Science,Professor,A5103103785
|
||||
Alexandra Dmitrienko,Vertrauenswürdige Systeme,Computer Science,Professor,A5042835341
|
||||
Carina Liebers,Human Computer Interaction,Computer Science,Researcher,A5004350173
|
||||
Jonas Keppel,Human Computer Interaction,Computer Science,Researcher,A5015767175
|
||||
Carlos Medina Sánchez,Networked Embedded Systems,Computer Science,Researcher,A5093479876
|
||||
Marcus Handte,Networked Embedded Systems,Computer Science,Researcher,A5007170803
|
||||
Simon Janzon,Networked Embedded Systems,Computer Science,Researcher,A5044472300
|
||||
Christian Niesler,Secure Software Systems,Computer Science,Researcher,A5069184110
|
||||
Christian Scholz,Secure Software Systems,Computer Science,Researcher,A5120610207
|
||||
Pascal Winkler,Secure Software Systems,Computer Science,Researcher,A5081189339
|
||||
Stefan Hanenberg,Software Engineering,Computer Science,Researcher,A5027034338
|
||||
Wilhelm Koop,Software Engineering,Computer Science,Researcher,A5019228221
|
||||
Venkata Marella,Vertrauenswürdige Systeme,Computer Science,Researcher,A5082156768
|
||||
Burak Atakan,Engineering,Engineering,Professor,A5041521847
|
||||
Corina Andronescu,Engineering,Engineering,Professor,A5082583063
|
||||
Gerd Bacher,Engineering,Engineering,Professor,A5056038758
|
||||
Miriam Böhm,Engineering,Engineering,Researcher,A5037448457
|
||||
Soheil Salighe,Steuerung Regelung und Systemdynamik,Engineering,Researcher,A5041884757
|
||||
Tobias Mikolas,Engineering,Engineering,Researcher,A5002909977
|
||||
Boris Hadaschik,Medicine,Medicine,Professor,A5077243123
|
||||
Hartmut Schmidt,Medicine,Medicine,Professor,A5015932441
|
||||
Matthias Gunzer,Medicine,Medicine,Professor,A5020520632
|
||||
Oliver Witzke,Medicine,Medicine,Professor,A5087456839
|
||||
Stephan Lang,Medicine,Medicine,Professor,A5030649192
|
||||
Tienush Rassaf,Medicine,Medicine,Professor,A5048609556
|
||||
Ulrike Bingel,Medicine,Medicine,Professor,A5002281474
|
||||
Birte Möhlendick,Medicine,Medicine,Researcher,A5030635588
|
||||
Julia Schwichtenberg,Medicine,Medicine,Researcher,A5119372151
|
||||
Katrin Schuldt,Medicine,Medicine,Researcher,A5002003996
|
||||
Sabrina Guckenbiehl,Medicine,Medicine,Researcher,A5008120333
|
||||
Zülal Cibir,Medicine,Medicine,Researcher,A5035081158
|
||||
Frank Kleemann,Sociology,Sociology,Professor,A5041694590
|
||||
Gregor Bongaerts,Sociology,Sociology,Professor,A5012265262
|
||||
Helen Baykara-Krumme,Sociology,Sociology,Professor,A5010111732
|
||||
Marcel Erlinghagen,Sociology,Sociology,Professor,A5021715937
|
||||
Ute Klammer,Sociology,Sociology,Professor,A5055077517
|
||||
Andreas Jansen,Sociology,Sociology,Researcher,A5030957194
|
||||
Antonia Görtz,Sociology,Sociology,Researcher,A5066776558
|
||||
Friedrich Scheller,Sociology,Sociology,Researcher,A5072565080
|
||||
Lara Altenstädter,Sociology,Sociology,Researcher,A5070117981
|
||||
Lisa Mansfeld,Sociology,Sociology,Researcher,A5018318930
|
||||
|
@@ -0,0 +1,633 @@
|
||||
from pathlib import Path
|
||||
from typing import Callable, Literal
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
INPUT_FILE = BASE_DIR / "career_stage_results.csv"
|
||||
PLOTS_DIR = BASE_DIR / "plots"
|
||||
SUMMARY_DIR = BASE_DIR / "summaries"
|
||||
|
||||
STATUS_ORDER = ["Professor", "Researcher"]
|
||||
METRICS = [
|
||||
"career_span",
|
||||
"active_years",
|
||||
"publication_count",
|
||||
"publications_per_active_year",
|
||||
"publications_per_career_year",
|
||||
"years_since_last_publication",
|
||||
]
|
||||
|
||||
NUMERIC_COLUMNS = [
|
||||
"first_publication_year",
|
||||
"last_publication_year",
|
||||
"career_age",
|
||||
*METRICS,
|
||||
]
|
||||
|
||||
METRIC_LABELS = {
|
||||
"career_span": "Career Span in Years",
|
||||
"active_years": "Active Publication Years",
|
||||
"publication_count": "Number of Publications",
|
||||
"publications_per_active_year": "Publications per Active Year",
|
||||
"publications_per_career_year": "Publications per Career Year",
|
||||
"years_since_last_publication": "Years Since Last Publication",
|
||||
}
|
||||
|
||||
METRIC_TITLES = {
|
||||
"career_span": "Career Span",
|
||||
"active_years": "Active Publication Years",
|
||||
"publication_count": "Publication Count",
|
||||
"publications_per_active_year": "Publications per Active Year",
|
||||
"publications_per_career_year": "Publications per Career Year",
|
||||
"years_since_last_publication": "Years Since Last Publication",
|
||||
}
|
||||
|
||||
|
||||
StatisticFunction = Callable[[pd.Series], float]
|
||||
ScatterLabelMode = Literal["none", "outliers", "all"]
|
||||
|
||||
|
||||
def prepare_data() -> pd.DataFrame:
|
||||
if not INPUT_FILE.exists():
|
||||
raise FileNotFoundError(
|
||||
f"Input file not found: {INPUT_FILE}. "
|
||||
"Run career_stage_analysis.py first."
|
||||
)
|
||||
|
||||
df = pd.read_csv(INPUT_FILE)
|
||||
|
||||
if "discipline_group" not in df.columns:
|
||||
df["discipline_group"] = df.get("discipline", "Unknown")
|
||||
|
||||
df["discipline_group"] = df["discipline_group"].fillna("Unknown")
|
||||
df["known_status"] = df["known_status"].fillna("Unknown")
|
||||
|
||||
for column in NUMERIC_COLUMNS:
|
||||
if column in df.columns:
|
||||
df[column] = pd.to_numeric(df[column], errors="coerce")
|
||||
|
||||
return df
|
||||
|
||||
|
||||
def ordered_statuses(df: pd.DataFrame) -> list[str]:
|
||||
statuses = [status for status in STATUS_ORDER if status in df["known_status"].unique()]
|
||||
additional_statuses = sorted(
|
||||
status
|
||||
for status in df["known_status"].dropna().unique()
|
||||
if status not in STATUS_ORDER
|
||||
)
|
||||
return statuses + additional_statuses
|
||||
|
||||
|
||||
def ordered_discipline_groups(df: pd.DataFrame) -> list[str]:
|
||||
return sorted(df["discipline_group"].dropna().unique())
|
||||
|
||||
|
||||
def mean_value(series: pd.Series) -> float:
|
||||
return series.mean()
|
||||
|
||||
|
||||
def median_value(series: pd.Series) -> float:
|
||||
return series.median()
|
||||
|
||||
|
||||
def build_summary(df: pd.DataFrame, group_columns: list[str]) -> pd.DataFrame:
|
||||
rows: list[dict[str, object]] = []
|
||||
|
||||
for group_values, group in df.groupby(group_columns, dropna=False):
|
||||
if not isinstance(group_values, tuple):
|
||||
group_values = (group_values,)
|
||||
|
||||
row: dict[str, object] = {
|
||||
column: value for column, value in zip(group_columns, group_values)
|
||||
}
|
||||
row["sample_size"] = len(group)
|
||||
|
||||
for metric in METRICS:
|
||||
if metric not in group.columns:
|
||||
continue
|
||||
|
||||
values = group[metric].dropna()
|
||||
row[f"mean_{metric}"] = values.mean() if not values.empty else None
|
||||
row[f"median_{metric}"] = values.median() if not values.empty else None
|
||||
|
||||
rows.append(row)
|
||||
|
||||
return pd.DataFrame(rows)
|
||||
|
||||
|
||||
def save_summary_tables(df: pd.DataFrame) -> None:
|
||||
SUMMARY_DIR.mkdir(exist_ok=True)
|
||||
|
||||
summary_by_status = build_summary(df, ["known_status"])
|
||||
summary_by_status.to_csv(
|
||||
SUMMARY_DIR / "summary_by_status.csv",
|
||||
index=False,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
summary_by_discipline_group = build_summary(df, ["discipline_group"])
|
||||
summary_by_discipline_group.to_csv(
|
||||
SUMMARY_DIR / "summary_by_discipline_group.csv",
|
||||
index=False,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
summary_by_discipline_group_and_status = build_summary(
|
||||
df,
|
||||
["discipline_group", "known_status"],
|
||||
)
|
||||
summary_by_discipline_group_and_status.to_csv(
|
||||
SUMMARY_DIR / "summary_by_discipline_group_and_status.csv",
|
||||
index=False,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def save_bar_plot_by_status(
|
||||
df: pd.DataFrame,
|
||||
metric: str,
|
||||
statistic_name: str,
|
||||
statistic_function: StatisticFunction,
|
||||
title: str,
|
||||
ylabel: str,
|
||||
filename: str,
|
||||
) -> None:
|
||||
grouped = df.groupby("known_status")[metric].apply(statistic_function)
|
||||
grouped = grouped.reindex(ordered_statuses(df)).dropna()
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
grouped.plot(kind="bar")
|
||||
plt.title(title)
|
||||
plt.xlabel("Known Status")
|
||||
plt.ylabel(ylabel)
|
||||
plt.xticks(rotation=30, ha="right")
|
||||
plt.tight_layout()
|
||||
plt.savefig(PLOTS_DIR / filename)
|
||||
plt.close()
|
||||
|
||||
print(f"Saved {statistic_name} plot: {filename}")
|
||||
|
||||
|
||||
def save_grouped_bar_plot_by_discipline_group(
|
||||
df: pd.DataFrame,
|
||||
metric: str,
|
||||
statistic_name: str,
|
||||
statistic_function: StatisticFunction,
|
||||
title: str,
|
||||
ylabel: str,
|
||||
filename: str,
|
||||
) -> None:
|
||||
grouped = (
|
||||
df.groupby(["discipline_group", "known_status"])[metric]
|
||||
.apply(statistic_function)
|
||||
.unstack("known_status")
|
||||
)
|
||||
|
||||
grouped = grouped.reindex(ordered_discipline_groups(df))
|
||||
grouped = grouped.reindex(columns=ordered_statuses(df))
|
||||
|
||||
plt.figure(figsize=(12, 6))
|
||||
grouped.plot(kind="bar")
|
||||
plt.title(title)
|
||||
plt.xlabel("Discipline Group")
|
||||
plt.ylabel(ylabel)
|
||||
plt.xticks(rotation=30, ha="right")
|
||||
plt.legend(title="Known Status")
|
||||
plt.tight_layout()
|
||||
plt.savefig(PLOTS_DIR / filename)
|
||||
plt.close()
|
||||
|
||||
print(f"Saved {statistic_name} discipline group plot: {filename}")
|
||||
|
||||
|
||||
def save_box_plot_by_status(
|
||||
df: pd.DataFrame,
|
||||
metric: str,
|
||||
title: str,
|
||||
ylabel: str,
|
||||
filename: str,
|
||||
) -> None:
|
||||
statuses = ordered_statuses(df)
|
||||
data = [df.loc[df["known_status"] == status, metric].dropna() for status in statuses]
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.boxplot(data, labels=statuses)
|
||||
plt.title(title)
|
||||
plt.xlabel("Known Status")
|
||||
plt.ylabel(ylabel)
|
||||
plt.xticks(rotation=30, ha="right")
|
||||
plt.tight_layout()
|
||||
plt.savefig(PLOTS_DIR / filename)
|
||||
plt.close()
|
||||
|
||||
|
||||
def save_box_plot_by_discipline_group_and_status(
|
||||
df: pd.DataFrame,
|
||||
metric: str,
|
||||
title: str,
|
||||
ylabel: str,
|
||||
filename: str,
|
||||
) -> None:
|
||||
labels: list[str] = []
|
||||
data: list[pd.Series] = []
|
||||
|
||||
for discipline_group in ordered_discipline_groups(df):
|
||||
discipline_group_data = df[df["discipline_group"] == discipline_group]
|
||||
|
||||
for status in ordered_statuses(discipline_group_data):
|
||||
values = discipline_group_data.loc[
|
||||
discipline_group_data["known_status"] == status,
|
||||
metric,
|
||||
].dropna()
|
||||
|
||||
if values.empty:
|
||||
continue
|
||||
|
||||
labels.append(f"{discipline_group}\n{status}")
|
||||
data.append(values)
|
||||
|
||||
if not data:
|
||||
return
|
||||
|
||||
plt.figure(figsize=(14, 6))
|
||||
plt.boxplot(data, labels=labels)
|
||||
plt.title(title)
|
||||
plt.xlabel("Discipline Group and Known Status")
|
||||
plt.ylabel(ylabel)
|
||||
plt.xticks(rotation=45, ha="right")
|
||||
plt.tight_layout()
|
||||
plt.savefig(PLOTS_DIR / filename)
|
||||
plt.close()
|
||||
|
||||
|
||||
def save_histogram(
|
||||
df: pd.DataFrame,
|
||||
metric: str,
|
||||
title: str,
|
||||
xlabel: str,
|
||||
filename: str,
|
||||
) -> None:
|
||||
plt.figure(figsize=(10, 6))
|
||||
df[metric].dropna().plot(kind="hist", bins=10)
|
||||
plt.title(title)
|
||||
plt.xlabel(xlabel)
|
||||
plt.ylabel("Number of Researchers")
|
||||
plt.tight_layout()
|
||||
plt.savefig(PLOTS_DIR / filename)
|
||||
plt.close()
|
||||
|
||||
|
||||
def is_outlier(row: pd.Series, df: pd.DataFrame, x_metric: str, y_metric: str) -> bool:
|
||||
x_values = df[x_metric].dropna()
|
||||
y_values = df[y_metric].dropna()
|
||||
|
||||
if x_values.empty or y_values.empty:
|
||||
return False
|
||||
|
||||
x_threshold = x_values.quantile(0.75) + 1.5 * (
|
||||
x_values.quantile(0.75) - x_values.quantile(0.25)
|
||||
)
|
||||
y_threshold = y_values.quantile(0.75) + 1.5 * (
|
||||
y_values.quantile(0.75) - y_values.quantile(0.25)
|
||||
)
|
||||
|
||||
x_value = row.get(x_metric)
|
||||
y_value = row.get(y_metric)
|
||||
|
||||
if pd.isna(x_value) or pd.isna(y_value):
|
||||
return False
|
||||
|
||||
is_statistical_outlier = x_value > x_threshold or y_value > y_threshold
|
||||
is_researcher_with_long_history = (
|
||||
row.get("known_status") == "Researcher"
|
||||
and (x_value > 20 or row.get("publication_count", 0) > 100)
|
||||
)
|
||||
is_suspiciously_old_first_publication = row.get("first_publication_year", 9999) < 1970
|
||||
|
||||
return bool(
|
||||
is_statistical_outlier
|
||||
or is_researcher_with_long_history
|
||||
or is_suspiciously_old_first_publication
|
||||
)
|
||||
|
||||
|
||||
def should_label_point(
|
||||
row: pd.Series,
|
||||
df: pd.DataFrame,
|
||||
x_metric: str,
|
||||
y_metric: str,
|
||||
label_mode: ScatterLabelMode,
|
||||
) -> bool:
|
||||
if label_mode == "none":
|
||||
return False
|
||||
|
||||
if label_mode == "all":
|
||||
return True
|
||||
|
||||
return is_outlier(row, df, x_metric, y_metric)
|
||||
|
||||
|
||||
def save_scatter_plot(
|
||||
df: pd.DataFrame,
|
||||
x_metric: str,
|
||||
y_metric: str,
|
||||
group_column: str,
|
||||
title: str,
|
||||
xlabel: str,
|
||||
ylabel: str,
|
||||
filename: str,
|
||||
label_mode: ScatterLabelMode = "none",
|
||||
) -> None:
|
||||
figure_width = 15 if label_mode == "all" else 11
|
||||
figure_height = 9 if label_mode == "all" else 7
|
||||
label_fontsize = 6 if label_mode == "all" else 8
|
||||
|
||||
plt.figure(figsize=(figure_width, figure_height))
|
||||
|
||||
for group_name, group in df.groupby(group_column):
|
||||
plt.scatter(group[x_metric], group[y_metric], label=group_name, alpha=0.8)
|
||||
|
||||
for _, row in group.iterrows():
|
||||
x_value = row.get(x_metric)
|
||||
y_value = row.get(y_metric)
|
||||
name = row.get("name")
|
||||
|
||||
if (
|
||||
pd.notna(name)
|
||||
and pd.notna(x_value)
|
||||
and pd.notna(y_value)
|
||||
and should_label_point(row, df, x_metric, y_metric, label_mode)
|
||||
):
|
||||
plt.annotate(
|
||||
str(name),
|
||||
(x_value, y_value),
|
||||
fontsize=label_fontsize,
|
||||
xytext=(5, 5),
|
||||
textcoords="offset points",
|
||||
)
|
||||
|
||||
plt.title(title)
|
||||
plt.xlabel(xlabel)
|
||||
plt.ylabel(ylabel)
|
||||
plt.legend(title=group_column)
|
||||
plt.tight_layout()
|
||||
plt.savefig(PLOTS_DIR / filename)
|
||||
plt.close()
|
||||
|
||||
|
||||
def create_status_plots(df: pd.DataFrame) -> None:
|
||||
for metric in ["career_span", "publication_count", "active_years"]:
|
||||
metric_title = METRIC_TITLES[metric]
|
||||
metric_label = METRIC_LABELS[metric]
|
||||
|
||||
save_bar_plot_by_status(
|
||||
df=df,
|
||||
metric=metric,
|
||||
statistic_name="average",
|
||||
statistic_function=mean_value,
|
||||
title=f"Average {metric_title} by Known Status",
|
||||
ylabel=f"Average {metric_label}",
|
||||
filename=f"average_{metric}_by_status.png",
|
||||
)
|
||||
|
||||
save_bar_plot_by_status(
|
||||
df=df,
|
||||
metric=metric,
|
||||
statistic_name="median",
|
||||
statistic_function=median_value,
|
||||
title=f"Median {metric_title} by Known Status",
|
||||
ylabel=f"Median {metric_label}",
|
||||
filename=f"median_{metric}_by_status.png",
|
||||
)
|
||||
|
||||
for metric in [
|
||||
"publications_per_active_year",
|
||||
"publications_per_career_year",
|
||||
"years_since_last_publication",
|
||||
]:
|
||||
metric_title = METRIC_TITLES[metric]
|
||||
metric_label = METRIC_LABELS[metric]
|
||||
|
||||
save_bar_plot_by_status(
|
||||
df=df,
|
||||
metric=metric,
|
||||
statistic_name="average",
|
||||
statistic_function=mean_value,
|
||||
title=f"Average {metric_title} by Known Status",
|
||||
ylabel=f"Average {metric_label}",
|
||||
filename=f"average_{metric}_by_status.png",
|
||||
)
|
||||
|
||||
save_box_plot_by_status(
|
||||
df=df,
|
||||
metric="career_span",
|
||||
title="Distribution of Career Span by Known Status",
|
||||
ylabel="Career Span in Years",
|
||||
filename="boxplot_career_span_by_status.png",
|
||||
)
|
||||
|
||||
save_box_plot_by_status(
|
||||
df=df,
|
||||
metric="publication_count",
|
||||
title="Distribution of Publication Count by Known Status",
|
||||
ylabel="Number of Publications",
|
||||
filename="boxplot_publication_count_by_status.png",
|
||||
)
|
||||
|
||||
save_box_plot_by_status(
|
||||
df=df,
|
||||
metric="active_years",
|
||||
title="Distribution of Active Publication Years by Known Status",
|
||||
ylabel="Active Publication Years",
|
||||
filename="boxplot_active_years_by_status.png",
|
||||
)
|
||||
|
||||
|
||||
def create_discipline_group_plots(df: pd.DataFrame) -> None:
|
||||
for metric in ["career_span", "publication_count", "active_years"]:
|
||||
metric_title = METRIC_TITLES[metric]
|
||||
metric_label = METRIC_LABELS[metric]
|
||||
|
||||
save_grouped_bar_plot_by_discipline_group(
|
||||
df=df,
|
||||
metric=metric,
|
||||
statistic_name="average",
|
||||
statistic_function=mean_value,
|
||||
title=f"Average {metric_title} by Discipline Group and Status",
|
||||
ylabel=f"Average {metric_label}",
|
||||
filename=f"average_{metric}_by_discipline_group_and_status.png",
|
||||
)
|
||||
|
||||
save_grouped_bar_plot_by_discipline_group(
|
||||
df=df,
|
||||
metric=metric,
|
||||
statistic_name="median",
|
||||
statistic_function=median_value,
|
||||
title=f"Median {metric_title} by Discipline Group and Status",
|
||||
ylabel=f"Median {metric_label}",
|
||||
filename=f"median_{metric}_by_discipline_group_and_status.png",
|
||||
)
|
||||
|
||||
save_box_plot_by_discipline_group_and_status(
|
||||
df=df,
|
||||
metric=metric,
|
||||
title=f"Distribution of {metric_title} by Discipline Group and Status",
|
||||
ylabel=metric_label,
|
||||
filename=f"boxplot_{metric}_by_discipline_group_and_status.png",
|
||||
)
|
||||
|
||||
|
||||
def create_distribution_plots(df: pd.DataFrame) -> None:
|
||||
save_histogram(
|
||||
df=df,
|
||||
metric="career_span",
|
||||
title="Career Span Distribution",
|
||||
xlabel="Career Span in Years",
|
||||
filename="histogram_career_span.png",
|
||||
)
|
||||
|
||||
save_histogram(
|
||||
df=df,
|
||||
metric="publication_count",
|
||||
title="Publication Count Distribution",
|
||||
xlabel="Number of Publications",
|
||||
filename="histogram_publication_count.png",
|
||||
)
|
||||
|
||||
|
||||
def create_scatter_plots(df: pd.DataFrame) -> None:
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="career_span",
|
||||
y_metric="publication_count",
|
||||
group_column="known_status",
|
||||
title="Career Span vs Publication Count by Status",
|
||||
xlabel="Career Span in Years",
|
||||
ylabel="Number of Publications",
|
||||
filename="scatter_career_span_vs_publication_count_by_status.png",
|
||||
label_mode="none",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="career_span",
|
||||
y_metric="publication_count",
|
||||
group_column="known_status",
|
||||
title="Career Span vs Publication Count by Status with Outlier Labels",
|
||||
xlabel="Career Span in Years",
|
||||
ylabel="Number of Publications",
|
||||
filename="scatter_career_span_vs_publication_count_by_status_outliers.png",
|
||||
label_mode="outliers",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="career_span",
|
||||
y_metric="publication_count",
|
||||
group_column="known_status",
|
||||
title="Career Span vs Publication Count by Status with All Names",
|
||||
xlabel="Career Span in Years",
|
||||
ylabel="Number of Publications",
|
||||
filename="scatter_career_span_vs_publication_count_by_status_all_names.png",
|
||||
label_mode="all",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="career_span",
|
||||
y_metric="publication_count",
|
||||
group_column="discipline_group",
|
||||
title="Career Span vs Publication Count by Discipline Group",
|
||||
xlabel="Career Span in Years",
|
||||
ylabel="Number of Publications",
|
||||
filename="scatter_career_span_vs_publication_count_by_discipline_group.png",
|
||||
label_mode="none",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="career_span",
|
||||
y_metric="publication_count",
|
||||
group_column="discipline_group",
|
||||
title="Career Span vs Publication Count by Discipline Group with All Names",
|
||||
xlabel="Career Span in Years",
|
||||
ylabel="Number of Publications",
|
||||
filename="scatter_career_span_vs_publication_count_by_discipline_group_all_names.png",
|
||||
label_mode="all",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="active_years",
|
||||
y_metric="publication_count",
|
||||
group_column="known_status",
|
||||
title="Active Publication Years vs Publication Count by Status",
|
||||
xlabel="Active Publication Years",
|
||||
ylabel="Number of Publications",
|
||||
filename="scatter_active_years_vs_publication_count_by_status.png",
|
||||
label_mode="none",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="active_years",
|
||||
y_metric="publication_count",
|
||||
group_column="known_status",
|
||||
title="Active Publication Years vs Publication Count by Status with All Names",
|
||||
xlabel="Active Publication Years",
|
||||
ylabel="Number of Publications",
|
||||
filename="scatter_active_years_vs_publication_count_by_status_all_names.png",
|
||||
label_mode="all",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="career_span",
|
||||
y_metric="publications_per_active_year",
|
||||
group_column="known_status",
|
||||
title="Career Span vs Publications per Active Year by Status",
|
||||
xlabel="Career Span in Years",
|
||||
ylabel="Publications per Active Year",
|
||||
filename="scatter_career_span_vs_publications_per_active_year_by_status.png",
|
||||
label_mode="none",
|
||||
)
|
||||
|
||||
save_scatter_plot(
|
||||
df=df,
|
||||
x_metric="career_span",
|
||||
y_metric="publications_per_active_year",
|
||||
group_column="known_status",
|
||||
title="Career Span vs Publications per Active Year by Status with All Names",
|
||||
xlabel="Career Span in Years",
|
||||
ylabel="Publications per Active Year",
|
||||
filename="scatter_career_span_vs_publications_per_active_year_by_status_all_names.png",
|
||||
label_mode="all",
|
||||
)
|
||||
|
||||
|
||||
def create_visualizations() -> None:
|
||||
PLOTS_DIR.mkdir(exist_ok=True)
|
||||
SUMMARY_DIR.mkdir(exist_ok=True)
|
||||
|
||||
df = prepare_data()
|
||||
|
||||
if df.empty:
|
||||
print("No data available for visualization.")
|
||||
return
|
||||
|
||||
save_summary_tables(df)
|
||||
create_status_plots(df)
|
||||
create_discipline_group_plots(df)
|
||||
create_distribution_plots(df)
|
||||
create_scatter_plots(df)
|
||||
|
||||
print(f"Visualizations saved to {PLOTS_DIR}")
|
||||
print(f"Summary tables saved to {SUMMARY_DIR}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_visualizations()
|
||||
@@ -0,0 +1,96 @@
|
||||
import json
|
||||
from typing import Any
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
|
||||
OPENALEX_WORKS_URL = "https://api.openalex.org/works"
|
||||
REQUEST_TIMEOUT_SECONDS = 30
|
||||
PER_PAGE = 200
|
||||
|
||||
|
||||
def normalize_author_id(author_id: str) -> str:
|
||||
"""
|
||||
Normalizes OpenAlex author IDs.
|
||||
|
||||
Supported inputs:
|
||||
- A123456789
|
||||
- https://openalex.org/A123456789
|
||||
- https://api.openalex.org/authors/A123456789
|
||||
"""
|
||||
cleaned_author_id = author_id.strip()
|
||||
|
||||
if cleaned_author_id.startswith("https://api.openalex.org/authors/"):
|
||||
return cleaned_author_id.replace(
|
||||
"https://api.openalex.org/authors/",
|
||||
"https://openalex.org/",
|
||||
)
|
||||
|
||||
if cleaned_author_id.startswith("https://openalex.org/"):
|
||||
return cleaned_author_id
|
||||
|
||||
if cleaned_author_id.startswith("A"):
|
||||
return f"https://openalex.org/{cleaned_author_id}"
|
||||
|
||||
return cleaned_author_id
|
||||
|
||||
|
||||
def fetch_openalex_page(author_id: str, cursor: str) -> dict[str, Any]:
|
||||
normalized_author_id = normalize_author_id(author_id)
|
||||
|
||||
query_params = urlencode(
|
||||
{
|
||||
"filter": f"authorships.author.id:{normalized_author_id}",
|
||||
"per-page": PER_PAGE,
|
||||
"cursor": cursor,
|
||||
"sort": "publication_year:asc",
|
||||
}
|
||||
)
|
||||
|
||||
url = f"{OPENALEX_WORKS_URL}?{query_params}"
|
||||
|
||||
request = Request(
|
||||
url,
|
||||
headers={
|
||||
"Accept": "application/json",
|
||||
"User-Agent": "AIIS career stage analysis",
|
||||
},
|
||||
)
|
||||
|
||||
try:
|
||||
with urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response:
|
||||
response_body = response.read().decode("utf-8")
|
||||
return json.loads(response_body)
|
||||
|
||||
except HTTPError as error:
|
||||
raise RuntimeError(
|
||||
f"OpenAlex request failed with HTTP status {error.code}: {url}"
|
||||
) from error
|
||||
|
||||
except URLError as error:
|
||||
raise RuntimeError(f"OpenAlex request failed: {error}") from error
|
||||
|
||||
|
||||
def get_all_author_works(author_id: str) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Fetches all works for an OpenAlex author by using cursor pagination.
|
||||
"""
|
||||
works: list[dict[str, Any]] = []
|
||||
cursor = "*"
|
||||
|
||||
while cursor:
|
||||
data = fetch_openalex_page(author_id, cursor)
|
||||
|
||||
page_results = data.get("results", [])
|
||||
works.extend(page_results)
|
||||
|
||||
meta = data.get("meta", {})
|
||||
next_cursor = meta.get("next_cursor")
|
||||
|
||||
if not next_cursor or next_cursor == cursor:
|
||||
break
|
||||
|
||||
cursor = next_cursor
|
||||
|
||||
return works
|
||||
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 35 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 81 KiB |
@@ -0,0 +1,6 @@
|
||||
discipline_group,sample_size,mean_career_span,median_career_span,mean_active_years,median_active_years,mean_publication_count,median_publication_count,mean_publications_per_active_year,median_publications_per_active_year,mean_publications_per_career_year,median_publications_per_career_year,mean_years_since_last_publication,median_years_since_last_publication
|
||||
Biology,10,44.5,35.0,23.0,23.5,184.5,138.5,6.410136743886744,6.833333333333333,4.342828101969518,2.8414179104477615,0.7,0.0
|
||||
Computer Science,22,24.90909090909091,18.5,17.136363636363637,17.5,115.54545454545455,106.0,5.194674030118668,4.390697674418605,4.383304699676206,3.1192307692307693,0.4090909090909091,0.0
|
||||
Engineering,6,20.166666666666668,15.0,17.833333333333332,13.5,124.16666666666667,74.5,4.5022556390977435,3.6357142857142857,4.054259702286018,3.2033492822966507,1.6666666666666667,1.0
|
||||
Medicine,12,37.916666666666664,26.5,23.0,21.5,343.6666666666667,188.5,10.699183227664198,8.416666666666666,7.862918672933688,6.795662100456621,0.25,0.0
|
||||
Sociology,10,21.8,23.0,13.9,15.0,55.2,35.0,3.0017820858310875,3.0277777777777777,2.245860377439325,2.206815114709852,1.2,0.5
|
||||
|
@@ -0,0 +1,11 @@
|
||||
discipline_group,known_status,sample_size,mean_career_span,median_career_span,mean_active_years,median_active_years,mean_publication_count,median_publication_count,mean_publications_per_active_year,median_publications_per_active_year,mean_publications_per_career_year,median_publications_per_career_year,mean_years_since_last_publication,median_years_since_last_publication
|
||||
Biology,Professor,5,62.8,58.0,33.4,35.0,303.4,332.0,8.856940154440155,9.485714285714286,5.944422997812213,5.442622950819672,0.4,0.0
|
||||
Biology,Researcher,5,26.2,22.0,12.6,15.0,65.6,36.0,3.9633333333333334,2.4,2.741233206126823,2.021276595744681,1.0,0.0
|
||||
Computer Science,Professor,11,39.72727272727273,31.0,25.90909090909091,22.0,203.8181818181818,202.0,8.05960497723338,7.214285714285714,6.804834459316603,6.470588235294118,0.18181818181818182,0.0
|
||||
Computer Science,Researcher,11,10.090909090909092,6.0,8.363636363636363,5.0,27.272727272727273,11.0,2.3297430830039527,2.2,1.96177494003581,1.5,0.6363636363636364,0.0
|
||||
Engineering,Professor,3,33.0,38.0,30.666666666666668,35.0,241.33333333333334,202.0,7.704511278195487,7.2105263157894735,7.230994152046783,7.2105263157894735,0.0,0.0
|
||||
Engineering,Researcher,3,7.333333333333333,8.0,5.0,5.0,7.0,7.0,1.3,1.4,0.8775252525252525,0.875,3.3333333333333335,3.0
|
||||
Medicine,Professor,7,56.714285714285715,30.0,34.285714285714285,29.0,572.7142857142857,615.0,16.225810703206655,16.253968253968253,11.606273280584732,8.76530612244898,0.14285714285714285,0.0
|
||||
Medicine,Researcher,5,11.6,7.0,7.2,7.0,23.0,21.0,2.961904761904762,3.0,2.6222222222222222,3.0,0.4,0.0
|
||||
Sociology,Professor,5,32.0,27.0,22.6,22.0,101.8,106.0,4.393564171662176,4.517241379310345,3.3512445644024593,3.55,0.4,0.0
|
||||
Sociology,Researcher,5,11.6,6.0,5.2,5.0,8.6,9.0,1.61,1.25,1.1404761904761904,0.5,2.0,1.0
|
||||
|
@@ -0,0 +1,3 @@
|
||||
known_status,sample_size,mean_career_span,median_career_span,mean_active_years,median_active_years,mean_publication_count,median_publication_count,mean_publications_per_active_year,median_publications_per_active_year,mean_publications_per_career_year,median_publications_per_career_year,mean_years_since_last_publication,median_years_since_last_publication
|
||||
Professor,31,45.38709677419355,31.0,28.93548387096774,28.0,290.35483870967744,224.0,9.40652855281006,7.611111111111111,7.234464912380307,6.172413793103448,0.22580645161290322,0.0
|
||||
Researcher,29,13.10344827586207,7.0,8.0,5.0,27.82758620689655,11.0,2.4897711858356537,1.8,1.9562675238653737,1.5,1.1724137931034482,0.0
|
||||
|