fixed bug causing uninitialised friend average reputation to be shown

This commit is contained in:
csoler 2015-10-09 18:55:07 -04:00
parent 338fcee865
commit 59d2ca9c3d

View File

@ -864,32 +864,26 @@ int p3GxsReputation::sendReputationRequest(RsPeerId peerid)
float Reputation::updateReputation(uint32_t average_active_friends) float Reputation::updateReputation(uint32_t average_active_friends)
{ {
// the calculation of reputation makes the whole thing // the calculation of reputation makes the whole thing
if(mOwnOpinion == RsReputations::OPINION_NEUTRAL) int friend_total = 0;
{
int friend_total = 0; // accounts for all friends. Neutral opinions count for 1-1=0
// accounts for all friends. Neutral opinions count for 1-1=0 for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
friend_total += it->second - 1;
for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
friend_total += it->second - 1; if(mOpinions.empty()) // includes the case of no friends!
mFriendAverage = 1.0f ;
if(mOpinions.empty()) // includes the case of no friends! else
{ mFriendAverage = 1.0+friend_total / float(std::max(average_active_friends,(uint32_t)mOpinions.size()));
mReputation = 1.0f;
mFriendAverage = 1.0f ; if(mOwnOpinion == RsReputations::OPINION_NEUTRAL)
} mReputation = mFriendAverage ;
else else
{ mReputation = (float)mOwnOpinion ;
mFriendAverage = 1.0+friend_total / float(std::max(average_active_friends,(uint32_t)mOpinions.size()));
mReputation = mFriendAverage ; return float(mOwnOpinion) ;
}
}
else
mReputation = (float)mOwnOpinion ;
return float(mOwnOpinion) ;
} }
void p3GxsReputation::debug_print() void p3GxsReputation::debug_print()