Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SKFP-1077 add members count stats #145

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading