Skip to content

Commit

Permalink
feat(website): Only count latest versions for stats on main page (#2814)
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson committed Sep 17, 2024
1 parent cca00bb commit 096b1d2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions website/src/components/IndexPage/getOrganismStatistics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DateTime, FixedOffsetZone } from 'luxon';

import { LapisClient } from '../../services/lapisClient.ts';
import { RELEASED_AT_FIELD } from '../../settings.ts';
import { RELEASED_AT_FIELD, VERSION_STATUS_FIELD, IS_REVOCATION_FIELD } from '../../settings.ts';
import { siloVersionStatuses } from '../../types/lapis';

export type OrganismStatistics = {
totalSequences: number;
Expand Down Expand Up @@ -49,7 +50,8 @@ const getTotalAndLastUpdatedAt = async (
const client = LapisClient.createForOrganism(organism);
return (
await client.call('aggregated', {
version: 1,
[VERSION_STATUS_FIELD]: siloVersionStatuses.latestVersion,
[IS_REVOCATION_FIELD]: 'false',
})
)
.map((x) => ({
Expand All @@ -67,12 +69,22 @@ const getTotalAndLastUpdatedAt = async (
const getRecent = async (organism: string, numberDaysAgo: number): Promise<number> => {
const recentTimestamp = Math.floor(Date.now() / 1000 - numberDaysAgo * 24 * 60 * 60);
const client = LapisClient.createForOrganism(organism);
return (
const recentTotal = (
await client.call('aggregated', {
[`${RELEASED_AT_FIELD}From`]: recentTimestamp,
version: 1,
})
)
.map((x) => x.data[0].count)
.unwrapOr(0);
const recentRevoked = (
await client.call('aggregated', {
[`${RELEASED_AT_FIELD}From`]: recentTimestamp,
version: 1,
[VERSION_STATUS_FIELD]: siloVersionStatuses.revoked,
})
)
.map((x) => x.data[0].count)
.unwrapOr(0);
return recentTotal - recentRevoked;
};

0 comments on commit 096b1d2

Please sign in to comment.