who to follow working well

This commit is contained in:
Luis Fernando Molina committed 2021-09-10 16:14:14 +02:00
1 parent e4f11d5341
commit 986172f616
10 files changed
+156 -32

No files matched your search

+6 -6
View File
@@ -101,11 +101,11 @@ function newWebApp() {
Test Query User Profiles.
*/
queryMessage = {
queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILES,
queryType: SA.projects.socialTrading.globals.queryTypes.UNFOLLOWED_USER_PROFILES,
emitterUserProfileId: undefined,
initialIndex: 'Last',
initialIndex: SA.projects.socialTrading.globals.queryConstants.INITIAL_INDEX_FIRST,
amountRequested: 3,
direction: 'Past'
direction: SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP
}
query = {
@@ -147,7 +147,7 @@ function newWebApp() {
if (event.target && event.target.nodeName === "BUTTON") {
switch (event.target.action) {
case 'Follow Profile': {
await sendUserProfileEvent(
await sendUserTargetProfileEvent(
event.target.userProfileId,
SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE
)
@@ -164,7 +164,7 @@ function newWebApp() {
break
}
case 'Unfollow Profile': {
await sendUserProfileEvent(
await sendUserTargetProfileEvent(
event.target.userProfileId,
SA.projects.socialTrading.globals.eventTypes.UNFOLLOW_USER_PROFILE
)
@@ -264,7 +264,7 @@ function newWebApp() {
table.setAttribute("class", "profile-to-follow-table")
}
async function sendUserProfileEvent(
async function sendUserTargetProfileEvent(
userProfileId,
eventType
) {
+6
View File
@@ -1339,6 +1339,12 @@
"functionName": "newSocialTradingModulesQueriesUserProfiles",
"fileName": "Queries/UserProfiles.js"
},
{
"name": "Unfollowed User Profiles",
"propertyName": "queriesUnfollowedUserProfiles",
"functionName": "newSocialTradingModulesQueriesUnfollowedUserProfiles",
"fileName": "Queries/UnfollowedUserProfiles.js"
},
{
"name": "Bot Profile Stats",
"propertyName": "queriesBotProfileStats",
@@ -35,7 +35,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
let response = []
switch (thisObject.direction) {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
@@ -43,7 +43,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
}
break
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
@@ -35,7 +35,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
let response = []
switch (thisObject.direction) {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
@@ -43,7 +43,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
}
break
}
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
@@ -0,0 +1,104 @@
exports.newSocialTradingModulesQueriesUnfollowedUserProfiles = function newSocialTradingModulesQueriesUnfollowedUserProfiles() {
/*
This query returns a list of user profiles ordered
by Ranking. It filters out all the profiles that
are already followed by the Emitter User Profile.
*/
let thisObject = {
emitterUserProfile: undefined,
profiles: undefined,
initialIndex: undefined,
amountRequested: undefined,
direction: undefined,
execute: execute,
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
thisObject.profiles = undefined
thisObject.emitterUserProfile = undefined
}
function initialize(queryReceived) {
thisObject.emitterUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId)
if (thisObject.emitterUserProfile === undefined) {
throw ('Emitter User Profile Not Found.')
}
thisObject.profiles = Array.from(
NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID,
x => x[1]
)
thisObject.profiles.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.profiles)
}
function execute() {
let response = []
switch (thisObject.direction) {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: {
let i = thisObject.initialIndex
let foundCount = 0
while (
foundCount < thisObject.amountRequested &&
i < thisObject.profiles.length
) {
let profile = thisObject.profiles[i]
if (
thisObject.emitterUserProfile.following.get(profile.userProfileId) === undefined &&
thisObject.emitterUserProfile.userProfileId !== profile.userProfileId
) {
addToResponse(profile)
foundCount++
}
i++
}
break
}
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: {
let i = thisObject.initialIndex
let foundCount = 0
while (
foundCount < thisObject.amountRequested &&
i >= 0
) {
let profile = thisObject.profiles[i]
if (
thisObject.emitterUserProfile.following.get(profile.userProfileId) === undefined &&
thisObject.emitterUserProfile.userProfileId !== profile.userProfileId
) {
addToResponse(profile)
foundCount++
}
i--
}
break
}
}
return response
function addToResponse(profile) {
let postResponse = {
"userProfileId": profile.userProfileId,
"userProfileHandle": profile.userProfileHandle,
"blockchainAccount": profile.blockchainAccount,
"ranking": profile.ranking,
"followingCount": profile.following.size,
"followersCount": profile.followers.size,
"postsCount": profile.posts.size,
"botsCount": profile.bots.size,
"emitterEventsCount": profile.emitterEventsCount,
"targetEventsCount": profile.targetEventsCount
}
response.push(postResponse)
}
}
}
@@ -5,7 +5,7 @@ exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingMo
and provide them with alternative of who to follow.
*/
let thisObject = {
array: undefined,
profiles: undefined,
initialIndex: undefined,
amountRequested: undefined,
direction: undefined,
@@ -17,18 +17,18 @@ exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingMo
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profiles = undefined
}
function initialize(queryReceived) {
thisObject.array = Array.from(
thisObject.profiles = Array.from(
NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID,
x => x[1]
)
thisObject.array.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1)
thisObject.profiles.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.profiles)
}
@@ -37,19 +37,19 @@ exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingMo
let response = []
switch (thisObject.direction) {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
let profile = thisObject.profiles[i]
if (profile === undefined) { break }
addToResponse(profile)
}
break
}
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
case SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
let profile = thisObject.profiles[i]
if (profile === undefined) { break }
addToResponse(profile)
}
break
}
@@ -34,6 +34,12 @@ exports.newSocialTradingModulesQuery = function newSocialTradingModulesQuery() {
break
}
case SA.projects.socialTrading.globals.queryTypes.UNFOLLOWED_USER_PROFILES: {
thisObject.query = NT.projects.socialTrading.modules.queriesUnfollowedUserProfiles.newSocialTradingModulesQueriesUnfollowedUserProfiles()
thisObject.query.initialize(queryReceived)
break
}
case SA.projects.socialTrading.globals.queryTypes.USER_PROFILE_STATS: {
thisObject.query = NT.projects.socialTrading.modules.queriesUserProfileStats.newSocialTradingModulesQueriesUserProfileStats()
thisObject.query.initialize(queryReceived)
@@ -91,7 +91,12 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU
throw ('Direction Undefined.')
}
if (queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE && queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST) {
if (
queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE &&
queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST &&
queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP &&
queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN
) {
throw ('Direction Not Supported.')
}
@@ -6,7 +6,9 @@ exports.newSocialTradingGlobalsQueryConstants = function () {
MIN_AMOUNT_REQUESTED: 1,
MAX_AMOUNT_REQUESTED: 100,
DIRECTION_FUTURE: 'Future',
DIRECTION_PAST: 'Past'
DIRECTION_PAST: 'Past',
DIRECTION_UP: 'Up',
DIRECTION_Down: 'Down'
}
return thisObject
@@ -2,13 +2,14 @@ exports.newSocialTradingGlobalsQueryTypes = function () {
let thisObject = {
USER_PROFILES: 0,
USER_PROFILE_STATS: 1,
BOT_PROFILE_STATS: 2,
PROFILE_POSTS: 3,
PROFILE_FOLLOWERS: 4,
PROFILE_FOLLOWING: 5,
POST_REPLIES: 6,
EVENTS: 7
UNFOLLOWED_USER_PROFILES: 1,
USER_PROFILE_STATS: 2,
BOT_PROFILE_STATS: 3,
PROFILE_POSTS: 4,
PROFILE_FOLLOWERS: 5,
PROFILE_FOLLOWING: 6,
POST_REPLIES: 7,
EVENTS: 8
}
return thisObject