Skip to content

Commit

Permalink
feat(clusters): add top country
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Oct 23, 2023
1 parent 6a8a859 commit 2f21fbb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client/src/layout/ClustersPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ export default function ClustersPanel({ graph, communities, publications, struct
/>
))}
</BadgeGroup>
<Title as="h6">
{' '}
1 main country :
{' '}
{community.country[0][0]}
{' '}
</Title>
<Title as="h6">
Publications years
</Title>
Expand Down
26 changes: 26 additions & 0 deletions client/src/utils/communityUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ function communityGetAffiliationsCount(community, publications, structures, limi
return Object.entries(topAffiliations);
}

function communityGetCountryCount(community, publications, structures, limit = 0) {
const countries = {};

// Count countries from unique publication ids
community.reduce((acc, node) => [...acc, ...node.attributes.publications.flatMap((id) => (!acc.includes(id) ? id : []))], []).forEach((publicationId) => {
publications[publicationId]?.affiliations?.forEach((structureId) => { countries[structures[structureId].country] = countries[structures[structureId].country] + 1 || 1; });
});

const numberOfCountries = Object.keys(countries).length;

if (numberOfCountries === 0) return [];

// Get max countries
const endSlice = limit > 0 ? limit : numberOfCountries;
const topCountries = Object.assign(
...Object
.entries(countries)
.sort(({ 1: a }, { 1: b }) => b - a)
.slice(0, endSlice)
.map(([k, v]) => ({ [k]: v })),
);

return Object.entries(topCountries);
}

function communityGetYearsCount(community, publications) {
const DEFAULT_YEARS = [2018, 2019, 2020, 2021, 2022, 2023];
const years = {};
Expand Down Expand Up @@ -114,6 +139,7 @@ export function fillAndSortCommunities(communities, publications, structures, {
authors: communityGetBestAuthors(values, authorsLimit),
affiliations: communityGetAffiliationsCount(values, publications, structures, institutionsLimit),
years: communityGetYearsCount(values, publications),
country: communityGetCountryCount(values, publications, structures, 1),
};
});

Expand Down

0 comments on commit 2f21fbb

Please sign in to comment.