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(website): Only count latest versions for stats on main page #2814

Merged
merged 10 commits into from
Sep 17, 2024
23 changes: 18 additions & 5 deletions website/src/components/IndexPage/getOrganismStatistics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DateTime, FixedOffsetZone } from 'luxon';

Check failure on line 1 in website/src/components/IndexPage/getOrganismStatistics.ts

View workflow job for this annotation

GitHub Actions / Check format and types

There should be at least one empty line between import groups

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

export type OrganismStatistics = {
totalSequences: number;
Expand Down Expand Up @@ -49,7 +49,7 @@
const client = LapisClient.createForOrganism(organism);
return (
await client.call('aggregated', {
version: 1,
[VERSION_STATUS_FIELD]: siloVersionStatuses.latestVersion,
theosanderson marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename the function to getTotalUnrevokedAndLastUpdatedAt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think this is ok as is (but I can live with the other option too)

})
)
.map((x) => ({
Expand All @@ -67,12 +67,25 @@
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
theosanderson marked this conversation as resolved.
Show resolved Hide resolved


})
)
.map((x) => x.data[0].count)
.unwrapOr(0);
return recentTotal-recentRevoked;
};
Loading