diff --git a/src/card.ts b/src/card.ts index 8b44ad9..c2a5d9c 100644 --- a/src/card.ts +++ b/src/card.ts @@ -6,7 +6,10 @@ import { TotalIssueTrophy, TotalPullRequestTrophy, TotalRepositoryTrophy, - MultipleLangTrophy + MultipleLangTrophy, + LongTimeAccountTrophy, + AncientAccountTrophy + } from "./trophies.ts"; import { UserInfo } from "./github_api_client.ts"; import { CONSTANTS, RANK_ORDER, RANK } from "./utils.ts"; @@ -32,6 +35,8 @@ export class Card { new TotalPullRequestTrophy(userInfo.totalPullRequests), new TotalRepositoryTrophy(userInfo.totalRepositories), new MultipleLangTrophy(userInfo.languageCount), + new LongTimeAccountTrophy(userInfo.durationYear), + new AncientAccountTrophy(userInfo.acientAccount), ); // Filter by hidden diff --git a/src/github_api_client.ts b/src/github_api_client.ts index 7edfe14..6ce42dc 100644 --- a/src/github_api_client.ts +++ b/src/github_api_client.ts @@ -8,7 +8,9 @@ export class UserInfo { public totalStargazers: number, public totalRepositories: number, public totalContributed: number, - public languageCount: number + public languageCount: number, + public durationYear: number, + public acientAccount:number ) { } } @@ -24,6 +26,7 @@ export class GithubAPIClient { user(login: $username) { name login + createdAt contributionsCollection { totalCommitContributions restrictedContributionsCount @@ -76,6 +79,9 @@ export class GithubAPIClient { languages.add(node.languages.nodes[0].name) } }); + const durationTime = new Date().getTime() - new Date(userData.createdAt).getTime(); + const durationYear = new Date(durationTime).getUTCFullYear() - 1970; + const acientAccount = new Date(userData.createdAt).getFullYear() <= 2010 ? 1:0; const userInfo = new UserInfo( totalCommits, userData.followers.totalCount, @@ -84,7 +90,9 @@ export class GithubAPIClient { totalStargazers, userData.repositories.totalCount, userData.repositoriesContributedTo.totalCount, - languages.size + languages.size, + durationYear, + acientAccount ) return userInfo; } diff --git a/src/icons.ts b/src/icons.ts index 180c0e8..72bfae8 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -1,14 +1,5 @@ -import { RANK } from "./utils.ts"; +import { RANK, COLORS } from "./utils.ts"; -const goldColor = "#FAD200"; -const goldShadowColor = "#C8A090"; -const goldTextColor = "#886000"; -const silverColor = "#B0B0B0"; -const sliverShadowColor = "#9090C0"; -const silverTextColor = "#505050"; -const bronzeColor = "#A18D66"; -const bronzeShadowColor = "#816D96"; -const bronzeTextColor = "#412D06"; const leafIcon = ` @@ -35,7 +26,6 @@ Created by potrace 1.15, written by Peter Selinger 2001-2017 export const getNextRankBar = ( title: string, - color: string, percentage: number, ): string => { const maxWidht = 80; @@ -60,7 +50,7 @@ export const getNextRankBar = ( width="${maxWidht}" height="3.2" opacity="0.3" - fill="${color}" + fill="${COLORS.NEXT_RANK_BAR}" /> `; }; @@ -82,7 +72,7 @@ const getSmallTrophyIcon = ( const leftXPosition = 7; const rightXPosition = 68; const getIcon = (x: number) => { - return ` + return ` ${icon} `; }; @@ -97,46 +87,46 @@ const getSmallTrophyIcon = ( return ""; }; export const getTrophyIcon = (rank = RANK.UNKNOWN) => { - let color = "currentColor"; - let rankColor = "#333"; + let color = COLORS.DEFAULT_RANK_BASE; + let rankColor = COLORS.DEFAULT_RANK_TEXT; let backgroundIcon = ""; let gradationColor = ` - - - + + + `; if (rank === RANK.SECRET) { - rankColor = "fuchsia"; + rankColor = COLORS.SECRET_RANK_TEXT; gradationColor = ` - - - - `; + + + + `; } else if (rank.slice(0, 1) === RANK.S) { - color = goldColor; - rankColor = goldTextColor; + color = COLORS.S_RANK_BASE; + rankColor = COLORS.S_RANK_TEXT; backgroundIcon = leafIcon; gradationColor = ` - + `; } else if (rank.slice(0, 1) === RANK.A) { - color = silverColor; - rankColor = silverTextColor; + color = COLORS.A_RANK_BASE; + rankColor = COLORS.A_RAKN_TEXT; backgroundIcon = leafIcon; gradationColor = ` - + `; } else if (rank === RANK.B) { - color = bronzeColor; - rankColor = bronzeTextColor; + color = COLORS.B_RANK_BASE; + rankColor = COLORS.B_RANK_TEXT; gradationColor = ` - + `; } const icon = ` diff --git a/src/trophies.ts b/src/trophies.ts index 60f8ade..ed636ee 100644 --- a/src/trophies.ts +++ b/src/trophies.ts @@ -1,5 +1,5 @@ import { getTrophyIcon, getNextRankBar } from "./icons.ts"; -import { CONSTANTS, RANK, abridgeScore, RANK_ORDER } from "./utils.ts"; +import { CONSTANTS, RANK, abridgeScore, RANK_ORDER, COLORS } from "./utils.ts"; class RankCondition { constructor( @@ -57,7 +57,6 @@ export class Trophy { render(x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE): string { const nextRankBar = getNextRankBar( this.title, - "#0366d6", this.calculateNextRankPercentage(), ); return ` @@ -103,7 +102,36 @@ export class MultipleLangTrophy extends Trophy{ this.title = "MultipleLang"; this.hidden = true; } +} +export class AncientAccountTrophy extends Trophy{ + constructor(score: number){ + const rankConditions = [ + new RankCondition( + RANK.SECRET, + "Ancient User", + 1, + ), + ]; + super(score, rankConditions); + this.title = "AncientUser"; + this.bottomMessage = "Before 2010" + this.hidden = true; + } +} +export class LongTimeAccountTrophy extends Trophy{ + constructor(score: number){ + const rankConditions = [ + new RankCondition( + RANK.SECRET, + "Village Elder", + 10, + ), + ]; + super(score, rankConditions); + this.title = "LongTimeUser"; + this.hidden = true; + } } export class TotalStarTrophy extends Trophy { diff --git a/src/utils.ts b/src/utils.ts index 2e96ae7..027137f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,8 +1,8 @@ import { ServerRequest } from ".././deps.ts"; export function parseParams(req: ServerRequest): URLSearchParams { - const splitedURL = req.url.split("?") - if (splitedURL.length < 2){ + const splitedURL = req.url.split("?"); + if (splitedURL.length < 2) { return new URLSearchParams(); } return new URLSearchParams(splitedURL[1]); @@ -12,12 +12,10 @@ export function abridgeScore(score: number): string { if (Math.abs(score) < 1) { return "unknown"; } - if (Math.abs(score) > 999){ - return (Math.sign(score) * (Math.abs(score) / 1000)).toFixed(1) + "pt" - + if (Math.abs(score) > 999) { + return (Math.sign(score) * (Math.abs(score) / 1000)).toFixed(1) + "pt"; } return (Math.sign(score) * Math.abs(score)).toString() + "pt"; - } export const CONSTANTS = { @@ -38,7 +36,26 @@ export enum RANK { B = "B", C = "C", UNKNOWN = "?", - } -export const RANK_ORDER= Object.values(RANK); +export const COLORS = { + SECRET_RANK_1: "red", + SECRET_RANK_2: "fuchsia", + SECRET_RANK_3: "blue", + SECRET_RANK_TEXT: "fuchsia", + S_RANK_BASE: "#FAD200", + S_RANK_SHADOW: "#C8A090", + S_RANK_TEXT: "#886000", + A_RANK_BASE: "#B0B0B0", + A_RANK_SHADOW: "#9090C0", + A_RAKN_TEXT: "#505050", + B_RANK_BASE: "#A18D66", + B_RANK_SHADOW: "#816D96", + B_RANK_TEXT: "#412D06", + DEFAULT_RANK_BASE: "#777", + DEFAULT_RANK_SHADOW: "#333", + DEFAULT_RANK_TEXT: "#333", + NEXT_RANK_BAR: "#0366d6", +}; + +export const RANK_ORDER = Object.values(RANK);