Superalgos Network: Query User Profiles debugged

This commit is contained in:
Luis Fernando Molina committed 2021-09-03 12:23:42 +02:00
1 parent 2645df775e
commit 67ec986422
13 files changed
+266 -227

No files matched your search

@@ -35,23 +35,23 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
return response
}
if (messageHeader.messageType === undefined) {
if (messageHeader.requestType === undefined) {
let response = {
result: 'Error',
message: 'Client Interface messageType Not Provided.'
message: 'Client Interface requestType Not Provided.'
}
return response
}
if (messageHeader.messageType !== 'Event' && messageHeader.messageType !== 'Query') {
if (messageHeader.requestType !== 'Event' && messageHeader.requestType !== 'Query') {
let response = {
result: 'Error',
message: 'Client Interface messageType Not Supported.'
message: 'Client Interface requestType Not Supported.'
}
return response
}
switch (messageHeader.messageType) {
switch (messageHeader.requestType) {
case 'Event': {
return await eventReceived(messageHeader.eventMessage, userProfile)
}
@@ -190,9 +190,15 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
Here we will process the query. This does not change the state of the Social Graph.
*/
try {
let query = NT.projects.socialTrading.modules.queriesQuery.newSocialTradingModulesQuery()
let query = NT.projects.socialTrading.modules.query.newSocialTradingModulesQuery()
query.initialize(queryReceived)
return query.execute()
let response = {
result: 'Ok',
message: 'Client Interface Query Processed.',
data: query.execute()
}
return response
} catch (err) {
/*
@@ -200,7 +206,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
*/
let response = {
result: 'Error',
message: 'Client Interface ' + err.message
message: err.message
}
return response
}
@@ -21,8 +21,8 @@ exports.newSocialTradingModulesQueriesEvents = function newSocialTradingModulesQ
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, NT.memory.arrays.EVENTS)
}
@@ -8,6 +8,7 @@ exports.newSocialTradingModulesQueriesPostReplies = function newSocialTradingMod
of a certain post, with all its replies.
*/
let thisObject = {
array: undefined,
profile: undefined,
post: undefined,
initialIndex: undefined,
@@ -21,27 +22,30 @@ exports.newSocialTradingModulesQueriesPostReplies = function newSocialTradingMod
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
thisObject.post = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.postValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.post.replies)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.postValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.post.replies)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (post === undefined) { break }
addToResponse(arrayItem)
}
@@ -49,7 +53,7 @@ exports.newSocialTradingModulesQueriesPostReplies = function newSocialTradingMod
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (post === undefined) { break }
addToResponse(arrayItem)
}
@@ -4,6 +4,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
all the User or Bot profiles that are following a certain User or Bot profile.
*/
let thisObject = {
array: undefined,
profile: undefined,
initialIndex: undefined,
amountRequested: undefined,
@@ -16,25 +17,27 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.profile.followers)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.profile.followers)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -42,7 +45,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -4,6 +4,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
all the User or Bot profiles that are being followed by a certain User or Bot profile.
*/
let thisObject = {
array: undefined,
profile: undefined,
initialIndex: undefined,
amountRequested: undefined,
@@ -16,25 +17,27 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.profile.following)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.profile.following)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -42,7 +45,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -8,6 +8,7 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
with all of its posts.
*/
let thisObject = {
array: undefined,
profile: undefined,
initialIndex: undefined,
amountRequested: undefined,
@@ -20,24 +21,26 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.profile.posts)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.profile.posts)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -45,7 +48,7 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -1,10 +1,11 @@
exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradingModulesQueriesUserProfileStats() {
exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingModulesQueriesUserProfiles() {
/*
This query returns a list of user profiles ordered
by Ranking. It is useful to bootstrap new users
and provide them with alternative of who to follow.
*/
let thisObject = {
array: undefined,
initialIndex: undefined,
amountRequested: undefined,
direction: undefined,
@@ -16,24 +17,29 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
return thisObject
function finalize() {
thisObject.array = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = 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)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID)
array.sort((a, b) => (a["ranking"].toLowerCase() > b["ranking"].toLowerCase()) ? 1 : -1)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -41,7 +47,7 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
+13 -19
View File
@@ -40,67 +40,61 @@ exports.newSocialTradingModulesQuery = function newSocialTradingModulesQuery() {
thisObject.queryType = queryReceived.queryType
switch (thisObject.queryType) {
case QUERY_TYPES.USER_PROFILES: {
thisObject.query = NT.projects.socialTrading.modules.queriesUserProfiles.newSocialTradingModulesQueriesUserProfiles()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.USER_PROFILE_STATS: {
thisObject.query = NT.projects.socialTrading.modules.queriesUserProfileStats.newSocialTradingModulesQueriesUserProfileStats()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.BOT_PROFILE_STATS: {
thisObject.query = NT.projects.socialTrading.modules.queriesBotProfileStats.newSocialTradingModulesQueriesBotProfileStats()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.PROFILE_POSTS: {
thisObject.query = NT.projects.socialTrading.modules.queriesProfilePosts.newSocialTradingModulesQueriesProfilePosts()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.POST_REPLIES: {
thisObject.query = NT.projects.socialTrading.modules.queriesPostReplies.newSocialTradingModulesQueriesPostReplies()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.PROFILE_FOLLOWERS: {
thisObject.query = NT.projects.socialTrading.modules.queriesProfileFollowers.newSocialTradingModulesQueriesProfileFollowers()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.PROFILE_FOLLOWING: {
thisObject.query = NT.projects.socialTrading.modules.queriesProfileFollowing.newSocialTradingModulesQueriesProfileFollowing()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.maps.EVENTS: {
thisObject.query = NT.projects.socialTrading.modules.queriesEvents.newSocialTradingModulesQueriesEvents()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
default: throw('Query Type Not Supported.')
default: throw ('Query Type Not Supported.')
}
}
function execute() {
return thisObject.query.execute()
let response = thisObject.query.execute()
thisObject.query.finalize()
return response
}
}
@@ -43,7 +43,7 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU
}
}
function arrayValidations(queryReceived, thisObject) {
function arrayValidations(queryReceived, thisObject, array) {
/*
Validate Initial Index
*/
@@ -52,7 +52,7 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU
}
if (queryReceived.initialIndex === NT.projects.socialTrading.globals.queryConstants.INITIAL_INDEX_LAST) {
queryReceived.initialIndex = thisObject.profile.posts.length - 1
queryReceived.initialIndex = array.length - 1
}
if (queryReceived.initialIndex === NT.projects.socialTrading.globals.queryConstants.INITIAL_INDEX_FIRST) {
@@ -82,6 +82,8 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU
if (queryReceived.amountRequested > NT.projects.socialTrading.globals.queryConstants.MAX_AMOUNT_REQUESTED) {
throw ('Amount Requested Above Max.')
}
thisObject.amountRequested = queryReceived.amountRequested
/*
Validate Direction
*/