Add long time account and acient account Trophy

This commit is contained in:
ryo-ma 2020-08-29 13:30:42 +09:00
parent 636e4437bd
commit 16c87caa4f
5 changed files with 94 additions and 46 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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 =
`<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="90pt" height="90pt" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
<metadata>
@ -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}"
/>
<rect
id="${title}-rank-progress"
@ -69,7 +59,7 @@ export const getNextRankBar = (
rx="1"
opacity="0.7"
height="3.2"
fill="${color}"
fill="${COLORS.NEXT_RANK_BAR}"
/>
`;
};
@ -82,7 +72,7 @@ const getSmallTrophyIcon = (
const leftXPosition = 7;
const rightXPosition = 68;
const getIcon = (x: number) => {
return `<svg x="${x}" y="35" width="65" height="65" viewBox="0 0 30 30" class="bi bi-trophy" fill="${color}" xmlns="http://www.w3.org/2000/svg">
return `<svg x="${x}" y="35" width="65" height="65" viewBox="0 0 30 30" fill="${color}" xmlns="http://www.w3.org/2000/svg">
${icon}
</svg>`;
};
@ -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 = `
<stop offset="0%" stop-color="#777"/>
<stop offset="50%" stop-color="#777"/>
<stop offset="100%" stop-color="#333"/>
<stop offset="0%" stop-color="${COLORS.DEFAULT_RANK_BASE}"/>
<stop offset="50%" stop-color="${COLORS.DEFAULT_RANK_BASE}"/>
<stop offset="100%" stop-color="${COLORS.DEFAULT_RANK_SHADOW}"/>
`;
if (rank === RANK.SECRET) {
rankColor = "fuchsia";
rankColor = COLORS.SECRET_RANK_TEXT;
gradationColor = `
<stop offset="0%" stop-color="red"/>
<stop offset="50%" stop-color="fuchsia"/>
<stop offset="100%" stop-color="blue"/>
<stop offset="0%" stop-color="${COLORS.SECRET_RANK_1}"/>
<stop offset="50%" stop-color="${COLORS.SECRET_RANK_2}"/>
<stop offset="100%" stop-color="${COLORS.SECRET_RANK_3}"/>
`;
} 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 = `
<stop offset="0%" stop-color="${color}"/>
<stop offset="70%" stop-color="${color}"/>
<stop offset="100%" stop-color="${goldShadowColor}"/>
<stop offset="100%" stop-color="${COLORS.S_RANK_SHADOW}"/>
`;
} 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 = `
<stop offset="0%" stop-color="${color}"/>
<stop offset="70%" stop-color="${color}"/>
<stop offset="100%" stop-color="${sliverShadowColor}"/>
<stop offset="100%" stop-color="${COLORS.A_RANK_SHADOW}"/>
`;
} else if (rank === RANK.B) {
color = bronzeColor;
rankColor = bronzeTextColor;
color = COLORS.B_RANK_BASE;
rankColor = COLORS.B_RANK_TEXT;
gradationColor = `
<stop offset="0%" stop-color="${color}"/>
<stop offset="70%" stop-color="${color}"/>
<stop offset="100%" stop-color="${bronzeShadowColor}"/>
<stop offset="100%" stop-color="${COLORS.B_RANK_SHADOW}"/>
`;
}
const icon = `

View file

@ -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 {

View file

@ -1,7 +1,7 @@
import { ServerRequest } from ".././deps.ts";
export function parseParams(req: ServerRequest): URLSearchParams {
const splitedURL = req.url.split("?")
const splitedURL = req.url.split("?");
if (splitedURL.length < 2) {
return new URLSearchParams();
}
@ -13,11 +13,9 @@ export function abridgeScore(score: number): string {
return "unknown";
}
if (Math.abs(score) > 999) {
return (Math.sign(score) * (Math.abs(score) / 1000)).toFixed(1) + "pt"
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 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);