fixed project pie chart for sure now
This commit is contained in:
@@ -746,22 +746,37 @@ class ProjectsTrendStrategy(TrendStrategy):
|
||||
primary_inst_id = DEFAULT_INSTITUTION_ID
|
||||
primary_inst_name = DEFAULT_INSTITUTION_NAME
|
||||
|
||||
query_institutions = []
|
||||
if institutions:
|
||||
query_institutions = [i.strip() for i in institutions]
|
||||
if primary_inst_id not in query_institutions:
|
||||
query_institutions.insert(0, primary_inst_id)
|
||||
def clean_inst_id(id_str: str) -> str:
|
||||
return id_str.split("/")[-1] if id_str and "/" in id_str else id_str
|
||||
|
||||
primary_inst_short = clean_inst_id(DEFAULT_INSTITUTION_ID)
|
||||
primary_inst_full = f"https://openalex.org/{primary_inst_short}"
|
||||
|
||||
raw_insts = institutions or []
|
||||
query_insts_short = [clean_inst_id(i) for i in raw_insts if i]
|
||||
if primary_inst_short not in query_insts_short:
|
||||
query_insts_short.insert(0, primary_inst_short)
|
||||
|
||||
# Preserve order while deduplicating
|
||||
seen_insts = set()
|
||||
dedup_inst_shorts = []
|
||||
for s_id in query_insts_short:
|
||||
if s_id not in seen_insts:
|
||||
seen_insts.add(s_id)
|
||||
dedup_inst_shorts.append(s_id)
|
||||
|
||||
query_institutions = dedup_inst_shorts
|
||||
ids_to_resolve = [f"https://openalex.org/{i}" for i in query_institutions]
|
||||
|
||||
query_countries = countries or []
|
||||
query_regions = regions or []
|
||||
|
||||
clean_countries = [c.strip().upper() for c in query_countries]
|
||||
clean_regions = [r.strip() for r in query_regions]
|
||||
ids_to_resolve = list(set(query_institutions))
|
||||
|
||||
# 1. Resolve institution names & aliases, country names, and regions
|
||||
async def fetch_institutions():
|
||||
names = {primary_inst_id: primary_inst_name}
|
||||
names = {primary_inst_full: DEFAULT_INSTITUTION_NAME, primary_inst_short: DEFAULT_INSTITUTION_NAME}
|
||||
codes = {}
|
||||
aliases_map = {}
|
||||
if not ids_to_resolve:
|
||||
@@ -778,20 +793,27 @@ class ProjectsTrendStrategy(TrendStrategy):
|
||||
)
|
||||
for hit in res.get("hits", {}).get("hits", []):
|
||||
source = hit["_source"]
|
||||
inst_id = source["id"]
|
||||
names[inst_id] = source.get("display_name", inst_id)
|
||||
codes[inst_id] = source.get("country_code", "")
|
||||
|
||||
async def get_aliases(inst_id):
|
||||
try:
|
||||
return inst_id, await client.get_institution_aliases_by_oa_institution_id(inst_id)
|
||||
except Exception as e:
|
||||
logger.warning("Failed to get aliases for %s: %s", inst_id, e)
|
||||
return inst_id, [names.get(inst_id, inst_id)]
|
||||
full_id = source["id"]
|
||||
short_id = clean_inst_id(full_id)
|
||||
d_name = source.get("display_name", full_id)
|
||||
c_code = source.get("country_code", "")
|
||||
names[full_id] = d_name
|
||||
names[short_id] = d_name
|
||||
codes[full_id] = c_code
|
||||
codes[short_id] = c_code
|
||||
|
||||
alias_results = await asyncio.gather(*(get_aliases(inst_id) for inst_id in ids_to_resolve))
|
||||
for inst_id, aliases in alias_results:
|
||||
aliases_map[inst_id] = aliases
|
||||
async def get_aliases(inst_short_id):
|
||||
try:
|
||||
resolved = await client.get_institution_aliases_by_oa_institution_id(inst_short_id)
|
||||
return inst_short_id, resolved or [names.get(inst_short_id, inst_short_id)]
|
||||
except Exception as e:
|
||||
logger.warning("Failed to get aliases for %s: %s", inst_short_id, e)
|
||||
return inst_short_id, [names.get(inst_short_id, inst_short_id)]
|
||||
|
||||
alias_results = await asyncio.gather(*(get_aliases(i) for i in query_institutions))
|
||||
for inst_short_id, aliases in alias_results:
|
||||
aliases_map[inst_short_id] = aliases
|
||||
aliases_map[f"https://openalex.org/{inst_short_id}"] = aliases
|
||||
except Exception as e:
|
||||
logger.warning("Failed to resolve institution details from ES: %s", e)
|
||||
return names, codes, aliases_map
|
||||
|
||||
+1
-2
@@ -397,8 +397,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (s.entity_type === 'institution') {
|
||||
if (cId === primaryInstCleanId) {
|
||||
primaryInstSeries.push(s);
|
||||
}
|
||||
if (currentInstIds.has(cId)) {
|
||||
} else if (currentInstIds.has(cId)) {
|
||||
compInstSeries.push(s);
|
||||
}
|
||||
} else if (s.entity_type === 'country') {
|
||||
|
||||
Reference in New Issue
Block a user