added additional comparison fields in dfg projects

This commit is contained in:
Kazgatari
2026-07-19 19:12:23 +02:00
parent 0a97b3797e
commit ebb986b225
@@ -1136,7 +1136,28 @@ class ProjectsTrendStrategy(TrendStrategy):
{"match": {"abstract_de": keyword}},
{"match": {"abstract_en": keyword}},
{"match": {"final_report_abstract_de": keyword}},
{"match": {"final_report_abstract_en": keyword}}
{"match": {"final_report_abstract_en": keyword}},
{
"nested": {
"path": "publications",
"query": {"match": {"publications.title": keyword}}
}
},
{
"nested": {
"path": "subject_classification",
"query": {
"bool": {
"should": [
{"match": {"subject_classification.fach": keyword}},
{"match": {"subject_classification.fachkollegium": keyword}},
{"match": {"subject_classification.wissenschaftsbereich": keyword}}
],
"minimum_should_match": 1
}
}
}
}
],
"minimum_should_match": 1
}
@@ -1432,61 +1453,46 @@ class AllTrendStrategy(TrendStrategy):
regions: Optional[List[str]] = None,
authors: Optional[List[str]] = None,
) -> TrendResponse:
# Runs Publications, Patents, Projects, and News strategies concurrently
# overlays their curves to display a Topic Lifecycle dashboard for UDE
target_inst = institutions[0] if institutions and len(institutions) > 0 else DEFAULT_INSTITUTION_ID
short_id = target_inst.split("/")[-1].upper()
is_ude = (short_id == "I62318514")
pub_strat = PublicationsTrendStrategy()
pat_strat = PatentsTrendStrategy()
proj_strat = ProjectsTrendStrategy()
news_strat = NewsTrendStrategy()
# Query UDE publications data only
pub_task = pub_strat.get_trend(topics, keywords, fuzzy, institutions=[DEFAULT_INSTITUTION_ID])
pat_task = pat_strat.get_trend(topics, keywords, fuzzy)
proj_task = proj_strat.get_trend(topics, keywords, fuzzy)
news_task = news_strat.get_trend(topics, keywords, fuzzy)
tasks = [
pub_strat.get_trend(topics, keywords, fuzzy, institutions=[target_inst]),
pat_strat.get_trend(topics, keywords, fuzzy, institutions=[target_inst]),
proj_strat.get_trend(topics, keywords, fuzzy, institutions=[target_inst])
]
pub_res, pat_res, proj_res, news_res = await asyncio.gather(pub_task, pat_task, proj_task, news_task)
if is_ude:
news_strat = NewsTrendStrategy()
tasks.append(news_strat.get_trend(topics, keywords, fuzzy))
results = await asyncio.gather(*tasks)
pub_res = results[0]
pat_res = results[1]
proj_res = results[2]
news_res = results[3] if is_ude else None
start_year = 2000
end_year = datetime.datetime.now().year - 1
years_range = list(range(start_year, end_year + 1))
# Extract UDE publications series
pub_series = next((s for s in pub_res.series if s.entity_id == DEFAULT_INSTITUTION_ID), None)
pub_series = pub_res.series[0] if pub_res.series else None
pat_series = pat_res.series[0] if pat_res.series else None
proj_series = proj_res.series[0] if proj_res.series else None
# Reconstruct a single news series containing the correct data for each topic
merged_news_topic_data = {}
for topic in topics:
term_key = f"news_topic_{topic}"
matching_series = next((s for s in news_res.series if s.entity_id == term_key), None)
if matching_series and topic in matching_series.topic_data:
merged_news_topic_data[topic] = matching_series.topic_data[topic]
else:
merged_news_topic_data[topic] = [
TopicYearlyData(year=yr, raw=0, normalized=0.0, cumulative=0.0, institutions_count=1)
for yr in years_range
]
news_series = TrendSeries(
entity_id="news",
entity_name="UDE Campus Aktuell Beiträge",
entity_type="institution",
topic_data=merged_news_topic_data
)
# Build composite TrendSeries
composite_series = []
# Helper to construct TrendSeries
def add_composite(series_obj: Optional[TrendSeries], c_id: str, c_name: str):
topic_data_map = {}
for topic in topics:
if series_obj and topic in series_obj.topic_data:
topic_data_map[topic] = series_obj.topic_data[topic]
else:
# Fallback empty list
topic_data_map[topic] = [
TopicYearlyData(year=yr, raw=0, normalized=0.0, cumulative=0.0, institutions_count=1)
for yr in years_range
@@ -1498,9 +1504,29 @@ class AllTrendStrategy(TrendStrategy):
topic_data=topic_data_map
))
add_composite(pub_series, "publications", "Akademische Publikationen (UDE)")
add_composite(pat_series, "patents", "Patentanmeldungen (UDE)")
add_composite(proj_series, "projects", "Drittmittelförderung (UDE)")
add_composite(news_series, "news", "UDE Campus Aktuell Beiträge")
add_composite(pub_series, "publications", "Akademische Publikationen")
add_composite(pat_series, "patents", "Patentanmeldungen")
add_composite(proj_series, "projects", "Drittmittelförderung")
if is_ude and news_res:
merged_news_topic_data = {}
for topic in topics:
term_key = f"news_topic_{topic}"
matching_series = next((s for s in news_res.series if s.entity_id == term_key), None)
if matching_series and topic in matching_series.topic_data:
merged_news_topic_data[topic] = matching_series.topic_data[topic]
else:
merged_news_topic_data[topic] = [
TopicYearlyData(year=yr, raw=0, normalized=0.0, cumulative=0.0, institutions_count=1)
for yr in years_range
]
news_series = TrendSeries(
entity_id="news",
entity_name="UDE Campus Aktuell Beiträge",
entity_type="institution",
topic_data=merged_news_topic_data
)
add_composite(news_series, "news", "UDE Campus Aktuell Beiträge")
return TrendResponse(series=composite_series, years=years_range)