From 17bdfa7cad0422ae81d06c1c26091077186ab031 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sun, 16 Dec 2012 00:43:15 +0000 Subject: [PATCH] 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 --- libretroshare/src/gxs/rsgxsdataaccess.cc | 5 +- libretroshare/src/retroshare/rsposted.h | 2 +- libretroshare/src/services/p3posted.cc | 107 +++++++++++++++--- .../src/gui/Posted/PostedListDialog.cpp | 27 ++++- .../src/gui/Posted/PostedListDialog.h | 3 +- .../src/gui/Posted/PostedListDialog.ui | 4 +- 6 files changed, 124 insertions(+), 24 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 3a62b7559..f132148d6 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -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; diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index c1ae4b749..ec6aa6f43 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -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; diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index ad4e91534..a207fac04 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -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 msgMeta, Pos scores.push_back(c); } - std::sort(scores.begin(), scores.end(), PostedTopScoreComp); + std::sort(scores.begin(), scores.end(), comp); - std::vector::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: diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.cpp b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp index 68f003739..1c5d1abfe 100644 --- a/retroshare-gui/src/gui/Posted/PostedListDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp @@ -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(); } diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.h b/retroshare-gui/src/gui/Posted/PostedListDialog.h index 78eddc875..e2554dcd1 100644 --- a/retroshare-gui/src/gui/Posted/PostedListDialog.h +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.h @@ -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; diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.ui b/retroshare-gui/src/gui/Posted/PostedListDialog.ui index 32192f8d8..2bddcaefc 100644 --- a/retroshare-gui/src/gui/Posted/PostedListDialog.ui +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.ui @@ -139,7 +139,7 @@ - + Submit Post @@ -220,7 +220,7 @@ 0 0 - 472 + 426 327