From 278eff9db877f13bb953f9d7b794726a669d5f39 Mon Sep 17 00:00:00 2001 From: Security-Chief-Odo <87156706+Security-Chief-Odo@users.noreply.github.com> Date: Mon, 17 Jul 2023 06:28:35 -0500 Subject: [PATCH] Change instance sort order - revised weight of member counts (#223) * Changed 'popular' instance sorting to be more evenly distributed, and improve the weighting for user numbers * Ran prettier on prevoiusly comitted code * Ran prettier on prevoiusly comitted code * Modified averageFunc to be a class function instead of const var. Ensured prettier and yarn lint were successfully ran. * Updated variable names and reverted min_monthly_user const * Prettier ran, modified generate_translations.mjs only for formatting corrections * Based on https://github.com/LemmyNet/joinlemmy-site/pull/214#issuecomment-1635522167, revised randomSortOrder to more heavy bias towards popular instances * Retrigger checks pipeline * Ran prettier and adding all modified files that prettier touched --- src/shared/components/instances.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/shared/components/instances.tsx b/src/shared/components/instances.tsx index 5f7bb9f..168f538 100644 --- a/src/shared/components/instances.tsx +++ b/src/shared/components/instances.tsx @@ -9,11 +9,12 @@ export class Instances extends Component { super(props, context); } - biasedRandom(min, max, bias, i) { - // Lets introduce a better bias to random suffle instances list - var rnd = Math.random() * (max - min) + min; - var mix = Math.random() * i; - return rnd * (1 - mix) + bias * mix; + biasedRandom(active_users, avg, max) { + // Lets introduce a better bias to random shuffle instances list + var influence = 1.25; + var rnd = Math.random() * (max / influence) + active_users; + var mix = Math.random() * influence; + return rnd * (1 - mix) + avg * mix; } averageFunc(values: any) { @@ -43,9 +44,8 @@ export class Instances extends Component { } // Use these values for the shuffle - const maxMonthlyUsers = Math.max(...values); - const minMonthlyUsers = Math.min(...values); const avgMonthlyUsers = this.averageFunc(values); + const maxMonthlyUsers = Math.max(...values); let recommended2 = recommended .map(value => ({ value, sort: Math.random() })) @@ -53,15 +53,13 @@ export class Instances extends Component { .map(({ value }) => value); // BIASED sorting for instances, based on the min/max of users_active_month - // weighted to 2/3 of all counts, but more even distribution let remaining2 = remaining .map(i => ({ instance: i, sort: this.biasedRandom( - minMonthlyUsers, - maxMonthlyUsers, + i.site_info.site_view.counts.users_active_month, avgMonthlyUsers, - 0.75, + maxMonthlyUsers, ), })) .sort((a, b) => b.sort - a.sort)