Skip to content

Commit

Permalink
fix a few stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 28, 2023
1 parent b41a46f commit 16772d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions client/src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default function Home() {
const affiliationIds = affiliations.map((affiliation) => affiliation.id);
allAffiliationsTmp.filter((affiliation) => affiliationIds.includes(affiliation.id)).map((affiliation) => affiliation.status = action);
setAllAffiliations(allAffiliationsTmp);
// setSelectedAffiliations([]);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions server/src/routes/works.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ router.route('/works')
const datasets = [];
deduplicatedWorks.forEach((deduplicatedWork) => {
if (
(deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.genre_raw !== 'dataset')
(deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.type !== 'dataset')
|| (deduplicatedWork.datasource.includes('openalex') && deduplicatedWork.type !== 'dataset')
) {
publications.push(deduplicatedWork);
} else if (
(deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.genre_raw === 'dataset')
(deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.type === 'dataset')
|| (deduplicatedWork.datasource.includes('openalex') && deduplicatedWork.type === 'dataset')
) {
datasets.push(deduplicatedWork);
Expand Down
4 changes: 2 additions & 2 deletions server/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const getRegexpFromOptions = (options) => {
return regex;
};

const normalizedName = (name) => name
const normalizeName = (name) => name
.toLowerCase()
.normalize('NFD')
.replace(/[^a-zA-Z0-9]/g, ' ')
Expand All @@ -42,6 +42,6 @@ const normalizedName = (name) => name
export {
cleanId,
getRegexpFromOptions,
normalizedName,
normalizeName,
range,
};
19 changes: 14 additions & 5 deletions server/src/utils/works.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cleanId, getRegexpFromOptions, normalizedName, range } from './utils';
import { cleanId, getRegexpFromOptions, normalizeName, range } from './utils';

const VITE_OPENALEX_MAX_PAGE = Math.floor(process.env.VITE_OPENALEX_SIZE / process.env.VITE_OPENALEX_PER_PAGE);

Expand Down Expand Up @@ -157,6 +157,8 @@ const getTypeFromOpenAlex = (type) => {
case 'posted-content':
newType = 'preprint';
break;
default:
newType = type;
}
return newType;
};
Expand Down Expand Up @@ -217,12 +219,12 @@ const groupByAffiliations = ({ options, works }) => {
works.forEach((work) => {
(work?.affiliations ?? [])
.forEach((affiliation) => {
const normalizedAffiliationName = normalizedName(affiliation);
const normalizedAffiliationName = normalizeName(affiliation);
if (!allAffiliationsTmp?.[normalizedAffiliationName]) {
// Check matches in affiliation name
let matches = affiliation?.match(regexp) ?? [];
// Normalize matched strings
matches = matches.map((match) => normalizedName(match));
matches = matches.map((match) => normalizeName(match));
// Filter matches as unique
matches = [...new Set(matches)];
allAffiliationsTmp[normalizedAffiliationName] = {
Expand All @@ -235,9 +237,16 @@ const groupByAffiliations = ({ options, works }) => {
allAffiliationsTmp[normalizedAffiliationName].works.push(work.id);
});
});

allAffiliationsTmp = Object.values(allAffiliationsTmp)
.map((affiliation, index) => ({ ...affiliation, id: index.toString(), works: [...new Set(affiliation.works)], worksNumber: [...new Set(affiliation.works)].length }));
.map((affiliation, index) => {
const uniqueWorks = [...new Set(affiliation.works)];
return ({
...affiliation,
id: index.toString(),
works: uniqueWorks,
worksNumber: uniqueWorks.length,
});
});
return allAffiliationsTmp;
};

Expand Down

0 comments on commit 16772d1

Please sign in to comment.