-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASAP-537 Algolia for team collaboration performance analytics (#4311)
- Loading branch information
Showing
13 changed files
with
572 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
apps/asap-cli/src/scripts/algolia/performance/collaboration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { SearchIndex } from 'algoliasearch'; | ||
import { | ||
timeRanges, | ||
TeamOutputDocumentType, | ||
PerformanceMetrics, | ||
} from '@asap-hub/model'; | ||
|
||
import { | ||
deletePreviousObjects, | ||
getAllHits, | ||
getBellCurveMetrics, | ||
Hit, | ||
} from '../process-performance'; | ||
|
||
type DocumentMetric = { | ||
Article: number; | ||
Bioinformatics: number; | ||
Dataset: number; | ||
'Lab Resource': number; | ||
Protocol: number; | ||
}; | ||
|
||
type TeamCollaborationHit = Hit & { | ||
outputsCoProducedAcross: { | ||
byDocumentType: DocumentMetric; | ||
}; | ||
outputsCoProducedWithin: DocumentMetric; | ||
}; | ||
|
||
export const processTeamCollaborationPerformance = async ( | ||
index: SearchIndex, | ||
) => { | ||
const type = 'team-collaboration' as const; | ||
|
||
await deletePreviousObjects(index, type); | ||
|
||
timeRanges.forEach(async (range) => { | ||
const getPaginatedHits = (page: number) => | ||
index.search<TeamCollaborationHit>('', { | ||
filters: `__meta.range:"${range}" AND (__meta.type:"${type}")`, | ||
attributesToRetrieve: [ | ||
'outputsCoProducedAcross', | ||
'outputsCoProducedWithin', | ||
], | ||
page, | ||
hitsPerPage: 50, | ||
}); | ||
|
||
const hits = await getAllHits<TeamCollaborationHit>(getPaginatedHits); | ||
|
||
const fields = [ | ||
{ name: 'Article', documentType: 'article' }, | ||
{ name: 'Bioinformatics', documentType: 'bioinformatics' }, | ||
{ name: 'Dataset', documentType: 'dataset' }, | ||
{ name: 'Lab Resource', documentType: 'labResource' }, | ||
{ name: 'Protocol', documentType: 'protocol' }, | ||
]; | ||
|
||
const teamPerformanceByDocumentType = (rawMetrics: DocumentMetric[]) => | ||
fields.reduce( | ||
(metrics, { name, documentType }) => ({ | ||
...metrics, | ||
[documentType]: getBellCurveMetrics( | ||
rawMetrics.map((item) => item[name as TeamOutputDocumentType]), | ||
), | ||
}), | ||
{} as Record<string, PerformanceMetrics>, | ||
); | ||
|
||
await index.saveObject( | ||
{ | ||
withinTeam: teamPerformanceByDocumentType( | ||
hits.map((hit) => hit.outputsCoProducedWithin), | ||
), | ||
accrossTeam: teamPerformanceByDocumentType( | ||
hits.map((hit) => hit.outputsCoProducedAcross.byDocumentType), | ||
), | ||
__meta: { | ||
range, | ||
type: `${type}-performance`, | ||
}, | ||
}, | ||
{ autoGenerateObjectIDIfNotExist: true }, | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.