Browse Source

Add contributors count to statistics

pull/342/head
Thomas 4 years ago
parent
commit
bd8b536c30
  1. 23
      apps/api/src/app/info/info.service.ts
  2. 12
      apps/client/src/app/pages/about/about-page.html
  3. 1
      libs/common/src/lib/interfaces/statistics.interface.ts

23
apps/api/src/app/info/info.service.ts

@ -90,6 +90,27 @@ export class InfoService {
}); });
} }
private async countGitHubContributors(): Promise<number> {
try {
const get = bent(
`https://api.github.com/repos/ghostfolio/ghostfolio/contributors`,
'GET',
'json',
200,
{
'User-Agent': 'request'
}
);
const contributors = await get();
return contributors?.length;
} catch (error) {
console.error(error);
return undefined;
}
}
private async countGitHubStargazers(): Promise<number> { private async countGitHubStargazers(): Promise<number> {
try { try {
const get = bent( const get = bent(
@ -131,11 +152,13 @@ export class InfoService {
const activeUsers1d = await this.countActiveUsers(1); const activeUsers1d = await this.countActiveUsers(1);
const activeUsers30d = await this.countActiveUsers(30); const activeUsers30d = await this.countActiveUsers(30);
const gitHubContributors = await this.countGitHubContributors();
const gitHubStargazers = await this.countGitHubStargazers(); const gitHubStargazers = await this.countGitHubStargazers();
return { return {
activeUsers1d, activeUsers1d,
activeUsers30d, activeUsers30d,
gitHubContributors,
gitHubStargazers gitHubStargazers
}; };
} }

12
apps/client/src/app/pages/about/about-page.html

@ -94,7 +94,7 @@
<mat-card> <mat-card>
<mat-card-content> <mat-card-content>
<div class="row"> <div class="row">
<div class="col-xs-12 col-md-4 my-2"> <div class="col-xs-12 col-md-3 my-2">
<h3 class="mb-0" [hidden]="!statistics?.activeUsers1d"> <h3 class="mb-0" [hidden]="!statistics?.activeUsers1d">
{{ statistics?.activeUsers1d ?? '-' }} {{ statistics?.activeUsers1d ?? '-' }}
</h3> </h3>
@ -102,7 +102,7 @@
Active Users <small class="text-muted">(Last 24 hours)</small> Active Users <small class="text-muted">(Last 24 hours)</small>
</div> </div>
</div> </div>
<div class="col-xs-12 col-md-4 my-2"> <div class="col-xs-12 col-md-3 my-2">
<h3 class="mb-0" [hidden]="!statistics?.activeUsers30d"> <h3 class="mb-0" [hidden]="!statistics?.activeUsers30d">
{{ statistics?.activeUsers30d ?? '-' }} {{ statistics?.activeUsers30d ?? '-' }}
</h3> </h3>
@ -110,7 +110,13 @@
Active Users <small class="text-muted">(Last 30 days)</small> Active Users <small class="text-muted">(Last 30 days)</small>
</div> </div>
</div> </div>
<div class="col-xs-12 col-md-4 my-2"> <div class="col-xs-12 col-md-3 my-2">
<h3 class="mb-0" [hidden]="!statistics?.gitHubContributors">
{{ statistics?.gitHubContributors ?? '-' }}
</h3>
<div class="h6 mb-0">Contributors on GitHub</div>
</div>
<div class="col-xs-12 col-md-3 my-2">
<h3 class="mb-0" [hidden]="!statistics?.gitHubStargazers"> <h3 class="mb-0" [hidden]="!statistics?.gitHubStargazers">
{{ statistics?.gitHubStargazers ?? '-' }} {{ statistics?.gitHubStargazers ?? '-' }}
</h3> </h3>

1
libs/common/src/lib/interfaces/statistics.interface.ts

@ -1,5 +1,6 @@
export interface Statistics { export interface Statistics {
activeUsers1d: number; activeUsers1d: number;
activeUsers30d: number; activeUsers30d: number;
gitHubContributors: number;
gitHubStargazers: number; gitHubStargazers: number;
} }

Loading…
Cancel
Save