mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-06 21:34:22 -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 *****/
|
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
|
||||||
|
|
||||||
req->status = GXS_REQUEST_V2_STATUS_PENDING;
|
req->status = GXS_REQUEST_V2_STATUS_PENDING;
|
||||||
|
req->reqTime = time(NULL);
|
||||||
mRequests[req->token] = req;
|
mRequests[req->token] = req;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -663,7 +664,7 @@ GxsRequest* RsGxsDataAccess::locked_retrieveRequest(const uint32_t& token)
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_REQUEST_AGE 10
|
#define MAX_REQUEST_AGE 30
|
||||||
|
|
||||||
void RsGxsDataAccess::processRequests()
|
void RsGxsDataAccess::processRequests()
|
||||||
{
|
{
|
||||||
|
@ -749,7 +750,7 @@ void RsGxsDataAccess::processRequests()
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
toClear.push_back(req->token);
|
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 << "RsGxsDataAccess::processrequests() Clearing Old Request Token: " << req->token;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
|
@ -84,7 +84,7 @@ class RsPosted : public RsGxsIfaceImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum RankType {TopRankType, BestRankType, NewRankType };
|
enum RankType {TopRankType, HotRankType, NewRankType };
|
||||||
|
|
||||||
static const uint32_t FLAG_MSGTYPE_POST;
|
static const uint32_t FLAG_MSGTYPE_POST;
|
||||||
static const uint32_t FLAG_MSGTYPE_VOTE;
|
static const uint32_t FLAG_MSGTYPE_VOTE;
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
#define NUM_TOPICS_TO_GENERATE 5
|
#define NUM_TOPICS_TO_GENERATE 5
|
||||||
#define NUM_POSTS_TO_GENERATE 7
|
#define NUM_POSTS_TO_GENERATE 7
|
||||||
#define NUM_VOTES_TO_GENERATE 11
|
#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 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_COMMENT = 0x0001;
|
||||||
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
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)
|
bool PostedTopScoreComp(const PostedScore& i, const PostedScore& j)
|
||||||
{
|
{
|
||||||
// if((i.upVotes -i.downVotes) == (j.upVotes - j.downVotes)){
|
int32_t i_score = (int32_t)i.upVotes - (int32_t)i.downVotes;
|
||||||
// return i.date > j.date;
|
int32_t j_score = (int32_t)j.upVotes - (int32_t)j.downVotes;
|
||||||
// }else
|
|
||||||
return (i.upVotes - i.downVotes) > (j.upVotes - 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)
|
bool PostedNewScoreComp(const PostedScore& i, const PostedScore& j)
|
||||||
|
@ -680,7 +760,10 @@ bool p3Posted::completePostedPostCalc(GxsPostedPostRanking *gpp)
|
||||||
case NewRankType:
|
case NewRankType:
|
||||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedNewScoreComp);
|
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedNewScoreComp);
|
||||||
break;
|
break;
|
||||||
case BestRankType:
|
case HotRankType:
|
||||||
|
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedHotScoreComp);
|
||||||
|
break;
|
||||||
|
case TopRankType:
|
||||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedTopScoreComp);
|
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedTopScoreComp);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -713,15 +796,13 @@ void p3Posted::calcPostedPostRank(const std::vector<RsMsgMetaData > msgMeta, Pos
|
||||||
scores.push_back(c);
|
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(int i = 0; i < scores.size(); i++)
|
||||||
for(; vit != scores.end(); vit++)
|
|
||||||
{
|
{
|
||||||
const PostedScore& p = *vit;
|
const PostedScore& p = scores[i];
|
||||||
ranking.insert(std::make_pair(i++, p.msgId));
|
ranking.insert(std::make_pair(i+1, p.msgId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -801,7 +882,7 @@ void p3Posted::completePostedCommentRanking(GxsPostedCommentRanking *gpc)
|
||||||
|
|
||||||
switch(gpc->rType)
|
switch(gpc->rType)
|
||||||
{
|
{
|
||||||
case BestRankType:
|
case HotRankType:
|
||||||
calcPostedCommentsRank(msgBranches, remappedMsgMeta, gpc->result, PostedBestScoreComp);
|
calcPostedCommentsRank(msgBranches, remappedMsgMeta, gpc->result, PostedBestScoreComp);
|
||||||
break;
|
break;
|
||||||
case TopRankType:
|
case TopRankType:
|
||||||
|
|
|
@ -80,7 +80,9 @@ PostedListDialog::PostedListDialog(CommentHolder *commentHolder, QWidget *parent
|
||||||
|
|
||||||
connect( ui.groupTreeWidget, SIGNAL( treeCurrentItemChanged(QString) ), this, SLOT( changedTopic(QString) ) );
|
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 */
|
/* create posted tree */
|
||||||
yourTopics = ui.groupTreeWidget->addCategoryItem(tr("Your Topics"), QIcon(IMAGE_FOLDER), true);
|
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);
|
otherTopics = ui.groupTreeWidget->addCategoryItem(tr("Other Topics"), QIcon(IMAGE_FOLDERYELLOW), false);
|
||||||
|
|
||||||
ui.hotSortButton->setChecked(true);
|
ui.hotSortButton->setChecked(true);
|
||||||
mSortButton = ui.hotSortButton;
|
|
||||||
|
|
||||||
connect( ui.newTopicButton, SIGNAL( clicked() ), this, SLOT( newTopic() ) );
|
connect( ui.newTopicButton, SIGNAL( clicked() ), this, SLOT( newTopic() ) );
|
||||||
connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refreshTopics()));
|
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())
|
if(mCurrTopicId.empty())
|
||||||
|
@ -107,7 +109,21 @@ void PostedListDialog::getHotRankings()
|
||||||
RsTokReqOptions opts;
|
RsTokReqOptions opts;
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||||
uint32_t token;
|
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);
|
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()
|
void PostedListDialog::newPost()
|
||||||
{
|
{
|
||||||
|
if(mCurrTopicId.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
PostedCreatePostDialog cp(mPostedQueue, rsPosted, mCurrTopicId, this);
|
PostedCreatePostDialog cp(mPostedQueue, rsPosted, mCurrTopicId, this);
|
||||||
cp.exec();
|
cp.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ private slots:
|
||||||
|
|
||||||
void submitVote(const RsGxsGrpMsgIdPair& msgId, bool up);
|
void submitVote(const RsGxsGrpMsgIdPair& msgId, bool up);
|
||||||
|
|
||||||
void getHotRankings();
|
void getRankings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -133,7 +133,6 @@ private:
|
||||||
QTreeWidgetItem *popularTopics;
|
QTreeWidgetItem *popularTopics;
|
||||||
QTreeWidgetItem *otherTopics;
|
QTreeWidgetItem *otherTopics;
|
||||||
|
|
||||||
QAbstractButton *mSortButton;
|
|
||||||
|
|
||||||
bool mThreadLoading;
|
bool mThreadLoading;
|
||||||
RsGxsGroupId mCurrTopicId;
|
RsGxsGroupId mCurrTopicId;
|
||||||
|
|
|
@ -139,7 +139,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QPushButton" name="newPostButton">
|
<widget class="QPushButton" name="submitPostButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Submit Post</string>
|
<string>Submit Post</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -220,7 +220,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>472</width>
|
<width>426</width>
|
||||||
<height>327</height>
|
<height>327</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue