A lightweight PHP library for calculating the Wilson Lower Bound Score and Bayesian Approximation weights for sorting algorithms based on user feedback.
Weighted Ratings Library is available via Composer. Just add this line to
your composer.json
file:
"ilicmiljan/weighted-ratings": "^1.0"
or you can run:
composer require ilicmiljan/weighted-ratings
Note that the vendor
folder and the vendor/autoload.php
script are generated
by Composer and they are not part of Weighted Ratings Library.
RatingWeightCalculator::FORMULA_WILSON_LOWER_BOUND
RatingWeightCalculator::FORMULA_BAYESIAN_APPROXIMATION
ausmeNegativeRatingisLessThan
- Number of stars in the rating that are assumed as negative (Default: 3)confidence
- Statistical Confidence used in Formulas (Default: 0.95)
You can use default optional config parameters to calculate weights without instantiating RateLimiterConfig
.
This can be achieved by setting the formula
in the instance of RatingWeightCalculator
.
You can create a new instance of RatingWeightConfig
with all the parameters and pass it to the RatingWeightCalculator
.
The formula for one instance of RatingWeightCalculator
can be set only once. Changing formula in the runtime will throw an exception.
$weightCalculator = new RatingWeightCalculator();
$ratingWeight = $weightCalculator->formula(RatingWeightCalculator::FORMULA_WILSON_LOWER_BOUND)
->calculateWeight([2,4,6,12,24]);
$weightCalculator = new RatingWeightCalculator(
new RatingWeightConfig(RatingWeightCalculator::FORMULA_WILSON_LOWER_BOUND, 5, 0.9)
);
$ratingWeight = $weightCalculator->calculateWeight([2,4,6,12,24,48,92,184,]);
To run Unit Tests inside this library you can use this command:
./vendor/bin/phpunit
- Mutation Score Indicator (MSI): 98%
- Mutation Code Coverage: 100%
- Covered Code MSI: 98%