From 5a3908f6b41497d96529a122f1e2855ae7f02d9e Mon Sep 17 00:00:00 2001 From: Onder DAL Date: Thu, 16 Jun 2022 16:41:30 +0300 Subject: [PATCH] Fixed a bug in Bitcoin Factory Server's case generation. Server README.md file has been edited. --- Bitcoin-Factory/Test-Server/README.md | 99 ++++++++-------- .../Test-Server/TestCasesManager.js | 109 +++++++++++++----- 2 files changed, 127 insertions(+), 81 deletions(-) diff --git a/Bitcoin-Factory/Test-Server/README.md b/Bitcoin-Factory/Test-Server/README.md index d2ae4b8b90..225610e5b1 100644 --- a/Bitcoin-Factory/Test-Server/README.md +++ b/Bitcoin-Factory/Test-Server/README.md @@ -1,50 +1,41 @@ -_________ .__ -/ _____/__ ________ ________________ | | ____ ____ ______ -\_____ \| | \____ \_/ __ \_ __ \__ \ | | / ___\ / _ \/ ___/ -/ \ | / |_> > ___/| | \// __ \| |__/ /_/ > <_> )___ \ -/_______ /____/| __/ \___ >__| (____ /____/\___ / \____/____ > - \/ |__| \/ \/ /_____/ \/ - _____ .__ .__ .____ .__ _________ -/ \ _____ ____ | |__ |__| ____ ____ | | ____ _____ _______ ____ |__| ____ ____ / _____/ ______________ __ ___________ -/ \ / \\__ \ _/ ___\| | \| |/ \_/ __ \ | | _/ __ \\__ \\_ __ \/ \| |/ \ / ___\ \_____ \_/ __ \_ __ \ \/ // __ \_ __ \ -/ Y \/ __ \\ \___| Y \ | | \ ___/ | |__\ ___/ / __ \| | \/ | \ | | \/ /_/ > / \ ___/| | \/\ /\ ___/| | \/ -\____|__ (____ /\___ >___| /__|___| /\___ > |_______ \___ >____ /__| |___| /__|___| /\___ / /_______ /\___ >__| \_/ \___ >__| - \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \//_____/ \/ \/ \/ ---------------------------------------------------------------------- -***To run a Test Case Server you need to setup two workspaces*** ---------------------------------------------------------------------- + +## To run a Test Case Server you need to setup two workspaces + Server Mining workspace. Test Case Server. For best results and to help keep things organised it is recommended to create a mining workspace. ---------------------------------------------------------------------- -***Create the Server Mining Workspace*** ---------------------------------------------------------------------- -Step 1: Load up the getting started tutorials workspace -Step 2: Rename the workspace to something related to the server eg: yourusername-mining-servername -Step 3: Delete the 3 tutorials -Step 4: Locate the Plugins/Data-Mining node and "Add specified plugin data mine" -Step 4: Add the specified data mine you plan to enable within the test server sensor bot, along with candles and masters. -Step 5: Save and reload the workspace. -Step 6: Locate the Crypto Ecosystem node and expand then find Exchange Markets, Hover over BTC/USDT and select "Install Market". -Step 7: Locate the data tasks node inside my computer node, then continue and expand BTC/USDT/Candles/Candles/Exchange Raw Data/Exchange Raw Data Sensor Bot and configure as follows: ---------------------------------------------------------------------- + +## Create the Server Mining Workspace + +1. Load up the getting started tutorials workspace +2. Rename the workspace to something related to the server eg: yourusername-mining-servername +3. Delete the 3 tutorials +4. Locate the Plugins/Data-Mining node and "Add specified plugin data mine" +5. Add the specified data mine you plan to enable within the test server sensor bot, along with candles and masters. +6. Save and reload the workspace. +7. Locate the Crypto Ecosystem node and expand then find Exchange Markets, Hover over BTC/USDT and select "Install Market". +8. Locate the data tasks node inside my computer node, then continue and expand BTC/USDT/Candles/Candles/Exchange Raw Data/Exchange Raw Data Sensor Bot and configure as follows: + +``` { "startDate": "2017-06-01" } ---------------------------------------------------------------------- -Step 8: Delete every "resistances and supports Multi-Time-Frame-Daily" node leaving only "resistances and supports Multi-Time-Frame-Market" nodes on each data mine task node. This will help reduce unnecessary processing. -Step 9: Run all project data tasks from the Data Tasks node. -Step 10: Save the workspace you are finished with the Mining workspace. - ---------------------------------------------------------------------- -***Server Workspace*** ---------------------------------------------------------------------- -The server workspace can be accessed by requesting a default template from the machine learning telegram group. ---------------------------------------------------------------------- -Step 1: Edit Test-Server Sensor Bot Instance with the following and replace YOUR-SERVER-NAME with the name of your server: +``` +9. Delete every "resistances and supports Multi-Time-Frame-Daily" node leaving only "resistances and supports Multi-Time-Frame-Market" nodes on each data mine task node. This will help reduce unnecessary processing. +10. Run all project data tasks from the Data Tasks node. +11. Save the workspace you are finished with the Mining workspace. + + +## Server Workspace + +**The server workspace can be accessed by requesting a default template from the machine learning telegram group.** + +1. Edit Test-Server Sensor Bot Instance with the following and replace YOUR-SERVER-NAME with the name of your server: + +``` { "networkCodeName": "Testnet", "targetSuperalgosHost": "localhost", @@ -53,11 +44,12 @@ Step 1: Edit Test-Server Sensor Bot Instance with the following and replace YOUR "serverInstanceName": "YOUR-SERVER-NAME", "timeSeriesFile": { "labels": [ +``` -Step 2: If you are running multiple instances of Superalgos and require data transfer from instance then input the IP address of the Superalgos instance in the "targetSuperalgosHost": "IP-ADDRESS-HERE", -Step 3: Edit each indicator you wish to activate like below. +2. If you are running multiple instances of Superalgos and require data transfer from instance then input the IP address of the Superalgos instance in the "targetSuperalgosHost": "IP-ADDRESS-HERE", +3. Edit each indicator you wish to activate like below. Indicator with range "ON" must be mining and up-to-date (from mining workspace preferably) - +``` { "dataMine": "Delta", "indicator": "MFI", @@ -68,13 +60,13 @@ Indicator with range "ON" must be mining and up-to-date (from mining workspace p "ON" ] }, - -Step 4: Create Task-Server-App from within your User Profile/User Apps. (If haven't done already) -Step 5: Use the Profile Constructor to Install Signing Accounts. (If haven't done already) -Step 6: If you have signed your account don't forget you need to save your profile and merge it with the plugins/governance/user-profiles develop branch on github.com -Step 7: Reference Task Server App Reference to the task server app in your profile. -Step 8: Start the Test-Server Task and check the console you should see something like this: - +``` +4. Create Task-Server-App from within your User Profile/User Apps. (If haven't done already) +5. Use the Profile Constructor to Install Signing Accounts. (If haven't done already) +6. If you have signed your account don't forget you need to save your profile and merge it with the plugins/governance/user-profiles develop branch on github.com +7. Reference Task Server App Reference to the task server app in your profile. +8. Start the Test-Server Task and check the console you should see something like this: +``` Superalgos TaskServer is Running! Websockets Client will try to Connect to Network Node via Web Sockets ........ Trying to Connect to devosonder -> P2P Network Node #1 -> 99.81.83.180:18042 @@ -101,19 +93,18 @@ Websockets Client Connected to Network Node via Web Sockets .................. C │ 3 │ 'Test Client Instance' │ 'rx300-3' │ '{\r\n "codeName": "rx300-3"\r\n}' │ 'Governance' │ '17d39be6-1c6a-445f-88b9-1dab4b1eb84b' │ undefined │ 'BlaaSwe' │ Congratulations the test server is now running ! +``` + + +## Governance ---------------------------------------------------------------------- -***Governance*** ---------------------------------------------------------------------- Machine learning test cases are deployed to users and all test data is stored within your Bitcoin-Factory/Test-Server/YOUR-SERVER-NAME It is important to note that you are required to keep this data and provide it in a report to allow the system to accurately account for all test cases solved by each user. Test reports are to be combined into a single report then merged into the Bitcoin-Factory/Reports folder with the naming style as follows: Testnet-2022-05-27.csv - ---------------------------------------------------------------------- -Random Notes: +### Random Notes: 1. You can not turn off the minimun 3 labels: Candle Close, Max, Min and 1 Feature: Candle Open. At the Test Server config all this must be ON. 2. Remember that the Test Cases Array JSON file is generated once the first time the Test Server run and does not detect that this file exists. If you change the config adding or removing ON / OFF switches for indicators, you need to manually delete this file and the Forecast Cases Array file so that the Test Server generates it again. Failing to do so will produce errors executing the tests at the Docker container, since dimensions for reshapes will not match, since they were calculated at the moment this file was generated but the changed config produces datasets with other amount of data. diff --git a/Projects/Bitcoin-Factory/TS/Bot-Modules/Test-Server/TestCasesManager.js b/Projects/Bitcoin-Factory/TS/Bot-Modules/Test-Server/TestCasesManager.js index 4531fd902f..6f46c789e7 100644 --- a/Projects/Bitcoin-Factory/TS/Bot-Modules/Test-Server/TestCasesManager.js +++ b/Projects/Bitcoin-Factory/TS/Bot-Modules/Test-Server/TestCasesManager.js @@ -12,6 +12,10 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network } const REPORT_NAME = networkCodeName + '-' + (new Date()).toISOString().substring(0, 16).replace("T", "-").replace(":", "-").replace(":", "-") + '-00' + const MUST_BE_ON_PARAMS = [ + 'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_MAX', 'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_MIN', + 'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_CLOSE', 'CANDLES_CANDLES-VOLUMES_CANDLES_CANDLE_OPEN' + ] let parametersRanges = TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.config.parametersRanges let timeSeriesFileFeatures = TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.config.timeSeriesFile.features @@ -43,6 +47,42 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network saveTestCasesFile() } + /* + Creates a list of those whose value is "ON" except MUST_BE_ON_PARAMS. + */ + function getParametersIsON() { + let parametersIsON = [] + + for (const key of Object.keys(parametersRanges)) { + if (!MUST_BE_ON_PARAMS.includes(key) && parametersRanges[key][0] === "ON") { + parametersIsON.push(key) + } + } + return parametersIsON + } + + /* + Creates all combinations with parameters whose value is "ON". + */ + function getAllCombinations() { + const parametersIsON = getParametersIsON() + const AMOUNT_OF_VARIABLES = parametersIsON.length + + let combinations = [] + for (let i = 0; i < (1 << AMOUNT_OF_VARIABLES); i++) { + let combination = [] + //Increasing or decreasing depending on which direction + for (let j = AMOUNT_OF_VARIABLES - 1; j >= 0; j--) { + let key = parametersIsON[j] + let parameter = { key: key, value: Boolean(i & (1 << j))?"ON":"OFF" } + combination.push(parameter) + } + combinations.push(combination); + + } + return combinations + } + function generateTestCases() { let preParameters = {} @@ -69,32 +109,47 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network /* Generate Cases based on Param Ranges */ - addParamRangesRecursively(0) - function addParamRangesRecursively(index) { + // List of all case combinations + let allCombinations = getAllCombinations() + + // Parameters are being set. + setPreparameters(0) + + // The values of the parameters are set according to their combinations. + for (let i = 0; i < allCombinations.length; i++) { + const combination = allCombinations[i]; + for (const combinationElement of combination) { + preParameters[combinationElement.key] = combinationElement.value + } + addToCaseList() + } + + function setPreparameters(index) { let propertyName = Object.keys(parametersRanges)[index] if (propertyName !== undefined) { for (let i = 0; i < parametersRanges[propertyName].length; i++) { preParameters[propertyName] = parametersRanges[propertyName][i] - addParamRangesRecursively(index + 1) - } - } else { - let parameters = getTestParameters(preParameters) - let parametersHash = TS.projects.foundations.globals.taskConstants.TEST_SERVER.utilities.hash(JSON.stringify(parameters)) - let testCase = { - id: thisObject.testCasesArray.length + 1, - mainAsset: preParameters.LIST_OF_ASSETS[0], - mainTimeFrame: preParameters.LIST_OF_TIMEFRAMES[0], - parameters: parameters, - parametersHash: parametersHash, - status: 'Never Tested' + setPreparameters(index + 1) } + } + } + function addToCaseList() { + let parameters = getTestParameters(preParameters) + let parametersHash = TS.projects.foundations.globals.taskConstants.TEST_SERVER.utilities.hash(JSON.stringify(parameters)) + let testCase = { + id: thisObject.testCasesArray.length + 1, + mainAsset: preParameters.LIST_OF_ASSETS[0], + mainTimeFrame: preParameters.LIST_OF_TIMEFRAMES[0], + parameters: parameters, + parametersHash: parametersHash, + status: 'Never Tested' + } - let existingTestCase = thisObject.testCasesMap.get(parametersHash) - if (existingTestCase === undefined) { - thisObject.testCasesArray.push(testCase) - thisObject.testCasesMap.set(parametersHash, testCase) - } + let existingTestCase = thisObject.testCasesMap.get(parametersHash) + if (existingTestCase === undefined) { + thisObject.testCasesArray.push(testCase) + thisObject.testCasesMap.set(parametersHash, testCase) } } @@ -164,20 +219,20 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network // definition of how the raw dataset is going to be divided between a Traing Dataset and a Test Dataset. parameters.PERCENTAGE_OF_DATASET_FOR_TRAINING = preParameters.PERCENTAGE_OF_DATASET_FOR_TRAINING - // TODO: this calculation is incomplete. If you had multiple time frames it might not work at some point. + // TODO: this calculation is incomplete. If you had multiple time frames it might not work at some point. parameters.NUMBER_OF_FEATURES = 0 for (let i = 0; i < parameters.LIST_OF_TIMEFRAMES.length; i++) { parameters.NUMBER_OF_FEATURES = parameters.NUMBER_OF_FEATURES + (i + 1) * parameters.NUMBER_OF_INDICATORS_PROPERTIES * parameters.NUMBER_OF_ASSETS } - // NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 12*5 - // NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 8*5 + 12*5 + 24*5 + // NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 12*5 + // NUMBER_OF_FEATURES = 1*5 + 2*5 + 3*5 + 4*5 + 6*5 + 8*5 + 12*5 + 24*5 // hyper-parameters parameters.NUMBER_OF_EPOCHS = preParameters.NUMBER_OF_EPOCHS parameters.NUMBER_OF_LSTM_NEURONS = preParameters.NUMBER_OF_LSTM_NEURONS /* - Add Labels + Add Labels */ for (let q = 0; q < timeSeriesFileLabels.length; q++) { let label = timeSeriesFileLabels[q].parameter @@ -187,7 +242,7 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network parameters[label] = preParameters[label] } /* - Add Features + Add Features */ for (let q = 0; q < timeSeriesFileFeatures.length; q++) { let feature = timeSeriesFileFeatures[q].parameter @@ -208,7 +263,7 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network async function getNextTestCase(currentClientInstance) { /* - The first thing we will try to do is to see if this Test Client Instance was not already assigned a Test case for which it never + The first thing we will try to do is to see if this Test Client Instance was not already assigned a Test case for which it never reported back. This is a common situation when some kind of error occured and the whole cycle was not closed. */ for (let i = 0; i < thisObject.testCasesArray.length; i++) { @@ -233,7 +288,7 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network } } /* - The second thing we will try to do is to see if there are assigned test cases that have not been tested in more than 24 hours. + The second thing we will try to do is to see if there are assigned test cases that have not been tested in more than 24 hours. If we find one of those, we will re assign them. */ for (let i = 0; i < thisObject.testCasesArray.length; i++) { @@ -445,4 +500,4 @@ exports.newTestCasesManager = function newTestCasesManager(processIndex, network let fileContent = JSON.stringify(thisObject.testCasesArray, undefined, 4) SA.nodeModules.fs.writeFileSync(global.env.PATH_TO_BITCOIN_FACTORY + "/Test-Server/" + TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.config.serverInstanceName + "/StateData/TestCases/Test-Cases-Array-" + networkCodeName + ".json", fileContent) } -} \ No newline at end of file +}