diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 22dfaed3f..83f497582 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -125,6 +125,15 @@ virtual bool submitPost(uint32_t &token, RsPostedPost &post, bool isNew) = 0; virtual bool submitVote(uint32_t &token, RsPostedVote &vote, bool isNew) = 0; virtual bool submitComment(uint32_t &token, RsPostedComment &comment, bool isNew) = 0; + // Special Ranking Request. +virtual bool requestRanking(uint32_t &token, std::string groupId) = 0; +virtual bool getRankedPost(const uint32_t &token, RsPostedPost &post) = 0; + +virtual bool extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments) = 0; + + // exposed for testing... +virtual float calcPostScore(const RsMsgMetaData &meta) = 0; + }; diff --git a/libretroshare/src/services/p3gxsservice.cc b/libretroshare/src/services/p3gxsservice.cc index 0731546ca..68cc08b9d 100644 --- a/libretroshare/src/services/p3gxsservice.cc +++ b/libretroshare/src/services/p3gxsservice.cc @@ -349,6 +349,11 @@ static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData // Exact Flags match required. if ((opts.mStatusMask & opts.mStatusFilter) == (opts.mStatusMask & group.mGroupStatus)) { + std::cerr << "checkGroupFilter() Accepting Group as StatusMatches: "; + std::cerr << " Mask: " << opts.mStatusMask << " StatusFilter: " << opts.mStatusFilter; + std::cerr << " GroupStatus: " << group.mGroupStatus << " GroupId: " << group.mGroupId; + std::cerr << std::endl; + statusMatch = true; } else @@ -371,6 +376,11 @@ static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData // Exact Flags match required. if (opts.mSubscribeFilter & group.mSubscribeFlags) { + std::cerr << "checkGroupFilter() Accepting Group as SubscribeMatches: "; + std::cerr << " SubscribeFilter: " << opts.mSubscribeFilter; + std::cerr << " GroupSubscribeFlags: " << group.mSubscribeFlags << " GroupId: " << group.mGroupId; + std::cerr << std::endl; + subMatch = true; } else @@ -399,6 +409,11 @@ static bool checkMsgFilter(const RsTokReqOptions &opts, const RsMsgMetaData &msg // Exact Flags match required. if ((opts.mStatusMask & opts.mStatusFilter) == (opts.mStatusMask & msg.mMsgStatus)) { + std::cerr << "checkMsgFilter() Accepting Msg as StatusMatches: "; + std::cerr << " Mask: " << opts.mStatusMask << " StatusFilter: " << opts.mStatusFilter; + std::cerr << " MsgStatus: " << msg.mMsgStatus << " MsgId: " << msg.mMsgId; + std::cerr << std::endl; + statusMatch = true; } else diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index bb39c80a6..69db3d537 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -769,8 +769,8 @@ void p3IdService::generateDummyData() } } -#define MAX_RANDOM_GPGIDS 1000 -#define MAX_RANDOM_PSEUDOIDS 5000 +#define MAX_RANDOM_GPGIDS 10 //1000 +#define MAX_RANDOM_PSEUDOIDS 50 //5000 int nFakeGPGs = (RSRandom::random_u32() % MAX_RANDOM_GPGIDS); int nFakePseudoIds = (RSRandom::random_u32() % MAX_RANDOM_PSEUDOIDS); diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index f7ff1d89f..5e3776ee7 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -99,6 +99,7 @@ int p3PostedService::tick() if (doCheck) { + addExtraDummyData(); background_requestGroups(); } @@ -979,8 +980,8 @@ bool p3PostedService::generateDummyData() { #define MAX_GROUPS 10 //100 #define MAX_POSTS 100 //1000 -#define MAX_COMMENTS 100 //10000 -#define MAX_VOTES 100 //10000 +#define MAX_COMMENTS 5000 //10000 +#define MAX_VOTES 10000 //10000 std::list mGroups; std::list::iterator git; @@ -1025,7 +1026,7 @@ bool p3PostedService::generateDummyData() float rnd = RSRandom::random_f32(); if (rnd < 0.1) { - group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN; + group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN | RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; } else if (rnd < 0.3) @@ -1190,19 +1191,67 @@ bool p3PostedService::generateDummyData() for(cit = mComments.begin(); cit != mComments.end(); cit++) { /* pushback */ - mPostedProxy->addComment(*cit); +#define COMMENT_FRAC_FOR_LATER (0.70) + if (RSRandom::random_f32() > COMMENT_FRAC_FOR_LATER) + { + mPostedProxy->addComment(*cit); + } + else + { + mDummyLaterComments.push_back(*cit); + } } for(vit = mVotes.begin(); vit != mVotes.end(); vit++) { /* pushback */ - mPostedProxy->addVote(*vit); + +#define VOTE_FRAC_FOR_LATER (0.70) + if (RSRandom::random_f32() > VOTE_FRAC_FOR_LATER) + { + mPostedProxy->addVote(*vit); + } + else + { + mDummyLaterVotes.push_back(*vit); + } } return true; } +#define EXTRA_COMMENT_ADD (20) +#define EXTRA_VOTE_ADD (50) + +bool p3PostedService::addExtraDummyData() +{ + std::cerr << "p3PostedService::addExtraDummyData()"; + std::cerr << std::endl; + + int i = 0; + + std::list::iterator vit; + std::list::iterator cit; + + for(cit = mDummyLaterComments.begin(); (cit != mDummyLaterComments.end()) && (i < EXTRA_COMMENT_ADD); i++) + { + mPostedProxy->addComment(*cit); + cit = mDummyLaterComments.erase(cit); + } + + i = 0; + for(vit = mDummyLaterVotes.begin(); (vit != mDummyLaterVotes.end()) && (i < EXTRA_VOTE_ADD); i++) + { + mPostedProxy->addVote(*vit); + vit = mDummyLaterVotes.erase(vit); + } + + return true; +} + + + /********************************************************************************************/ /********************************************************************************************/ @@ -1518,7 +1567,7 @@ bool p3PostedService::processPosts() } std::multimap postMap; - std::multimap::iterator mit; + std::multimap::reverse_iterator mit; for(it = postList.begin(); it != postList.end(); it++) { @@ -1536,7 +1585,7 @@ bool p3PostedService::processPosts() RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ unsigned int i = 0; - for(mit = postMap.begin(); (mit != postMap.end()) && (i < mViewStart); mit++, i++) + for(mit = postMap.rbegin(); (mit != postMap.rend()) && (i < mViewStart); mit++, i++) { std::cerr << "p3PostedService::processPosts() Skipping PostId: " << mit->second; std::cerr << " with score: " << mit->first; @@ -1544,7 +1593,7 @@ bool p3PostedService::processPosts() } - for(i = 0; (mit != postMap.end()) && (i < mViewCount); mit++, i++) + for(i = 0; (mit != postMap.rend()) && (i < mViewCount); mit++, i++) { std::cerr << "p3PostedService::processPosts() Adding PostId: " << mit->second; std::cerr << " with score: " << mit->first; @@ -1672,7 +1721,7 @@ bool p3PostedService::background_requestNewMessages() if (!getGroupList(token, groupIds)) { - std::cerr << "p3PostedService::background_requestNewMessages() ERROR"; + std::cerr << "p3PostedService::background_requestNewMessages() ERROR No Group List"; std::cerr << std::endl; background_cleanup(); return false; @@ -1717,7 +1766,7 @@ bool p3PostedService::background_processNewMessages() if (!getMsgSummary(token, newMsgList)) { - std::cerr << "p3PostedService::background_processNewMessages() ERROR"; + std::cerr << "p3PostedService::background_processNewMessages() ERROR No New Msgs"; std::cerr << std::endl; background_cleanup(); return false; @@ -1747,13 +1796,13 @@ bool p3PostedService::background_processNewMessages() /* discard threadheads */ if (it->mParentId.empty()) { - std::cerr << "\tIgnoring ThreadHead"; + std::cerr << "\tIgnoring ThreadHead: " << *it; std::cerr << std::endl; } else if (it->mMsgFlags & RSPOSTED_MSGTYPE_COMMENT) { /* Comments are counted by Thread Id */ - std::cerr << "\tProcessing Comment"; + std::cerr << "\tProcessing Comment: " << *it; std::cerr << std::endl; vit = mBgCommentMap.find(it->mThreadId); @@ -1769,6 +1818,7 @@ bool p3PostedService::background_processNewMessages() std::cerr << "\tThreadId: " << it->mThreadId; std::cerr << " Comment Total: " << mBgCommentMap[it->mThreadId]; + std::cerr << std::endl; } else { @@ -1778,11 +1828,14 @@ bool p3PostedService::background_processNewMessages() std::cerr << std::endl; } } - else if (it->mMsgFlags & RSPOSTED_MSGTYPE_COMMENT) + else if (it->mMsgFlags & RSPOSTED_MSGTYPE_VOTE) { /* Votes are organised by Parent Id, * ie. you can vote for both Posts and Comments */ + std::cerr << "\tProcessing Vote: " << *it; + std::cerr << std::endl; + vit = mBgVoteMap.find(it->mParentId); if (vit == mBgVoteMap.end()) { @@ -1796,6 +1849,7 @@ bool p3PostedService::background_processNewMessages() std::cerr << "\tParentId: " << it->mParentId; std::cerr << " Vote Total: " << mBgVoteMap[it->mParentId]; + std::cerr << std::endl; } else { diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index aa2307480..3466be7c4 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -128,12 +128,12 @@ virtual bool getRankedPost(const uint32_t &token, RsPostedPost &post); // These are exposed for GUI usage. virtual bool encodePostedCache(std::string &str, uint32_t votes, uint32_t comments); virtual bool extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments); +virtual float calcPostScore(const RsMsgMetaData &meta); private: // bool checkRankingRequest(); -float calcPostScore(const RsMsgMetaData &meta); bool processPosts(); // background processing of Votes. @@ -151,7 +151,8 @@ bool background_cleanup(); std::string genRandomId(); -bool generateDummyData(); +bool generateDummyData(); +bool addExtraDummyData(); PostedDataProxy *mPostedProxy; @@ -179,6 +180,10 @@ bool generateDummyData(); std::map mBgVoteMap; // ParentId -> Vote Count. std::map mBgCommentMap; // ThreadId -> Comment Count. + // extra dummy data. + std::list mDummyLaterVotes; + std::list mDummyLaterComments; + };