Compare commits

..
4 Commits
Author SHA1 Message Date
François Rozet 1afe4189cb Add finer ranking levels 2023-06-01 20:24:21 +02:00
github-actions[bot]andrickstaa e0b3d833b0 refactor: update languages JSON (#2760)
Co-authored-by: rickstaa <rickstaa@users.noreply.github.com>
2023-05-31 13:24:11 +02:00
Alexandr Garbuzov 275c1fc1c7 Show notice about no languages data instead of empty card (#2755)
* Show message about no languages data instead of empty card

* dev

* dev

* dev

* dev

* dev

* dev
2023-05-29 08:45:19 +02:00
Alexandr Garbuzov 73b0a91b7b Improve ukrainian translation of langcard.title (#2756) 2023-05-29 08:43:37 +02:00
9 changed files with 152 additions and 73 deletions
+25 -29
View File
@@ -1,5 +1,10 @@
function expsf(x, lambda = 1) {
return 2 ** (-lambda * x);
function exponential_cdf(x) {
return 1 - 2 ** -x;
}
function log_normal_cdf(x) {
// approximation
return x / (1 + x);
}
/**
@@ -13,7 +18,7 @@ function expsf(x, lambda = 1) {
* @param {number} params.repos Total number of repos.
* @param {number} params.stars The number of stars.
* @param {number} params.followers The number of followers.
* @returns {{level: string, score: number}}} The users rank.
* @returns {{level: string, percentile: number}}} The users rank.
*/
function calculateRank({
all_commits,
@@ -24,15 +29,15 @@ function calculateRank({
stars,
followers,
}) {
const COMMITS_MEAN = all_commits ? 1000 : 250,
const COMMITS_MEDIAN = all_commits ? 1000 : 250,
COMMITS_WEIGHT = 2;
const PRS_MEAN = 50,
const PRS_MEDIAN = 50,
PRS_WEIGHT = 3;
const ISSUES_MEAN = 25,
const ISSUES_MEDIAN = 25,
ISSUES_WEIGHT = 1;
const STARS_MEAN = 250,
const STARS_MEDIAN = 50,
STARS_WEIGHT = 4;
const FOLLOWERS_MEAN = 25,
const FOLLOWERS_MEDIAN = 10,
FOLLOWERS_WEIGHT = 1;
const TOTAL_WEIGHT =
@@ -42,30 +47,21 @@ function calculateRank({
STARS_WEIGHT +
FOLLOWERS_WEIGHT;
const THRESHOLDS = [1, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100];
const LEVELS = ["S", "A+", "A", "A-", "B+", "B", "B-", "C+", "C"];
const rank =
(COMMITS_WEIGHT * expsf(commits, 1 / COMMITS_MEAN) +
PRS_WEIGHT * expsf(prs, 1 / PRS_MEAN) +
ISSUES_WEIGHT * expsf(issues, 1 / ISSUES_MEAN) +
STARS_WEIGHT * expsf(stars, 1 / STARS_MEAN) +
FOLLOWERS_WEIGHT * expsf(followers, 1 / FOLLOWERS_MEAN)) /
TOTAL_WEIGHT;
1 -
(COMMITS_WEIGHT * exponential_cdf(commits / COMMITS_MEDIAN) +
PRS_WEIGHT * exponential_cdf(prs / PRS_MEDIAN) +
ISSUES_WEIGHT * exponential_cdf(issues / ISSUES_MEDIAN) +
STARS_WEIGHT * log_normal_cdf(stars / STARS_MEDIAN) +
FOLLOWERS_WEIGHT * log_normal_cdf(followers / FOLLOWERS_MEDIAN)) /
TOTAL_WEIGHT;
const RANK_S_PLUS = 0.025;
const RANK_S = 0.1;
const RANK_A_PLUS = 0.25;
const RANK_A = 0.5;
const RANK_B_PLUS = 0.75;
const level = LEVELS[THRESHOLDS.findIndex((t) => rank * 100 <= t)];
const level = (() => {
if (rank <= RANK_S_PLUS) return "S+";
if (rank <= RANK_S) return "S";
if (rank <= RANK_A_PLUS) return "A+";
if (rank <= RANK_A) return "A";
if (rank <= RANK_B_PLUS) return "B+";
return "B";
})();
return { level, score: rank * 100 };
return { level: level, percentile: rank * 100 };
}
export { calculateRank };
+2 -3
View File
@@ -209,9 +209,8 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
hide_rank ? 0 : 150,
);
// the better user's score the the rank will be closer to zero so
// subtracting 100 to get the progress in 100%
const progress = 100 - rank.score;
// the lower the user's percentile the better
const progress = 100 - rank.percentile;
const cssStyles = getStyles({
titleColor,
ringColor,
+40 -11
View File
@@ -17,6 +17,7 @@ const MIN_CARD_WIDTH = 280;
const DEFAULT_LANGS_COUNT = 5;
const DEFAULT_LANG_COLOR = "#858585";
const CARD_PADDING = 25;
const COMPACT_LAYOUT_BASE_HEIGHT = 90;
/**
* @typedef {import("../fetchers/types").Lang} Lang
@@ -101,7 +102,7 @@ const getCircleLength = (radius) => {
* @returns {number} Card height.
*/
const calculateCompactLayoutHeight = (totalLangs) => {
return 90 + Math.round(totalLangs / 2) * 25;
return COMPACT_LAYOUT_BASE_HEIGHT + Math.round(totalLangs / 2) * 25;
};
/**
@@ -654,6 +655,19 @@ const renderDonutLayout = (langs, width, totalLanguageSize) => {
`;
};
/**
* Creates the no coding activity SVG node.
*
* @param {{color: string, text: string, layout: import("./types").TopLangOptions["layout"]}} The function prop
*/
const noLanguagesDataNode = ({ color, text, layout }) => {
return `
<text x="${
layout === "pie" || layout === "donut-vertical" ? CARD_PADDING : 0
}" y="11" class="stat bold" fill="${color}">${text}</text>
`;
};
/**
* Renders card that display user's most frequently used programming languages.
*
@@ -699,8 +713,24 @@ const renderTopLanguages = (topLangs, options = {}) => {
: card_width;
let height = calculateNormalLayoutHeight(langs.length);
// returns theme based colors with proper overrides and defaults
const colors = getCardColors({
title_color,
text_color,
bg_color,
border_color,
theme,
});
let finalLayout = "";
if (layout === "pie") {
if (langs.length === 0) {
height = COMPACT_LAYOUT_BASE_HEIGHT;
finalLayout = noLanguagesDataNode({
color: colors.textColor,
text: i18n.t("langcard.nodata"),
layout,
});
} else if (layout === "pie") {
height = calculatePieLayoutHeight(langs.length);
finalLayout = renderPieLayout(langs, totalLanguageSize);
} else if (layout === "donut-vertical") {
@@ -724,15 +754,6 @@ const renderTopLanguages = (topLangs, options = {}) => {
finalLayout = renderNormalLayout(langs, width, totalLanguageSize);
}
// returns theme based colors with proper overrides and defaults
const colors = getCardColors({
title_color,
text_color,
bg_color,
border_color,
theme,
});
const card = new Card({
customTitle: custom_title,
defaultTitle: i18n.t("langcard.title"),
@@ -764,6 +785,14 @@ const renderTopLanguages = (topLangs, options = {}) => {
width: 100%;
}
}
.stat {
font: 600 14px 'Segoe UI', Ubuntu, "Helvetica Neue", Sans-Serif; fill: ${colors.textColor};
}
@supports(-moz-appearance: auto) {
/* Selector detects Firefox */
.stat { font-size:12px; }
}
.bold { font-weight: 700 }
.lang-name {
font: 400 11px "Segoe UI", Ubuntu, Sans-Serif;
fill: ${colors.textColor};
+9 -1
View File
@@ -106,6 +106,7 @@
"Cypher": "#34c0eb",
"Cython": "#fedf5b",
"D": "#ba595e",
"D2": "#526ee8",
"DM": "#447265",
"Dafny": "#FFEC25",
"Darcs Patch": "#8eff23",
@@ -185,6 +186,7 @@
"Go": "#00ADD8",
"Go Checksums": "#00ADD8",
"Go Module": "#00ADD8",
"Go Workspace": "#00ADD8",
"Godot Resource": "#355570",
"Golo": "#88562A",
"Gosu": "#82937f",
@@ -284,6 +286,7 @@
"Lua": "#000080",
"MATLAB": "#e16737",
"MAXScript": "#00a6a6",
"MDX": "#fcb32c",
"MLIR": "#5EC8DB",
"MQL4": "#62A8D6",
"MQL5": "#4A76B8",
@@ -330,11 +333,12 @@
"Nu": "#c9df40",
"NumPy": "#9C8AF9",
"Nunjucks": "#3d8137",
"Nushell": "#4E9906",
"OASv2-json": "#85ea2d",
"OASv2-yaml": "#85ea2d",
"OASv3-json": "#85ea2d",
"OASv3-yaml": "#85ea2d",
"OCaml": "#3be133",
"OCaml": "#ef7a08",
"ObjectScript": "#424893",
"Objective-C": "#438eff",
"Objective-C++": "#6866fb",
@@ -360,6 +364,7 @@
"PLSQL": "#dad8d8",
"PLpgSQL": "#336790",
"POV-Ray SDL": "#6bac65",
"Pact": "#F7A8B8",
"Pan": "#cc0000",
"Papyrus": "#6600cc",
"Parrot": "#f3ca0a",
@@ -398,6 +403,7 @@
"Quake": "#882233",
"R": "#198CE7",
"RAML": "#77d9fb",
"RBS": "#701516",
"RDoc": "#701516",
"REXX": "#d90e09",
"RMarkdown": "#198ce7",
@@ -472,6 +478,7 @@
"Swift": "#F05138",
"SystemVerilog": "#DAE1C2",
"TI Program": "#A0AA87",
"TL-Verilog": "#C40023",
"TLA": "#4b0079",
"TOML": "#9c4221",
"TSQL": "#e38c00",
@@ -512,6 +519,7 @@
"Vyper": "#2980b9",
"Web Ontology Language": "#5b70bd",
"WebAssembly": "#04133b",
"WebAssembly Interface Type": "#6250e7",
"Whiley": "#d5c397",
"Wikitext": "#fc5757",
"Windows Registry Entries": "#52d5ff",
+1 -1
View File
@@ -192,7 +192,7 @@ const fetchStats = async (
totalIssues: 0,
totalStars: 0,
contributedTo: 0,
rank: { level: "B", score: 0 },
rank: { level: "C", percentile: 100 },
};
let res = await statsFetcher(username);
+1 -1
View File
@@ -22,7 +22,7 @@ export type StatsData = {
totalIssues: number;
totalStars: number;
contributedTo: number;
rank: { level: string; score: number };
rank: { level: string; percentile: number };
};
export type Lang = {
+31 -1
View File
@@ -283,7 +283,7 @@ const langCardLocales = {
np: "अधिक प्रयोग गरिएको भाषाहरू",
el: "Οι περισσότερο χρησιμοποιούμενες γλώσσες",
ru: "Наиболее часто используемые языки",
"uk-ua": "Найбільш часто використовувані мови",
"uk-ua": "Найчастіше використовувані мови",
id: "Bahasa Yang Paling Banyak Digunakan",
ml: "കൂടുതൽ ഉപയോഗിച്ച ഭാഷകൾ",
my: "Bahasa Paling Digunakan",
@@ -293,6 +293,36 @@ const langCardLocales = {
vi: "Ngôn Ngữ Thường Sử Dụng",
se: "Mest använda språken",
},
"langcard.nodata": {
ar: "لا توجد بيانات لغات.",
cn: "沒有語言數據。",
"zh-tw": "沒有語言數據。",
cs: "Žádné jazykové údaje.",
de: "Keine Sprachdaten.",
bn: "কোন ভাষার ডেটা নেই।",
en: "No languages data.",
es: "Sin datos de idiomas.",
fr: "Aucune donnée sur les langues.",
hu: "Nincsenek nyelvi adatok.",
it: "Nessun dato sulle lingue.",
ja: "言語データがありません。",
kr: "언어 데이터가 없습니다.",
nl: "Ingen sprogdata.",
"pt-pt": "Sem dados de idiomas.",
"pt-br": "Sem dados de idiomas.",
np: "कुनै भाषा डाटा छैन।",
el: "Δεν υπάρχουν δεδομένα γλωσσών.",
ru: "Нет данных о языках.",
"uk-ua": "Немає даних про мови.",
id: "Tidak ada data bahasa.",
ml: "ഭാഷാ ഡാറ്റയില്ല.",
my: "Tiada data bahasa.",
sk: "Žiadne údaje o jazykoch.",
tr: "Dil verisi yok.",
pl: "Brak danych dotyczących języków.",
vi: "Không có dữ liệu ngôn ngữ.",
se: "Inga språkdata.",
},
};
const wakatimeCardLocales = {
+39 -25
View File
@@ -2,7 +2,7 @@ import "@testing-library/jest-dom";
import { calculateRank } from "../src/calculateRank.js";
describe("Test calculateRank", () => {
it("new user gets B rank", () => {
it("new user gets C rank", () => {
expect(
calculateRank({
all_commits: false,
@@ -13,10 +13,24 @@ describe("Test calculateRank", () => {
stars: 0,
followers: 0,
}),
).toStrictEqual({ level: "B", score: 100 });
).toStrictEqual({ level: "C", percentile: 100 });
});
it("average user gets A rank", () => {
it("beginner user gets B- rank", () => {
expect(
calculateRank({
all_commits: false,
commits: 125,
prs: 25,
issues: 10,
repos: 0,
stars: 25,
followers: 5,
}),
).toStrictEqual({ level: "B-", percentile: 69.333868386557 });
});
it("median user gets B+ rank", () => {
expect(
calculateRank({
all_commits: false,
@@ -24,13 +38,13 @@ describe("Test calculateRank", () => {
prs: 50,
issues: 25,
repos: 0,
stars: 250,
followers: 25,
stars: 50,
followers: 10,
}),
).toStrictEqual({ level: "A", score: 50 });
).toStrictEqual({ level: "B+", percentile: 50 });
});
it("average user gets A rank (include_all_commits)", () => {
it("average user gets B+ rank (include_all_commits)", () => {
expect(
calculateRank({
all_commits: true,
@@ -38,13 +52,13 @@ describe("Test calculateRank", () => {
prs: 50,
issues: 25,
repos: 0,
stars: 250,
followers: 25,
stars: 50,
followers: 10,
}),
).toStrictEqual({ level: "A", score: 50 });
).toStrictEqual({ level: "B+", percentile: 50 });
});
it("more than average user gets A+ rank", () => {
it("advanced user gets A rank", () => {
expect(
calculateRank({
all_commits: false,
@@ -52,13 +66,13 @@ describe("Test calculateRank", () => {
prs: 100,
issues: 50,
repos: 0,
stars: 500,
followers: 50,
stars: 200,
followers: 40,
}),
).toStrictEqual({ level: "A+", score: 25 });
).toStrictEqual({ level: "A", percentile: 22.72727272727273 });
});
it("expert user gets S rank", () => {
it("expert user gets A+ rank", () => {
expect(
calculateRank({
all_commits: false,
@@ -66,23 +80,23 @@ describe("Test calculateRank", () => {
prs: 200,
issues: 100,
repos: 0,
stars: 1000,
followers: 100,
stars: 800,
followers: 160,
}),
).toStrictEqual({ level: "S", score: 6.25 });
).toStrictEqual({ level: "A+", percentile: 6.082887700534744 });
});
it("ezyang gets S+ rank", () => {
it("sindresorhus gets S rank", () => {
expect(
calculateRank({
all_commits: false,
commits: 1000,
prs: 4000,
issues: 2000,
commits: 1300,
prs: 1500,
issues: 4500,
repos: 0,
stars: 5000,
followers: 2000,
stars: 600000,
followers: 50000,
}),
).toStrictEqual({ level: "S+", score: 1.1363983154296875 });
).toStrictEqual({ level: "S", percentile: 0.49947889605312934 });
});
});
+4 -1
View File
@@ -20,7 +20,10 @@ const STATS_DATA = {
totalIssues: 1,
totalStars: 1,
contributedTo: 1,
rank: { level: "B", score: 98.50610674501908 },
rank: {
level: "A+",
score: 50.88831151384285,
},
};
const LANGS_DATA = {