Skip to content

Commit 0ef369f

Browse files
committed
Merge remote-tracking branch 'origin/staging'
2 parents 12090ac + 482be46 commit 0ef369f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2106
-769
lines changed

client/nginx.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ server {
3232
proxy_set_header X-Real-IP $remote_addr;
3333
proxy_pass https://ec.europa.eu/info/funding-tenders/opportunities/data/topicDetails/$1.json;
3434
}
35-
}
35+
location ~* ^/openalex/(.*) {
36+
proxy_pass https://api.openalex.org/$1$is_args$args&api_key=$OPENALEX_API_KEY;
37+
proxy_set_header X-Real-IP $remote_addr;
38+
proxy_ssl_server_name on;
39+
}
40+
}
Lines changed: 15 additions & 0 deletions
Loading
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { AggregationArgs } from "../../types/commons";
2+
3+
import { getOpenalexUrl } from "./config";
4+
5+
const groupBys = [
6+
"publication_year",
7+
"type",
8+
"authorships.countries",
9+
"authorships.author.id",
10+
"authorships.institutions.lineage",
11+
"primary_topic.id",
12+
// "keywords.id",
13+
"primary_location.source.id",
14+
"grants.funder",
15+
// "authorships.institutions.continent",
16+
];
17+
18+
export async function fetchOpenAlexAggregations({ query, filters = [] }: AggregationArgs): Promise<any> {
19+
console.log("fetchOpenAlexAggregations", query, filters)
20+
const urls = groupBys.map((groupBy) => {
21+
if (filters.length) {
22+
/* @ts-expect-error unknown */
23+
const yearRange: any = filters.find((el: any) => el?.range?.year)?.range?.year
24+
const [yearMin, yearMax] = [yearRange?.gte, yearRange?.lte]
25+
const types = filters
26+
?.find((el) => el?.terms?.["type.keyword"])
27+
?.terms["type.keyword"]
28+
?.map((type: string) => `types/${type}`);
29+
30+
const typesFilter = types?.length > 0 ? `type:${types.join("|")}` : "";
31+
const yearsFilter = (yearMin && yearMax) ? `publication_year:${parseInt(yearMin)}-${parseInt(yearMax)}` : "";
32+
const finalQuery= [query, typesFilter, yearsFilter].filter(Boolean).join(",")
33+
console.log("finalQuery", finalQuery)
34+
return getOpenalexUrl(finalQuery, groupBy);
35+
}
36+
return getOpenalexUrl(query, groupBy);
37+
});
38+
39+
const responses = await Promise.all(urls.map((url) => fetch(url)));
40+
const results = await Promise.all(responses.map((res) => res.json()));
41+
const [
42+
publicationYear,
43+
publicationType,
44+
authorshipsCountries,
45+
authorshipsAllAuthors,
46+
authorshipsAuthorsInstitutions,
47+
primaryTopic,
48+
// keywords,
49+
primaryLocationUrl,
50+
grantsFunder,
51+
// authorshipsAuthorsInstitutionsContinents,
52+
] = results.map((result) => {
53+
const agg = result.group_by;
54+
55+
return agg.map((item) => ({
56+
value: item.key,
57+
label: item.key_display_name,
58+
count: item.count,
59+
}));
60+
});
61+
// const frenchies = authorshipsFrenchAuthors.map((item) => item.value);
62+
// const authorshipsAuthors = authorshipsAllAuthors.map((item) => {
63+
// if (frenchies.includes(item.value)) {
64+
// return {...item, label: "🇫🇷 " + item.label};
65+
// }
66+
// return item;
67+
// });
68+
const total = results?.[0]?.meta?.count;
69+
return {
70+
total,
71+
publicationYear,
72+
publicationType,
73+
authorshipsCountries,
74+
authorshipsAuthors: authorshipsAllAuthors,
75+
// authorshipsFrenchAuthors,
76+
authorshipsAuthorsInstitutions,
77+
primaryTopic,
78+
// keywords,
79+
primaryLocationUrl,
80+
grantsFunder,
81+
// authorshipsAuthorsInstitutionsContinents,
82+
};
83+
}

client/src/api/openalex/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const VITE_OPENALEX_URL = import.meta.env.VITE_OPENALEX_URL;
2+
3+
export const OPENALEX_URL = VITE_OPENALEX_URL || '/openalex';
4+
5+
export const getOpenalexUrl = (query: string, groupBy: string) =>
6+
`${OPENALEX_URL}/works?page=1&filter=title_and_abstract.search:${query}&group_by=${groupBy}`;

client/src/api/openalex/filters.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { fillWithMissingYears } from "../utils/years";
2+
import { getOpenalexUrl } from "./config";
3+
4+
const groupBysFilters = [
5+
"publication_year",
6+
"type",
7+
];
8+
9+
export async function fetchOpenFilters({
10+
query
11+
}: {
12+
query: string;
13+
}): Promise<any> {
14+
const urls = groupBysFilters.map((groupBy) => getOpenalexUrl(query, groupBy));
15+
16+
const responses = await Promise.all(urls.map((url) => fetch(url)));
17+
const results = await Promise.all(responses.map((res) => res.json()));
18+
const years = results?.[0]?.group_by.map((item) => ({
19+
value: parseInt(item.key, 10),
20+
label: parseInt(item.key_display_name, 10),
21+
count: item.count,
22+
}))
23+
const _100Year = Math.max(...years.map((el) => el.count));
24+
const byYear = years.filter((element) => element.value > 1990).map((element) => {
25+
return {
26+
...element,
27+
normalizedCount: element.doc_count * 100 / _100Year,
28+
}
29+
}).sort((a, b) => a.label - b.label).reduce(fillWithMissingYears, []) || [];
30+
const byType = results?.[1]?.group_by.map((item) => ({
31+
value: item.key_display_name,
32+
label: item.key_display_name,
33+
count: item.count,
34+
}));
35+
console.log("byType", byType)
36+
37+
return { byYear, byType }
38+
}

0 commit comments

Comments
 (0)