Skip to content

Commit

Permalink
feat: SKFP-1077 add members count stats (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
aperron-ferlab authored May 22, 2024
1 parent 074c668 commit 0d31f3e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ describe('Express app (without Arranger)', () => {
count: 867,
},
],
members: {
totalCount: 12343,
publicCount: 345,
},
};
(getStatistics as jest.Mock).mockImplementation(() => expectedStats);

Expand Down
26 changes: 26 additions & 0 deletions src/endpoints/statistics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import filesize from 'filesize';
import EsInstance from '../../ElasticSearchClientInstance';
import {
esFileIndex,
esMembersIndex,
esParticipantIndex,
esPublicMemberIndex,
esStudyIndex,
esVariantIndex,
familyIdKey,
Expand All @@ -23,6 +25,11 @@ export type Diagnosis = {
count: number;
};

export type MembersCount = {
totalCount: number;
publicCount: number;
};

export type Statistics = {
files: number;
fileSize: string;
Expand All @@ -37,6 +44,7 @@ export type Statistics = {
downSyndromeStatus: Record<string, number>;
race: Record<string, number>;
diagnosis: Diagnosis[];
members: MembersCount;
};

const fetchFileStats = async (client: Client): Promise<number> => {
Expand Down Expand Up @@ -289,6 +297,22 @@ export const fetchTopDiagnosis = async (client: Client): Promise<Diagnosis[]> =>
}));
};

export const fetchMemberStats = async (client: Client): Promise<MembersCount> => {
if (project === PROJECT_INCLUDE) return;

const { body: members } = await client.count({
index: esMembersIndex,
});

const { body: publicMembers } = await client.count({
index: esPublicMemberIndex,
});
return {
totalCount: members?.count,
publicCount: publicMembers?.count,
};
};

export const getStatistics = async (): Promise<Statistics> => {
const client = EsInstance.getInstance();
const results = await Promise.all([
Expand All @@ -306,6 +330,7 @@ export const getStatistics = async (): Promise<Statistics> => {

const diagnosis = await fetchTopDiagnosis(client);

const members = await fetchMemberStats(client);
return {
files: results[0],
studies: results[1],
Expand All @@ -320,6 +345,7 @@ export const getStatistics = async (): Promise<Statistics> => {
downSyndromeStatus: results[9][1],
race: results[9][2],
diagnosis,
members,
};
};

Expand Down
4 changes: 4 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const esParticipantIndex = process.env.ES_PARTICIPANT_INDEX || 'participa
export const esBiospecimenIndex = process.env.ES_BIOSPECIMEN_INDEX || 'biospecimen_centric';
export const esVariantIndex = process.env.ES_VARIANT_INDEX || 'variant_centric';

export const esMembersIndex = process.env.ES_MEMBERS_INDEX || 'members';

export const esPublicMemberIndex = process.env.ES_PUBLIC_MEMBERS_INDEX || 'members-public';

export const maxNOfGenomicFeatureSuggestions = process.env.MAX_NUMBER_OF_GF_SUGGESTIONS || 5;

export const indexNameGeneFeatureSuggestion = process.env.GENES_SUGGESTIONS_INDEX_NAME;
Expand Down

0 comments on commit 0d31f3e

Please sign in to comment.