mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-06 08:05:18 -04:00
enabled token expiration, 30 seconds
add new, and hot ranking, and fixed top ranking for posts (not comments yet) top ranking decay period set at 4 seconds for testing enabled ranking posts fixed comments generation git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5989 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7935c5547f
commit
17bdfa7cad
6 changed files with 124 additions and 24 deletions
|
@ -297,6 +297,7 @@ void RsGxsDataAccess::storeRequest(GxsRequest* req)
|
|||
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
|
||||
|
||||
req->status = GXS_REQUEST_V2_STATUS_PENDING;
|
||||
req->reqTime = time(NULL);
|
||||
mRequests[req->token] = req;
|
||||
|
||||
return;
|
||||
|
@ -663,7 +664,7 @@ GxsRequest* RsGxsDataAccess::locked_retrieveRequest(const uint32_t& token)
|
|||
return req;
|
||||
}
|
||||
|
||||
#define MAX_REQUEST_AGE 10
|
||||
#define MAX_REQUEST_AGE 30
|
||||
|
||||
void RsGxsDataAccess::processRequests()
|
||||
{
|
||||
|
@ -749,7 +750,7 @@ void RsGxsDataAccess::processRequests()
|
|||
std::cerr << std::endl;
|
||||
toClear.push_back(req->token);
|
||||
}
|
||||
else if (false/*now - req->reqTime > MAX_REQUEST_AGE*/)
|
||||
else if (now - req->reqTime > MAX_REQUEST_AGE)
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::processrequests() Clearing Old Request Token: " << req->token;
|
||||
std::cerr << std::endl;
|
||||
|
|
|
@ -84,7 +84,7 @@ class RsPosted : public RsGxsIfaceImpl
|
|||
{
|
||||
public:
|
||||
|
||||
enum RankType {TopRankType, BestRankType, NewRankType };
|
||||
enum RankType {TopRankType, HotRankType, NewRankType };
|
||||
|
||||
static const uint32_t FLAG_MSGTYPE_POST;
|
||||
static const uint32_t FLAG_MSGTYPE_VOTE;
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
#define NUM_TOPICS_TO_GENERATE 5
|
||||
#define NUM_POSTS_TO_GENERATE 7
|
||||
#define NUM_VOTES_TO_GENERATE 11
|
||||
#define NUM_COMMENTS_TO_GENERATE 1
|
||||
#define NUM_COMMENTS_TO_GENERATE 3
|
||||
|
||||
#define VOTE_UPDATE_PERIOD 5 // 20 seconds
|
||||
#define HOT_PERIOD 4 // 4 secs for testing prob 1 to 2 days in practice
|
||||
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
||||
|
@ -618,10 +619,89 @@ void p3Posted::discardCalc(const uint32_t &token)
|
|||
|
||||
bool PostedTopScoreComp(const PostedScore& i, const PostedScore& j)
|
||||
{
|
||||
// if((i.upVotes -i.downVotes) == (j.upVotes - j.downVotes)){
|
||||
// return i.date > j.date;
|
||||
// }else
|
||||
return (i.upVotes - i.downVotes) > (j.upVotes - j.downVotes);
|
||||
int32_t i_score = (int32_t)i.upVotes - (int32_t)i.downVotes;
|
||||
int32_t j_score = (int32_t)j.upVotes - (int32_t)j.downVotes;
|
||||
|
||||
if(i_score == j_score){
|
||||
return i.date > j.date;
|
||||
}else
|
||||
{
|
||||
return i_score > j_score;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool PostedHotScoreComp(const PostedScore& i, const PostedScore& j)
|
||||
{
|
||||
int32_t i_score = (int32_t)i.upVotes - (int32_t)i.downVotes;
|
||||
int32_t j_score = (int32_t)j.upVotes - (int32_t)j.downVotes;
|
||||
|
||||
time_t now = time(NULL);
|
||||
long long td = now - i.date;
|
||||
|
||||
if(td == 0)
|
||||
{
|
||||
return i.date > j.date;
|
||||
}
|
||||
|
||||
int y;
|
||||
if(i_score > 0)
|
||||
{
|
||||
y = 1;
|
||||
}else if(i_score == 0)
|
||||
{
|
||||
y = 0;
|
||||
}else
|
||||
{
|
||||
y = -1;
|
||||
}
|
||||
|
||||
double z;
|
||||
if(abs(i_score) >= 1)
|
||||
{
|
||||
z = abs(i_score);
|
||||
}
|
||||
else
|
||||
{
|
||||
z = 1;
|
||||
}
|
||||
|
||||
double i_hot_score = log10(z) + ( ((double)(y*td))
|
||||
/ HOT_PERIOD );
|
||||
|
||||
if(j_score > 0)
|
||||
{
|
||||
y = 1;
|
||||
}else if(j_score == 0)
|
||||
{
|
||||
y = 0;
|
||||
}else
|
||||
{
|
||||
y = -1;
|
||||
}
|
||||
|
||||
|
||||
if(abs(j_score) >= 1)
|
||||
{
|
||||
z = abs(j_score);
|
||||
}
|
||||
else
|
||||
{
|
||||
z = 1;
|
||||
}
|
||||
|
||||
td = now - j.date;
|
||||
|
||||
double j_hot_score = log10(z) + ( ((double)(y*td))
|
||||
/ HOT_PERIOD );
|
||||
if(i_hot_score == j_hot_score)
|
||||
{
|
||||
return i.date > j.date;
|
||||
}else
|
||||
{
|
||||
return i_hot_score > j_hot_score;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool PostedNewScoreComp(const PostedScore& i, const PostedScore& j)
|
||||
|
@ -680,7 +760,10 @@ bool p3Posted::completePostedPostCalc(GxsPostedPostRanking *gpp)
|
|||
case NewRankType:
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedNewScoreComp);
|
||||
break;
|
||||
case BestRankType:
|
||||
case HotRankType:
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedHotScoreComp);
|
||||
break;
|
||||
case TopRankType:
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedTopScoreComp);
|
||||
break;
|
||||
default:
|
||||
|
@ -713,15 +796,13 @@ void p3Posted::calcPostedPostRank(const std::vector<RsMsgMetaData > msgMeta, Pos
|
|||
scores.push_back(c);
|
||||
}
|
||||
|
||||
std::sort(scores.begin(), scores.end(), PostedTopScoreComp);
|
||||
std::sort(scores.begin(), scores.end(), comp);
|
||||
|
||||
std::vector<PostedScore>::iterator vit = scores.begin();
|
||||
|
||||
int i = 1;
|
||||
for(; vit != scores.end(); vit++)
|
||||
for(int i = 0; i < scores.size(); i++)
|
||||
{
|
||||
const PostedScore& p = *vit;
|
||||
ranking.insert(std::make_pair(i++, p.msgId));
|
||||
const PostedScore& p = scores[i];
|
||||
ranking.insert(std::make_pair(i+1, p.msgId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -801,7 +882,7 @@ void p3Posted::completePostedCommentRanking(GxsPostedCommentRanking *gpc)
|
|||
|
||||
switch(gpc->rType)
|
||||
{
|
||||
case BestRankType:
|
||||
case HotRankType:
|
||||
calcPostedCommentsRank(msgBranches, remappedMsgMeta, gpc->result, PostedBestScoreComp);
|
||||
break;
|
||||
case TopRankType:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue