From 52ccc94bb66e46a530f84d22d1e3500412026f89 Mon Sep 17 00:00:00 2001 From: ryo-ma Date: Mon, 24 Aug 2020 23:03:21 +0900 Subject: [PATCH] Replace Number to number --- src/github_api_client.ts | 16 +++--- src/trophies.ts | 103 ++++++++++++++++----------------------- 2 files changed, 49 insertions(+), 70 deletions(-) diff --git a/src/github_api_client.ts b/src/github_api_client.ts index c10e72b..d116d77 100644 --- a/src/github_api_client.ts +++ b/src/github_api_client.ts @@ -1,13 +1,13 @@ import {soxa} from "../deps.ts"; export class UserInfo { constructor( - public totalCommits: Number, - public totalFollowers: Number, - public totalIssues: Number, - public totalPullRequests: Number, - public totalStargazers: Number, - public totalRepositories: Number, - public totalContributed: Number, + public totalCommits: number, + public totalFollowers: number, + public totalIssues: number, + public totalPullRequests: number, + public totalStargazers: number, + public totalRepositories: number, + public totalContributed: number, ) { } } @@ -60,7 +60,7 @@ export class GithubAPIClient { ); const userData = response.data.data.user; const totalCommits = userData.contributionsCollection.restrictedContributionsCount + userData.contributionsCollection.totalCommitContributions; - const totalStargazers = userData.repositories.nodes.reduce((prev: Number, node: any) => { + const totalStargazers = userData.repositories.nodes.reduce((prev: number, node: any) => { return prev + node.stargazers.totalCount; }, 0); const userInfo = new UserInfo( diff --git a/src/trophies.ts b/src/trophies.ts index d8677f3..74dee7d 100644 --- a/src/trophies.ts +++ b/src/trophies.ts @@ -1,11 +1,14 @@ import { getTropyIcon } from "./icons.ts"; -import { CONSTANTS, RANK } from "./utils.ts"; +import { CONSTANTS, RANK, abridgeScore } from "./utils.ts"; export abstract class Trophy { rank: RANK = RANK.UNKNOWN; topMessage = "Unknown"; bottomMessage = "+0"; title = ""; + constructor() { + this.setRank(); + } abstract setRank(): void; render(x = 0, y = 0, panelSize = CONSTANTS.DEFALT_PANEL_SIZE): string { return ` @@ -31,169 +34,145 @@ export abstract class Trophy { ${getTropyIcon(this.rank)} ${this.title} ${this.topMessage} - ${this.bottomMessage} + ${this.bottomMessage} `; } } export class TotalStarTrophy extends Trophy { - constructor(private totalStartgazer: Number) { + constructor(private score: number) { super(); this.title = "Star"; - this.setRank(); } setRank() { - if (this.totalStartgazer >= 200) { + this.bottomMessage = abridgeScore(this.score); + if (this.score >= 200) { this.rank = RANK.S; this.topMessage = "Super Star"; - this.bottomMessage = "+200"; - } else if (this.totalStartgazer >= 100) { + } else if (this.score >= 100) { this.rank = RANK.A; this.topMessage = "High Star"; - this.bottomMessage = "+100"; - } else if (this.totalStartgazer >= 10) { + } else if (this.score >= 10) { this.rank = RANK.B; this.topMessage = "Middle Star"; - this.bottomMessage = "+10"; - } else if (this.totalStartgazer >= 1) { + } else if (this.score >= 1) { this.rank = RANK.C; this.topMessage = "First Star"; - this.bottomMessage = "+1"; } } } export class TotalCommitTrophy extends Trophy { - constructor(private totalStartgazer: Number) { + constructor(private score: number) { super(); this.title = "Commit"; - this.setRank(); } setRank() { - if (this.totalStartgazer >= 1000) { + this.bottomMessage = abridgeScore(this.score); + if (this.score >= 1000) { this.rank = RANK.S; this.topMessage = "Super Commiter"; - this.bottomMessage = "+1000"; - } else if (this.totalStartgazer >= 500) { + } else if (this.score >= 500) { this.rank = RANK.A; this.topMessage = "High Commiter"; - this.bottomMessage = "+500"; - } else if (this.totalStartgazer >= 100) { + } else if (this.score >= 100) { this.rank = RANK.B; this.topMessage = "Middle Commiter"; - this.bottomMessage = "+100"; - } else if (this.totalStartgazer >= 1) { + } else if (this.score >= 1) { this.rank = RANK.C; this.topMessage = "First Commit"; - this.bottomMessage = "+1"; } } } export class TotalFollowerTrophy extends Trophy { - constructor(private totalStartgazer: Number) { + constructor(private score: number) { super(); this.title = "Follower"; - this.setRank(); } setRank() { - if (this.totalStartgazer >= 100) { + this.bottomMessage = abridgeScore(this.score); + if (this.score >= 100) { this.rank = RANK.S; this.topMessage = "Celebrity"; - this.bottomMessage = "+100"; - } else if (this.totalStartgazer >= 20) { + } else if (this.score >= 20) { this.rank = RANK.A; this.topMessage = "Famous User"; - this.bottomMessage = "+20"; - } else if (this.totalStartgazer >= 10) { + } else if (this.score >= 10) { this.rank = RANK.B; this.topMessage = "Many Friends"; - this.bottomMessage = "+10"; - } else if (this.totalStartgazer >= 1) { + } else if (this.score >= 1) { this.rank = RANK.C; this.topMessage = "First Friend"; - this.bottomMessage = "+1"; } } } export class TotalIssueTrophy extends Trophy { - constructor(private totalStartgazer: Number) { + constructor(private score: number) { super(); this.title = "Issue"; - this.setRank(); } setRank() { - if (this.totalStartgazer >= 100) { + this.bottomMessage = abridgeScore(this.score); + if (this.score >= 100) { this.rank = RANK.S; this.topMessage = "Super Issuer"; - this.bottomMessage = "+100"; - } else if (this.totalStartgazer >= 20) { + } else if (this.score >= 20) { this.rank = RANK.A; this.topMessage = "High Issuer"; - this.bottomMessage = "+20"; - } else if (this.totalStartgazer >= 10) { + } else if (this.score >= 10) { this.rank = RANK.B; this.topMessage = "Middle Issuer"; - this.bottomMessage = "+10"; - } else if (this.totalStartgazer >= 1) { + } else if (this.score >= 1) { this.rank = RANK.C; this.topMessage = "First Issue"; - this.bottomMessage = "+1"; } } } export class TotalPullRequestTrophy extends Trophy { - constructor(private totalStartgazer: Number) { + constructor(private score: number) { super(); this.title = "PR"; - this.setRank(); } setRank() { - if (this.totalStartgazer >= 100) { + this.bottomMessage = abridgeScore(this.score); + if (this.score >= 100) { this.rank = RANK.S; this.topMessage = "God PR User"; - this.bottomMessage = "+100"; - } else if (this.totalStartgazer >= 20) { + } else if (this.score >= 20) { this.rank = RANK.A; this.topMessage = "High PR User"; - this.bottomMessage = "+20"; - } else if (this.totalStartgazer >= 10) { + } else if (this.score >= 10) { this.rank = RANK.B; this.topMessage = "Many PRs"; - this.bottomMessage = "+10"; - } else if (this.totalStartgazer >= 1) { + } else if (this.score >= 1) { this.rank = RANK.C; this.topMessage = "First PR"; - this.bottomMessage = "+1"; } } } export class TotalRepositoryTrophy extends Trophy { - constructor(private totalStartgazer: Number) { + constructor(private score: number) { super(); this.title = "Repo"; - this.setRank(); } setRank() { - if (this.totalStartgazer >= 100) { + this.bottomMessage = abridgeScore(this.score); + if (this.score >= 100) { this.rank = RANK.S; this.topMessage = "God Repo Creator"; - this.bottomMessage = "+100"; - } else if (this.totalStartgazer >= 20) { + } else if (this.score >= 20) { this.rank = RANK.A; this.topMessage = "High Repo Creator"; - this.bottomMessage = "+20"; - } else if (this.totalStartgazer >= 10) { + } else if (this.score >= 10) { this.rank = RANK.B; this.topMessage = "Many Repo"; - this.bottomMessage = "+10"; - } else if (this.totalStartgazer >= 1) { + } else if (this.score >= 1) { this.rank = RANK.C; this.topMessage = "First Repository"; - this.bottomMessage = "+1"; } } }