Skip to content

Commit

Permalink
ASAP-607 - filter out outputs that are not asap funded (#4361)
Browse files Browse the repository at this point in the history
* filter out outputs not asap funded

* update tests

* update collaboration tests
  • Loading branch information
AkosuaA authored Aug 30, 2024
1 parent 183d0a0 commit 4547c7b
Show file tree
Hide file tree
Showing 10 changed files with 485 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
getFilterOutputByDocumentCategory,
getFilterOutputByRange,
getFilterOutputBySharingStatus,
isAsapFundedResearchOutput,
isTeamOutputDocumentType,
} from '../../utils/analytics/common';
import { getEngagementItems } from '../../utils/analytics/engagement';
Expand Down Expand Up @@ -272,6 +273,7 @@ const getUserProductivityItems = (
) || [];

const userOutputsCount = user.linkedFrom?.researchOutputsCollection?.items
.filter(isAsapFundedResearchOutput)
.filter(getFilterOutputByRange(filter?.timeRange))
.filter(getFilterOutputByDocumentCategory(filter?.documentCategory))
.reduce(
Expand Down Expand Up @@ -343,6 +345,7 @@ const getTeamProductivityItems = (

const documentTypesCount =
teamItem.linkedFrom?.researchOutputsCollection?.items
.filter(isAsapFundedResearchOutput)
.filter(getFilterOutputByRange(rangeKey))
.filter(getFilterOutputBySharingStatus(outputType))
.reduce((count, researchOutput) => {
Expand Down
3 changes: 3 additions & 0 deletions apps/crn-server/src/utils/analytics/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getFilterOutputByDocumentCategory,
getFilterOutputByRange,
getFilterOutputBySharingStatus,
isAsapFundedResearchOutput,
isTeamOutputDocumentType,
} from './common';

Expand Down Expand Up @@ -119,6 +120,7 @@ export const getUserCollaborationItems = (
const outputsCoAuthoredWithinTeamSet = new Set();

item.linkedFrom?.researchOutputsCollection?.items
.filter(isAsapFundedResearchOutput)
.filter(getFilterOutputByRange(rangeKey))
.filter(getFilterOutputByDocumentCategory(documentCategory))
.forEach((output) => {
Expand Down Expand Up @@ -260,6 +262,7 @@ export const getTeamCollaborationItems = (
): TeamCollaborationDataObject[] =>
cleanArray(teamCollection?.items).map((team) => {
const outputsData = team.linkedFrom?.researchOutputsCollection?.items
.filter(isAsapFundedResearchOutput)
.filter(getFilterOutputByRange(rangeKey))
.filter(getFilterOutputBySharingStatus(outputType))
.filter(
Expand Down
10 changes: 9 additions & 1 deletion apps/crn-server/src/utils/analytics/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
type AnalyticOutput = Maybe<
Pick<
ResearchOutputs,
'documentType' | 'sharingStatus' | 'addedDate' | 'createdDate'
| 'documentType'
| 'sharingStatus'
| 'addedDate'
| 'createdDate'
| 'asapFunded'
> & {
authorsCollection?: Maybe<{
items: Array<
Expand Down Expand Up @@ -79,6 +83,10 @@ export const isTeamOutputDocumentType = (
): documentType is TeamOutputDocumentType =>
teamOutputDocumentTypes.includes(documentType as TeamOutputDocumentType);

export const isAsapFundedResearchOutput = (
researchOutput: AnalyticOutput,
): boolean => researchOutput?.asapFunded === 'Yes';

// remove string from one array that are present in another array and return a new array of strings
export const removeDuplicates = (arr1: string[], arr2: string[]): string[] => [
...arr1.filter((elem) => !arr2.includes(elem)),
Expand Down
Loading

0 comments on commit 4547c7b

Please sign in to comment.