Skip to content

Commit

Permalink
fix(networks): clusters publications count
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Oct 21, 2024
1 parent 51af50f commit 8082bf3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 3 additions & 4 deletions client/src/api/networks/network/communities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number> =>
aggs?.publicationsByYear?.buckets.reduce((acc, bucket) => ({ ...acc, [bucket.key]: bucket.doc_count }), {})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -166,6 +164,7 @@ export default async function communitiesCreate(graph: Graph, computeClusters: b
}),
...(hits && {
publications: communityGetPublications(hits),
publicationsCount: hits.length,
}),
}
return community
Expand Down
3 changes: 3 additions & 0 deletions client/src/api/networks/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
Expand Down
12 changes: 11 additions & 1 deletion client/src/pages/networks/hooks/useExportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ 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) => {
acc = [...acc, { id: publication.id, title: publication.title, cluster: cluster.cluster, clusterLabel: cluster.label }]
})
return acc
}, [])

XLSX.utils.book_append_sheet(workbook, XLSX.utils.json_to_sheet(publicationsList), "Publications")

const workbookOutput = XLSX.write(workbook, { type: "binary", bookType: "xlsx" })
Expand Down

0 comments on commit 8082bf3

Please sign in to comment.