mirror of
https://github.com/LemmyNet/joinlemmy-site.git
synced 2024-12-22 19:01:28 +00:00
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
This commit is contained in:
parent
0db6460782
commit
278eff9db8
1 changed files with 9 additions and 11 deletions
|
@ -9,11 +9,12 @@ export class Instances extends Component<any, any> {
|
|||
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<any, any> {
|
|||
}
|
||||
|
||||
// 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<any, any> {
|
|||
.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)
|
||||
|
|
Loading…
Reference in a new issue