Skip to content

Commit 5489962

Browse files
Merge remote-tracking branch 'origin/staging'
2 parents 975c6db + a06e637 commit 5489962

File tree

38 files changed

+11093
-3
lines changed

38 files changed

+11093
-3
lines changed

client/package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"highcharts-react-official": "^3.2.1",
3232
"leaflet": "^1.9.4",
3333
"ml-regression-simple-linear": "^3.0.1",
34+
"proj4": "^2.17.0",
3435
"react": "^18.2.0",
3536
"react-dom": "^18.2.0",
3637
"react-intersection-observer": "^9.5.3",

client/src/api/organizations/[id]/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function getStructurePublicationsById(id: string): Promise<any> {
7777
},
7878
bySupportEntity: {
7979
terms: {
80-
field: "structured_acknowledgments.support.entity.keyword",
80+
field: "structured_acknowledgments.private_support.entity.keyword",
8181
size: 50,
8282
}
8383
},

client/src/api/patents/_utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const FIELDS = [
22
"id.keyword^10",
3+
"title_abs_text^3",
34
"inpadocFamily.keyword^10",
45
"patents.id.keyword^10",
56
"patents.publicationNumber.keyword^10",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { patentsIndex, postHeaders } from "../../../config/api";
2+
import { AggregationArgs } from "../../../types/commons";
3+
import { PatentsAggregationsForAnalyticTool } from "../../../types/patent";
4+
import { fillWithMissingYears } from "../../utils/years";
5+
import { FIELDS } from "../_utils/constants";
6+
7+
8+
export async function aggregatePatentsForAnalyticTool(
9+
{ query }: AggregationArgs
10+
): Promise<PatentsAggregationsForAnalyticTool> {
11+
const body: any = {
12+
size: 0,
13+
query: {
14+
bool: {
15+
must: [
16+
{
17+
query_string: {
18+
query: query || '*',
19+
fields: FIELDS,
20+
},
21+
}
22+
]
23+
}
24+
},
25+
aggs: {
26+
byYear: {
27+
terms: {
28+
field: "year",
29+
size: 25,
30+
},
31+
},
32+
patentsCount: {
33+
value_count: { field: "id.keyword" },
34+
},
35+
byApplicants: {
36+
terms: {
37+
field: "applicants.id_name.keyword",
38+
size: 15,
39+
order: {
40+
_count: "desc"
41+
}
42+
}
43+
},
44+
byInventors: {
45+
terms: {
46+
field: "inventors.name.keyword",
47+
size: 15,
48+
// min_doc_count: 5,
49+
order: {
50+
_count: "desc"
51+
}
52+
}
53+
},
54+
}
55+
}
56+
const res = await fetch(
57+
`${patentsIndex}/_search`,
58+
{ method: 'POST', body: JSON.stringify(body), headers: postHeaders })
59+
const result = await res.json()
60+
const { aggregations: data} = result;
61+
62+
const _100Year =
63+
data?.byYear?.buckets &&
64+
Math.max(...data.byYear.buckets.map((el) => el.doc_count));
65+
const byYear =
66+
data?.byYear?.buckets
67+
?.map((element) => {
68+
return {
69+
value: element.key,
70+
label: element.key,
71+
count: element.doc_count,
72+
normalizedCount: (element.doc_count * 100) / _100Year,
73+
};
74+
})
75+
.sort((a, b) => a.label - b.label)
76+
.reduce(fillWithMissingYears, []) || [];
77+
78+
const byApplicants = data?.byApplicants?.buckets?.map((element) => {
79+
return {
80+
value: element.key?.split('###')?.[0] || element.key,
81+
label: element.key?.split('###')?.[1] || element.key,
82+
count: element.doc_count,
83+
}
84+
}).filter(el => el) || [];
85+
const byInventors = data?.byInventors?.buckets?.map((element) => {
86+
return {
87+
value: element.key,
88+
label: element.key,
89+
count: element.doc_count,
90+
}
91+
}).filter(el => el) || [];
92+
const patentsCount = data.patentsCount?.value;
93+
return {
94+
byInventors,
95+
byApplicants,
96+
patentsCount,
97+
byYear,
98+
};
99+
}

client/src/api/projects/_utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const FIELDS = [
22
"id^3",
33
"label.*^3",
4+
"title_abs_text^3",
45
"acronym.*^3",
56
"description.*^2",
67
"domains.label.*",
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { projectsIndex, postHeaders } from "../../../config/api";
2+
import { AggregationArgs } from "../../../types/commons";
3+
import { ProjectAggregationsForAnalyticsTool } from "../../../types/project";
4+
import { fillWithMissingYears } from "../../utils/years";
5+
import { FIELDS } from "../_utils/constants";
6+
7+
export async function aggregateProjectsForAnalyticsTool(
8+
{ query }: AggregationArgs
9+
): Promise<ProjectAggregationsForAnalyticsTool> {
10+
const body: any = {
11+
size: 0,
12+
query: {
13+
bool: {
14+
must: [
15+
{
16+
query_string: {
17+
query: query || '*',
18+
fields: FIELDS,
19+
},
20+
}
21+
]
22+
}
23+
},
24+
aggs: {
25+
projectsCount: {
26+
value_count: { field: "id.keyword" },
27+
},
28+
byType: {
29+
terms: {
30+
field: "type.keyword",
31+
size: 500,
32+
}
33+
},
34+
byYear: {
35+
terms: {
36+
field: "year",
37+
size: 25,
38+
}
39+
},
40+
byInstitution: {
41+
terms: {
42+
field: "participants.structure.id_name.keyword",
43+
size: 500,
44+
}
45+
}
46+
}
47+
}
48+
const res = await fetch(
49+
`${projectsIndex}/_search`,
50+
{ method: 'POST', body: JSON.stringify(body), headers: postHeaders })
51+
const result = await res.json()
52+
const { aggregations: data } = result;
53+
const byInstitution = data?.byInstitution?.buckets
54+
?.filter((element) => element.key.split('###')?.[0].match(/^[0-9]{9}[A-Z]{1}$/))
55+
.map((element) => {
56+
return {
57+
value: element.key.split('###')?.[0],
58+
label: element.key.split('###')?.[1]?.split('_')?.[1]?.split('|||')?.[0],
59+
count: element.doc_count,
60+
}
61+
})
62+
.filter(el => el) || [];
63+
64+
const _100Year = data?.byYear?.buckets && Math.max(...data.byYear.buckets.map((el) => el.doc_count));
65+
const byYear = data?.byYear?.buckets?.map((element) => {
66+
return {
67+
value: element.key,
68+
label: element.key,
69+
count: element.doc_count,
70+
normalizedCount: element.doc_count * 100 / _100Year,
71+
}
72+
}).sort((a, b) => a.label - b.label).reduce(fillWithMissingYears, []) || [];
73+
const byType = data?.byType?.buckets?.map((element) => {
74+
return {
75+
value: element.key,
76+
label: element.key,
77+
count: element.doc_count,
78+
}
79+
}).filter(el => el) || [];
80+
const projectsCount = data?.projectsCount?.value || 0;
81+
return { byInstitution, byYear, byType, projectsCount};
82+
83+
}

client/src/api/publications/_utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const FIELDS = [
22
"id^10",
33
"externalIds.id^3",
44
"title.*^3",
5+
"title_abs_text^3",
56
"summary.*^2",
67
"domains.label.*^2",
78
"domains.code^2",

0 commit comments

Comments
 (0)