From 8082bf3ddce3a76d57ceec4169f98638ee884f0e Mon Sep 17 00:00:00 2001 From: victor barbier Date: Mon, 21 Oct 2024 12:36:44 +0200 Subject: [PATCH] fix(networks): clusters publications count --- client/src/api/networks/network/communities.ts | 7 +++---- client/src/api/networks/search/search.ts | 3 +++ client/src/pages/networks/hooks/useExportData.ts | 12 +++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/client/src/api/networks/network/communities.ts b/client/src/api/networks/network/communities.ts index e9fa4b76..b2b4102d 100644 --- a/client/src/api/networks/network/communities.ts +++ b/client/src/api/networks/network/communities.ts @@ -44,9 +44,7 @@ const communityGetNodes = (graph: Graph, community: number): Array<{ id: string; return nodes.sort((a, b) => b.weight - a.weight) } -const communityGetPublicationsCount = (aggs: ElasticAggregations): number => - aggs?.publicationsByYear?.buckets.reduce((acc, bucket) => acc + bucket.doc_count, 0) + - aggs?.publicationsByYear?.sum_other_doc_count +const communityGetPublicationsCount = (aggs: ElasticAggregations): number => aggs?.publicationsCount?.value || 0 const communityGetPublicationsByYear = (aggs: ElasticAggregations): Record => aggs?.publicationsByYear?.buckets.reduce((acc, bucket) => ({ ...acc, [bucket.key]: bucket.doc_count }), {}) @@ -138,7 +136,7 @@ export default async function communitiesCreate(graph: Graph, computeClusters: b const nodePublicationsCount = nodeInfos.publicationsCount const nodeCitationsCount = nodeGetCitationsCount(nodeCitationsByYear) const nodeCitationsRecent = nodeGetCitationsRecent(nodeCitationsByYear) - const nodeCitationsScore = nodeCitationsRecent / (nodePublicationsCount || 1) + const nodeCitationsScore = nodeCitationsRecent / (nodePublicationsCount || 1) || 0 graph.setNodeAttribute(key, "publicationsCount", nodePublicationsCount) graph.setNodeAttribute(key, "citationsCount", nodeCitationsCount) graph.setNodeAttribute(key, "citationsRecent", nodeCitationsRecent) @@ -166,6 +164,7 @@ export default async function communitiesCreate(graph: Graph, computeClusters: b }), ...(hits && { publications: communityGetPublications(hits), + publicationsCount: hits.length, }), } return community diff --git a/client/src/api/networks/search/search.ts b/client/src/api/networks/search/search.ts index 39ba12f5..7bc80b9d 100644 --- a/client/src/api/networks/search/search.ts +++ b/client/src/api/networks/search/search.ts @@ -133,6 +133,9 @@ export async function networkSearchAggs({ }, }, aggs: { + publicationsCount: { + value_count: { field: "id.keyword" }, + }, publicationsByYear: { terms: { field: "year", include: DEFAULT_YEARS, size: DEFAULT_YEARS.length }, }, diff --git a/client/src/pages/networks/hooks/useExportData.ts b/client/src/pages/networks/hooks/useExportData.ts index 4eaadff0..c4a06fdc 100644 --- a/client/src/pages/networks/hooks/useExportData.ts +++ b/client/src/pages/networks/hooks/useExportData.ts @@ -17,7 +17,16 @@ const XSLXFormatter = (network: any) => { XLSX.utils.book_append_sheet(workbook, XLSX.utils.json_to_sheet(network.items), "Items") XLSX.utils.book_append_sheet(workbook, XLSX.utils.json_to_sheet(network.links), "Links") - XLSX.utils.book_append_sheet(workbook, XLSX.utils.json_to_sheet(network.clusters), "Clusters") + XLSX.utils.book_append_sheet( + workbook, + XLSX.utils.json_to_sheet( + network.clusters.map((cluster) => { + const { publications, ...data } = cluster + return data + }) + ), + "Clusters" + ) const publicationsList = network.clusters?.reduce((acc, cluster) => { cluster?.publications.forEach((publication) => { @@ -25,6 +34,7 @@ const XSLXFormatter = (network: any) => { }) return acc }, []) + XLSX.utils.book_append_sheet(workbook, XLSX.utils.json_to_sheet(publicationsList), "Publications") const workbookOutput = XLSX.write(workbook, { type: "binary", bookType: "xlsx" })