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:
chrisparker126 2012-12-16 00:43:15 +00:00
parent 7935c5547f
commit 17bdfa7cad
6 changed files with 124 additions and 24 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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:

View File

@ -80,7 +80,9 @@ PostedListDialog::PostedListDialog(CommentHolder *commentHolder, QWidget *parent
connect( ui.groupTreeWidget, SIGNAL( treeCurrentItemChanged(QString) ), this, SLOT( changedTopic(QString) ) );
connect(ui.hotSortButton, SIGNAL(clicked()), this, SLOT(getHotRankings()));
connect(ui.hotSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
connect(ui.newSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
connect(ui.topSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
/* create posted tree */
yourTopics = ui.groupTreeWidget->addCategoryItem(tr("Your Topics"), QIcon(IMAGE_FOLDER), true);
@ -89,13 +91,13 @@ PostedListDialog::PostedListDialog(CommentHolder *commentHolder, QWidget *parent
otherTopics = ui.groupTreeWidget->addCategoryItem(tr("Other Topics"), QIcon(IMAGE_FOLDERYELLOW), false);
ui.hotSortButton->setChecked(true);
mSortButton = ui.hotSortButton;
connect( ui.newTopicButton, SIGNAL( clicked() ), this, SLOT( newTopic() ) );
connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refreshTopics()));
connect(ui.submitPostButton, SIGNAL(clicked()), this, SLOT(newPost()));
}
void PostedListDialog::getHotRankings()
void PostedListDialog::getRankings()
{
if(mCurrTopicId.empty())
@ -107,7 +109,21 @@ void PostedListDialog::getHotRankings()
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
uint32_t token;
rsPosted->requestPostRankings(token, RsPosted::BestRankType, mCurrTopicId);
QObject* button = sender();
if(button == ui.hotSortButton)
{
rsPosted->requestPostRankings(token, RsPosted::HotRankType, mCurrTopicId);
}else if(button == ui.topSortButton)
{
rsPosted->requestPostRankings(token, RsPosted::TopRankType, mCurrTopicId);
}else if(button == ui.newSortButton)
{
rsPosted->requestPostRankings(token, RsPosted::NewRankType, mCurrTopicId);
}else{
return;
}
mPostedQueue->queueRequest(token, TOKENREQ_GROUPINFO, RS_TOKREQ_ANSTYPE_DATA, TOKEN_USER_TYPE_POST_RANKINGS);
}
@ -172,6 +188,9 @@ void PostedListDialog::groupListCustomPopupMenu( QPoint /*point*/ )
void PostedListDialog::newPost()
{
if(mCurrTopicId.empty())
return;
PostedCreatePostDialog cp(mPostedQueue, rsPosted, mCurrTopicId, this);
cp.exec();
}

View File

@ -74,7 +74,7 @@ private slots:
void submitVote(const RsGxsGrpMsgIdPair& msgId, bool up);
void getHotRankings();
void getRankings();
private:
@ -133,7 +133,6 @@ private:
QTreeWidgetItem *popularTopics;
QTreeWidgetItem *otherTopics;
QAbstractButton *mSortButton;
bool mThreadLoading;
RsGxsGroupId mCurrTopicId;

View File

@ -139,7 +139,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="newPostButton">
<widget class="QPushButton" name="submitPostButton">
<property name="text">
<string>Submit Post</string>
</property>
@ -220,7 +220,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<width>426</width>
<height>327</height>
</rect>
</property>