-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Weighted Reaction System 2.0 implementation #91
Conversation
$reaction->getAttributeValue('rate') === $rate Need to use Variant 1$reaction->getRate() === $rate I think it's better stop on this variant because this accessor will be useful for the statistics too. Variant 2$reaction->hasRate($rate) |
Automated DB Schema changes like $ composer require doctrine/dbal |
We can add 3rd property
Use Case 1Send notification to support team leads when user reacted with minimum rate to conversation with support manager. $reactant->isReactedBy($reacter, $reactionType, $rate) It will check if Use Case 2Open access to restricted application area to users who reacted with maximum rate to our post. $reactant->isReactedBy($reacter, null, $rate) It will check if |
Part of #85
To Do
rate
attribute toReaction
modelgetRate
method toReaction
modelweight
attributes type tofloat
getWeight
methods return type tofloat
incrementWeight
methods argument type tofloat
decrementWeight
methods argument type tofloat
love_reactant_reaction_counters.weight
db column type todecimal(13, 2)
love_reactant_reaction_totals.weight
db column type todecimal(13, 2)
love_reactions.weight
db column type todecimal(4, 2)
$rate
argument toreactTo
methodrate
$rate
toReactant::isReactedBy
method$rate
toReactant::isNotReactedBy
method$rate
toReacter::hasReactedTo
method$rate
toReacter::hasNotReactedTo
methodlove_reactions.rate
db column min valuelove_reactions.rate
db column max valueMin\Max Values
Reaction::RATE_MIN = 0.01
Reaction::RATE_MAX = 99.99
ReactionCounter::WEIGHT_MIN = -99999999999.99
ReactionCounter::WEIGHT_MAX = 99999999999.99
ReactionTotal::WEIGHT_MIN = -99999999999.99
ReactionTotal::WEIGHT_MAX = 99999999999.99
I decided not to create constants for
ReactionCounter
&ReactionTotal
weight ranges for now. They are computed automatically and it's nearly to impossible to reach the limits in near future.How did I calculated this decimal value?
If we will take the most popular YouTube video with 40 000 000+ likes multiply this value by 99.99 (RATE_MAX) we will receive ~4 000 000 000 total weight (10 digits). Because decimals are stored using a binary format that packs nine decimal digits into 4 bytes, then we will have 2 packs for integer part (9 + 1) which will require 4 bytes + 1 byte. But +1 digit wouldn't add extra byte because 1-2 digits have same size of 1 byte, so we could start with 11 digits on the integer part and 2 digits on fractional part.
DECIMAL(4, 2)
require2 + 1 = 3 bytes
DECIMAL (13, 2)
require4 + 1 + 1 = 6 bytes
A
decimal
type can store a Maximum of 65 Digits values, with 30 digits after decimal point. This is another one reason why I decided not to add range limits for counters. You are free to modify your database columns and extend or reduce weight range without touching codebase.