Commit 1d4c69b9 authored by Ahmad Nemati's avatar Ahmad Nemati

git pu

parent a3158e27
let fs = require('fs') let fs = require('fs')
let _ = require('lodash') let _ = require('lodash')
let drawDown=[30,40,50] let drawDown = [30, 40, 50]
let sort = 'profitPerMonth' let sort = 'profitPerMonth'
let alocatedReserve = 3 let alocatedReserve = 3
let alocatedReserveCompound = 3 let alocatedReserveCompound = 3
...@@ -10,25 +10,22 @@ let dir ...@@ -10,25 +10,22 @@ let dir
work() work()
async function work() { async function work() {
let arr=[] let arr = []
try { try {
await fs.mkdirSync('end') await fs.mkdirSync('end')
} } catch (e) {
catch (e)
{
} }
let configs = await fs.readdirSync('last1000/') let configs = await fs.readdirSync('last1000/')
for (let z=0;z<configs.length;z++) for (let z = 0; z < configs.length; z++) {
{ let directory = await fs.readdirSync('last1000/' + configs[z])
let directory = await fs.readdirSync('last1000/'+configs[z])
for (let i = 0; i < directory.length; i = i + 1000) { for (let i = 0; i < directory.length; i = i + 1000) {
// console.log('hi') // console.log('hi')
for (let j = 0; j < 1000; j++) { for (let j = 0; j < 1000; j++) {
try { try {
if ((j + i) < directory.length) if ((j + i) < directory.length)
arr.push(configs[z]+'/'+directory[j + i]) arr.push(configs[z] + '/' + directory[j + i])
} catch (e) { } catch (e) {
} }
...@@ -37,11 +34,6 @@ async function work() { ...@@ -37,11 +34,6 @@ async function work() {
} }
} }
...@@ -50,34 +42,28 @@ async function work() { ...@@ -50,34 +42,28 @@ async function work() {
if (arr.length !== 0) { if (arr.length !== 0) {
let timestamp = Date.now() let timestamp = Date.now()
try { try {
await fs.mkdirSync('end' +'/'+ timestamp) await fs.mkdirSync('end' + '/' + timestamp)
await fs.mkdirSync('end' +'/' + timestamp+'/default') await fs.mkdirSync('end' + '/' + timestamp + '/default')
// for (let z=0;z<drawDown.length;z++) // for (let z=0;z<drawDown.length;z++)
// await fs.mkdirSync('final1000/' + timestamp+'/drawDown'+drawDown[z]) // await fs.mkdirSync('final1000/' + timestamp+'/drawDown'+drawDown[z])
} catch (e) { } catch (e) {
} }
await run('default','compound1000', arr, timestamp) await run('default', 'compound1000', arr, timestamp)
// run('default','compound1000Start', arr, timestamp) // run('default','compound1000Start', arr, timestamp)
// run('default','profitPerMonth1000', arr, timestamp) // run('default','profitPerMonth1000', arr, timestamp)
// generateByDrawDown(timestamp,arr) // generateByDrawDown(timestamp,arr)
// await run('default','profitPerMonth1000Start', arr, timestamp) // await run('default','profitPerMonth1000Start', arr, timestamp)
} }
} }
async function run(root, name, directory, timestamp) {
async function run(root,name, directory, timestamp) {
// let directory = await fs.readdirSync('last1000') // let directory = await fs.readdirSync('last1000')
let arr2 = [] let arr2 = []
let arrFinal = [] let arrFinal = []
...@@ -87,7 +73,7 @@ async function run(root,name, directory, timestamp) { ...@@ -87,7 +73,7 @@ async function run(root,name, directory, timestamp) {
if (typeof directory[f] === "undefined") if (typeof directory[f] === "undefined")
continue continue
console.log(directory[f]) console.log(directory[f])
arrFinal.push(readFile(root,name, directory[f])) arrFinal.push(readFile(root, name, directory[f]))
} }
...@@ -106,7 +92,7 @@ async function run(root,name, directory, timestamp) { ...@@ -106,7 +92,7 @@ async function run(root,name, directory, timestamp) {
// console.log(arr2) // console.log(arr2)
let t=name.toLowerCase() let t = name.toLowerCase()
if (t.includes('per') || name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start') if (t.includes('per') || name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start')
last = _.orderBy(arr2, ['profitPerMonthDrawDown'], ['desc']); last = _.orderBy(arr2, ['profitPerMonthDrawDown'], ['desc']);
...@@ -117,25 +103,26 @@ async function run(root,name, directory, timestamp) { ...@@ -117,25 +103,26 @@ async function run(root,name, directory, timestamp) {
last = _.orderBy(arr2, ['maxLevel'], ['asc']); last = _.orderBy(arr2, ['maxLevel'], ['asc']);
let las = [] let las = []
for (let i = 0; i < last.length; i++) { for (let i = 0; i < last.length; i++) {
if (i < last.length) if (i < last.length)
if (last[i].total > 0) if (last[i].total > 0)
las.push(last[i]) las.push(last[i])
} }
var oldJSON = JSON;
createfileADV(root,timestamp, name, JSON.stringify(las, null, 2)) JSON = undefined;
require('./json2');
JSON.stringify = oldJSON.stringify;
createfileADV(root, timestamp, name, JSON.stringify(las, null, 2))
last = [] last = []
} }
async function readFile(root,name, directory,conf) { async function readFile(root, name, directory, conf) {
let sortByProfit = [] let sortByProfit = []
let file = await fs.readFileSync('./last1000/' + directory + '/'+root+'/' + name + '.json', 'utf8') let file = await fs.readFileSync('./last1000/' + directory + '/' + root + '/' + name + '.json', 'utf8')
file = JSON.parse(file) file = JSON.parse(file)
// file = _.orderBy(file, sort, ['desc']); // file = _.orderBy(file, sort, ['desc']);
...@@ -145,15 +132,12 @@ async function readFile(root,name, directory,conf) { ...@@ -145,15 +132,12 @@ async function readFile(root,name, directory,conf) {
} }
return file return file
} }
function createfileADV(root,timestamp, filename, data) { function createfileADV(root, timestamp, filename, data) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
fs.writeFile('end'+'/' + timestamp + '/'+root+'/' + filename + '.json', data, 'utf8', function (err) { fs.writeFile('end' + '/' + timestamp + '/' + root + '/' + filename + '.json', data, 'utf8', function (err) {
if (err) reject(err); if (err) reject(err);
else resolve(data); else resolve(data);
}); });
......
...@@ -124,6 +124,13 @@ async function run(root, name, directory, timestamp) { ...@@ -124,6 +124,13 @@ async function run(root, name, directory, timestamp) {
} }
var oldJSON = JSON;
JSON = undefined;
require('./json2');
JSON.stringify = oldJSON.stringify;
createfileADV(root, timestamp, name, JSON.stringify(las, null, 2)) createfileADV(root, timestamp, name, JSON.stringify(las, null, 2))
last = [] last = []
......
...@@ -125,10 +125,17 @@ async function run(root,name, directory, timestamp) { ...@@ -125,10 +125,17 @@ async function run(root,name, directory, timestamp) {
let las = [] let las = []
for (let i = 0; i < last.length; i++) { for (let i = 0; i < last.length; i++) {
if (i < last.length) if (i < last.length)
if (last[i].total > 0)
las.push(last[i]) las.push(last[i])
} }
var oldJSON = JSON;
JSON = undefined;
require('./json2');
JSON.stringify = oldJSON.stringify;
createfileADV(root,timestamp, name, JSON.stringify(las, null, 2)) createfileADV(root,timestamp, name, JSON.stringify(las, null, 2))
last = [] last = []
......
This diff is collapsed.
...@@ -24,5 +24,10 @@ ...@@ -24,5 +24,10 @@
"shelljs": "^0.8.4", "shelljs": "^0.8.4",
"stringify-object": "^4.0.1", "stringify-object": "^4.0.1",
"unzip": "^0.1.11" "unzip": "^0.1.11"
},
"devDependencies": {
"@babel/core": "^7.17.9",
"@babel/preset-env": "^7.16.11",
"@babel/register": "^7.17.7"
} }
} }
let stringifyObject =require('stringify-object') var oldJSON = JSON;
JSON = undefined;
require('./json2');
JSON.stringify = oldJSON.stringify;
const object = {
foo: 'bar',
'arr': [1, 2, 3],
nested: {
hello: "world"
}
};
const pretty = stringifyObject(object, { let arr=[{hi:1}]
indent: ' ',
singleQuotes: false
});
console.log(pretty); console.log(JSON.stringify(arr, null, 2))
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment