From edb66bb16639fb5e72a01132f2f641c248eef0fc Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 1 Nov 2021 21:15:09 +0100 Subject: [PATCH] Feature/extend statistics (#449) * Extend statistics * Update changelog --- CHANGELOG.md | 2 ++ apps/api/src/app/info/info.service.ts | 28 ++++++++++++++++++- .../src/app/pages/about/about-page.html | 28 ++++++++++++++++--- .../lib/interfaces/statistics.interface.ts | 2 ++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e670973..56cb7e31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Prettified the generic scraper symbols in the portfolio proportion chart component +- Extended the statistics section on the about page by the active users count (7d) +- Extended the statistics section on the about page by the new users count ## 1.67.0 - 31.10.2021 diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index c84daab1a..7aca1b82d 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -136,6 +136,28 @@ export class InfoService { } } + private async countNewUsers(aDays: number) { + return await this.prismaService.user.count({ + orderBy: { + createdAt: 'desc' + }, + where: { + AND: [ + { + NOT: { + Analytics: null + } + }, + { + createdAt: { + gt: subDays(new Date(), aDays) + } + } + ] + } + }); + } + private getDemoAuthToken() { return this.jwtService.sign({ id: InfoService.DEMO_USER_ID @@ -155,15 +177,19 @@ export class InfoService { } const activeUsers1d = await this.countActiveUsers(1); + const activeUsers7d = await this.countActiveUsers(7); const activeUsers30d = await this.countActiveUsers(30); + const newUsers30d = await this.countNewUsers(30); const gitHubContributors = await this.countGitHubContributors(); const gitHubStargazers = await this.countGitHubStargazers(); return { activeUsers1d, + activeUsers7d, activeUsers30d, gitHubContributors, - gitHubStargazers + gitHubStargazers, + newUsers30d }; } diff --git a/apps/client/src/app/pages/about/about-page.html b/apps/client/src/app/pages/about/about-page.html index beff9cf75..a8462f5c1 100644 --- a/apps/client/src/app/pages/about/about-page.html +++ b/apps/client/src/app/pages/about/about-page.html @@ -107,7 +107,7 @@
-
+

{{ statistics?.activeUsers1d ?? '-' }}

@@ -117,7 +117,17 @@ >
-
+
+

+ {{ statistics?.activeUsers7d ?? '-' }} +

+
+ Active Users (Last 7 days) +
+
+

{{ statistics?.activeUsers30d ?? '-' }}

@@ -127,13 +137,23 @@ >
-
+
+

+ {{ statistics?.newUsers30d ?? '-' }} +

+
+ New Users (Last 30 days) +
+
+

{{ statistics?.gitHubContributors ?? '-' }}

Contributors on GitHub
-
+

{{ statistics?.gitHubStargazers ?? '-' }}

diff --git a/libs/common/src/lib/interfaces/statistics.interface.ts b/libs/common/src/lib/interfaces/statistics.interface.ts index 5bac1387f..98f1753bb 100644 --- a/libs/common/src/lib/interfaces/statistics.interface.ts +++ b/libs/common/src/lib/interfaces/statistics.interface.ts @@ -1,6 +1,8 @@ export interface Statistics { activeUsers1d: number; + activeUsers7d: number; activeUsers30d: number; gitHubContributors: number; gitHubStargazers: number; + newUsers30d: number; }