Added Account Duration/Experience Trophy (#203)

* Added Account Duration/Experience Trophy

* Minor Formatting Changes

* deno fmt correction

---------

Co-authored-by: Alexandro Castro <10711649+AlexcastroDev@users.noreply.github.com>
This commit is contained in:
Bhav Beri 2023-10-03 20:28:45 +05:30 • committed by GitHub
parent 22a9bc4112
commit 0cc5b5cbc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 0 deletions

View file

@ -267,6 +267,57 @@ export class TotalReviewsTrophy extends Trophy {
}
}
export class AccountDurationTrophy extends Trophy {
constructor(score: number) {
const rankConditions = [
new RankCondition(
RANK.SSS,
"Seasoned Veteran",
70, // 20 years
),
new RankCondition(
RANK.SS,
"GranMaster",
55, // 15 years
),
new RankCondition(
RANK.S,
"Master Dev",
40, // 10 years
),
new RankCondition(
RANK.AAA,
"Expert Dev",
28, // 7.5 years
),
new RankCondition(
RANK.AA,
"Experienced Dev",
18, // 5 years
),
new RankCondition(
RANK.A,
"Intermediate Dev",
11, // 3 years
),
new RankCondition(
RANK.B,
"Junior Dev",
6, // 1.5 years
),
new RankCondition(
RANK.C,
"Newbie",
2, // 0.5 year
),
];
super(score, rankConditions);
this.title = "Experience";
this.filterTitles = ["Experience", "Duration", "Since"];
// this.hidden = true;
}
}
export class TotalStarTrophy extends Trophy {
constructor(score: number) {
const rankConditions = [

View file

@ -1,4 +1,5 @@
import {
AccountDurationTrophy,
AllSuperRankTrophy,
AncientAccountTrophy,
Joined2020Trophy,
@ -40,6 +41,7 @@ export class TrophyList {
new OGAccountTrophy(userInfo.ogAccount),
new Joined2020Trophy(userInfo.joined2020),
new MultipleOrganizationsTrophy(userInfo.totalOrganizations),
new AccountDurationTrophy(userInfo.durationDays),
);
}
get length() {

View file

@ -51,6 +51,7 @@ export class UserInfo {
public readonly totalRepositories: number;
public readonly languageCount: number;
public readonly durationYear: number;
public readonly durationDays: number;
public readonly ancientAccount: number;
public readonly joined2020: number;
public readonly ogAccount: number;
@ -83,6 +84,9 @@ export class UserInfo {
const durationTime = new Date().getTime() -
new Date(userActivity.createdAt).getTime();
const durationYear = new Date(durationTime).getUTCFullYear() - 1970;
const durationDays = Math.floor(
durationTime / (1000 * 60 * 60 * 24) / 100,
);
const ancientAccount =
new Date(userActivity.createdAt).getFullYear() <= 2010 ? 1 : 0;
const joined2020 = new Date(userActivity.createdAt).getFullYear() == 2020
@ -104,6 +108,7 @@ export class UserInfo {
this.totalRepositories = userRepository.repositories.totalCount;
this.languageCount = languages.size;
this.durationYear = durationYear;
this.durationDays = durationDays;
this.ancientAccount = ancientAccount;
this.joined2020 = joined2020;
this.ogAccount = ogAccount;