From 9dc9aa68b8a5febd8dcfad48d086c61881ae2b60 Mon Sep 17 00:00:00 2001 From: shandianchengzi Date: Sun, 8 Sep 2024 01:12:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E5=A2=9E=E5=8A=A0=E6=80=BB?= =?UTF-8?q?=E6=A6=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/src/config.ts | 10 +++-- pages/src/layouts/RankLayout.astro | 68 +++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 11 deletions(-) diff --git a/pages/src/config.ts b/pages/src/config.ts index 970a674..e618006 100644 --- a/pages/src/config.ts +++ b/pages/src/config.ts @@ -44,11 +44,13 @@ export const RANK_LIST: { tabText?: string; hideInTab?: boolean; color?: string; + weight: number; }[] = [ - { status: "translator", text: "翻译王者", tabText: "翻译王者", color: "bg-green-500" }, - { status: "proofreader", text: "校验大佬", tabText: "校验大佬", color: "bg-purple-500" }, - { status: "collector", text: "用心选题", tabText: "用心选题", color: "bg-red-500" }, - { status: "publisher", text: "编辑部业绩", tabText: "编辑部业绩", color: "bg-blue-500" }, + { status: "all", text: "总榜", tabText: "总榜", color: "bg-yellow-500", weight: 0}, + { status: "translator", text: "翻译", tabText: "翻译王者", color: "bg-green-500", weight: 1 }, + { status: "proofreader", text: "校验", tabText: "校验大佬", color: "bg-purple-500" , weight: 1}, + { status: "collector", text: "选题", tabText: "用心选题", color: "bg-red-500" , weight: 0.5}, + { status: "publisher", text: "发布", tabText: "编辑部业绩", color: "bg-blue-500" , weight: 0.8}, ]; export const SOCIALS: SocialObjects = [ diff --git a/pages/src/layouts/RankLayout.astro b/pages/src/layouts/RankLayout.astro index d46e80b..292450a 100644 --- a/pages/src/layouts/RankLayout.astro +++ b/pages/src/layouts/RankLayout.astro @@ -13,11 +13,15 @@ let paginatedPosts = await getCollection("posts", (entry: unknown) => true); // use all the post data to init the nameRank function getRank() { - let nameRank = new Map(); + let nameRank = new Map(); // structure: {"" => Map} let rankResult = new Map(); - // set all nameRank as {"status": Map()}, e.g. {"translator": Map(), "proofreader": Map()} - RANK_LIST.forEach(({status}) => { + let personRank = new Map(); // structure: {"" => {count: number, avatar: string}} + let weightMap: Map = new Map(); // structure: {"" => weight} + + // set all nameRank as {"status": Map()}, e.g. {"translator": Map(), "proofreader": Map()} + RANK_LIST.forEach(({status, weight}) => { nameRank.set(status, new Map()); + weightMap.set(status, weight); }); // init all the tags rank @@ -59,7 +63,21 @@ function getRank() { oneRank.set(rankPerson, { count: 1, avatar: "https://github.com/" + rankPerson + ".png"}); } } + // 计算单人的总分 + oneRank.forEach((partCount: { count: number; avatar: string; }, personName: string) => { + let thisPersonPartCount = partCount.count * (weightMap.get(key) ?? 0); + if (personRank.has(personName)) { + let thisPerson = personRank.get(personName); + thisPerson.count += thisPersonPartCount; + personRank.set(personName, thisPerson); + } else { + personRank.set(personName, { count: thisPersonPartCount, avatar: partCount.avatar}); + } + }); }); + // 更新单人的总分 + nameRank.set("all", personRank); + // sort all the tags and store the result in "rankResult" nameRank.forEach((value, key) => { let oneRank = value; @@ -167,12 +185,12 @@ async function getAllAvatar() {