Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change of statistics #19

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/courses/all/CourseCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import useCourseCard from "@/composables/courses/all/useCourseCard";
import AvatarContainer from "@/components/users/profile/AvatarContainer";
import { judgeItems, instituteInfo, scoreInfo } from "@/composables/global/useStaticData";
import { averageOf } from "@/composables/global/useArrayUtils";
import { bayesianAverageOf } from "@/composables/global/useArrayUtils";
import { roundScore, enoughDataThreshold } from "@/composables/global/useParseScore"

export default {
Expand Down Expand Up @@ -184,7 +185,14 @@ export default {
let rounded = roundScore(score, this.course["comment_num"]);
this.roundedScore.push(rounded);
}
this.averageScore = averageOf(this.course.score) * 20;
// Bayes statistics inference
// averageScore = (C * m + Σ(ratings)) / (C + N)
// C: Prior Comments Count = 2
// m: Prior Mean Rating = 3.19
// N: Current Comments Count = this.course.score
// By the way, we set a bar that the course must have at least 8 comments
// and the raw average score at 5 to consider this course as a full score course.
this.averageScore = bayesianAverageOf(this.course.score, 4.1, 1, 5) * 20;
},
};
</script>
Expand Down
19 changes: 19 additions & 0 deletions src/composables/global/useArrayUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ export function averageOf(arr) {
return sumOf(arr) / arr.length
}

/**
* Given an array, an prior average and prior count, return the bayesian average of those items.
* @param {Array<any>} arr
* @param {Array<any>} priorAverage
* @param {any} priorCount
* @param {any} fullScoreBar - The number of reviews required to consider the average as 5.
* @returns any - The bayesian average of the numbers in the array.
*/
export function bayesianAverageOf(arr, priorAverage, priorCount, fullScoreBar) {
if (arr.length == 0) {
return 0;
}
if(averageOf(arr) == 5 && arr.length >= fullScoreBar) {
return 5;
}

return (priorCount * priorAverage + sumOf(arr)) / (priorCount + arr.length)
}


/**
* It takes an array of numbers and returns an array of numbers that are the same proportions of the
Expand Down