From 4a202b909aeed3bea40120825045a2864e452fa1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 28 Aug 2021 20:30:40 +0200 Subject: [PATCH] Superalgos Network: Bot Profile Stats Implemented --- Network/NetwokNode.js | 3 +- Network/Queries/BotProfileStats.js | 52 +++++++++++++++++++ Network/Queries/Events.js | 14 ++--- .../{ProfileStats.js => UserProfileStats.js} | 6 +-- Network/Query.js | 24 ++++++--- Network/userProfile.js | 2 +- 6 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 Network/Queries/BotProfileStats.js rename Network/Queries/{ProfileStats.js => UserProfileStats.js} (89%) diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index fa5c8f701..5db39e9a1 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -20,7 +20,8 @@ global.NT = { EVENT: require('./Event.js'), POST: require('./Post.js'), QUERY: require('./Query.js'), - QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'), + QUERY_USER_PROFILE_STATS: require('./Queries/UserProfileStats.js'), + QUERY_BOT_PROFILE_STATS: require('./Queries/BotProfileStats.js'), QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'), QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'), QUERY_EVENTS: require('./Queries/Events.js') diff --git a/Network/Queries/BotProfileStats.js b/Network/Queries/BotProfileStats.js new file mode 100644 index 000000000..de05fea1a --- /dev/null +++ b/Network/Queries/BotProfileStats.js @@ -0,0 +1,52 @@ +exports.newBotProfileStats = function newBotProfileStats() { + + let thisObject = { + profile: undefined, + execute: execute, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + thisObject.profile = undefined + } + + function initialize(queryReceived) { + /* + Validate Bot Profile + */ + let userProfile + if (queryReceived.targetBotProfileId !== undefined) { + userProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + } else { + userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileId) + } + + if (userProfile === undefined) { + throw ('Target User Profile Not Found.') + } + /* + Validate Bot Profile + */ + thisObject.profile = userProfile.bots.get(queryReceived.targetBotProfileId) + if (thisObject.profile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } + + function execute() { + + return { + "botProfileId": thisObject.profile.botProfileId, + "botProfileHandle": thisObject.profile.botProfileHandle, + "ranking": thisObject.profile.ranking, + "followingCount": thisObject.profile.followingCount, + "followersCount": thisObject.profile.followersCount, + "emitterEventsCount": thisObject.profile.emitterEventsCount, + "targetEventsCount": thisObject.profile.targetEventsCount, + "postsCount": thisObject.profile.postsCount + } + } +} \ No newline at end of file diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index bb84a4de8..b234d316a 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -130,13 +130,13 @@ exports.newEvents = function newEvents() { Test #1 : The Emitter or Target profile must be the same as the Query Profile. */ if (emitterUserProfile !== undefined) { - if (emitterUserProfile.userProfieId === thisObject.profile.userProfieId) { + if (emitterUserProfile.userProfileId === thisObject.profile.userProfileId) { addToResponse(event) return } } if (targetUserProfile !== undefined) { - if (targetUserProfile.userProfieId === thisObject.profile.userProfieId) { + if (targetUserProfile.userProfileId === thisObject.profile.userProfileId) { addToResponse(event) return } @@ -145,13 +145,13 @@ exports.newEvents = function newEvents() { Test #2 : The Emitter or Traget profile must be at the Following map of the Query Profile. */ if (emitterUserProfile !== undefined) { - if (thisObject.profile.following.get(emitterUserProfile.userProfieId) !== undefined) { + if (thisObject.profile.following.get(emitterUserProfile.userProfileId) !== undefined) { addToResponse(event) return } } if (targetUserProfile !== undefined) { - if (thisObject.profile.following.get(targetUserProfile.userProfieId) !== undefined) { + if (thisObject.profile.following.get(targetUserProfile.userProfileId) !== undefined) { addToResponse(event) return } @@ -200,15 +200,17 @@ exports.newEvents = function newEvents() { } if (emitterUserProfile !== undefined) { - let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats() query.initialize({ targetUserProfileId: event.emitterUserProfileId }) eventResponse.emitterUserProfile = query.execute() + query.finalize() } if (targetUserProfile !== undefined) { - let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats() query.initialize({ targetUserProfileId: event.targetUserProfileId }) eventResponse.targetUserProfile = query.execute() + query.finalize() } if (emitterPost !== undefined) { diff --git a/Network/Queries/ProfileStats.js b/Network/Queries/UserProfileStats.js similarity index 89% rename from Network/Queries/ProfileStats.js rename to Network/Queries/UserProfileStats.js index 56de88255..383d39aab 100644 --- a/Network/Queries/ProfileStats.js +++ b/Network/Queries/UserProfileStats.js @@ -1,4 +1,4 @@ -exports.newProfileStats = function newProfileStats() { +exports.newUserProfileStats = function newUserProfileStats() { let thisObject = { profile: undefined, @@ -10,7 +10,7 @@ exports.newProfileStats = function newProfileStats() { return thisObject function finalize() { - + thisObject.profile = undefined } function initialize(queryReceived) { @@ -32,7 +32,7 @@ exports.newProfileStats = function newProfileStats() { function execute() { return { - "userProfieId": thisObject.profile.userProfieId, + "userProfileId": thisObject.profile.userProfileId, "userProfileHandle": thisObject.profile.userProfileHandle, "blockchainAccount": thisObject.profile.blockchainAccount, "ranking": thisObject.profile.ranking, diff --git a/Network/Query.js b/Network/Query.js index 3c5d24dfd..65166a513 100644 --- a/Network/Query.js +++ b/Network/Query.js @@ -10,10 +10,11 @@ exports.newQuery = function newQuery() { const QUERY_TYPES = { - PROFILE_STATS: 0, - PROFILE_POSTS: 1, - POST_REPLIES: 2, - EVENTS: 3 + USER_PROFILE_STATS: 0, + BOT_PROFILE_STATS: 1, + PROFILE_POSTS: 2, + POST_REPLIES: 3, + EVENTS: 4 } @@ -30,27 +31,38 @@ exports.newQuery = function newQuery() { switch (thisObject.queryType) { - case QUERY_TYPES.PROFILE_STATS: { - thisObject.query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + case QUERY_TYPES.USER_PROFILE_STATS: { + thisObject.query = NT.modules.QUERY_USER_PROFILE_STATS.newUserProfileStats() query.initialize(queryReceived) + query.finalize() + break + } + + case QUERY_TYPES.BOT_PROFILE_STATS: { + thisObject.query = NT.modules.QUERY_BOT_PROFILE_STATS.newBotProfileStats() + query.initialize(queryReceived) + query.finalize() break } case QUERY_TYPES.PROFILE_POSTS: { thisObject.query = NT.modules.QUERY_PROFILE_POSTS.newProfilePosts() query.initialize(queryReceived) + query.finalize() break } case QUERY_TYPES.POST_REPLIES: { thisObject.query = NT.modules.QUERY_POST_REPLIES.newPostReplies() query.initialize(queryReceived) + query.finalize() break } case QUERY_TYPES.maps.EVENTS: { thisObject.query = NT.modules.QUERY_EVENTS.newEvents() query.initialize(queryReceived) + query.finalize() break } default: throw('Query Type Not Supported.') diff --git a/Network/userProfile.js b/Network/userProfile.js index 50766821f..07516f643 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -1,7 +1,7 @@ exports.newUserProfile = function newUserProfile() { let thisObject = { - userProfieId: undefined, + userProfileId: undefined, userProfileHandle: undefined, blockchainAccount: undefined, ranking: undefined,