Commit 96003452 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 5e482336
node --max-old-space-size=9999999999 end.js
\ No newline at end of file
let fs = require('fs')
let _ = require('lodash')
let drawDown=[30,40,50]
let sort = 'profitPerMonth'
let alocatedReserve = 3
let alocatedReserveCompound = 3
let dir
work()
async function work() {
let arr=[]
try {
await fs.mkdirSync('end')
}
catch (e)
{
}
let configs = await fs.readdirSync('last1000/')
for (let z=0;z<configs.length;z++)
{
let directory = await fs.readdirSync('last1000/'+configs[z])
for (let i = 0; i < directory.length; i = i + 1000) {
// console.log('hi')
for (let j = 0; j < 1000; j++) {
try {
if ((j + i) < directory.length)
arr.push(configs[z]+'/'+directory[j + i])
} catch (e) {
}
}
}
}
if (arr.length !== 0) {
let timestamp = Date.now()
try {
await fs.mkdirSync('end' +'/'+ timestamp)
await fs.mkdirSync('end' +'/' + timestamp+'/default')
// for (let z=0;z<drawDown.length;z++)
// await fs.mkdirSync('final1000/' + timestamp+'/drawDown'+drawDown[z])
} catch (e) {
}
run('default','compound1000', arr, timestamp)
run('default','compound1000Start', arr, timestamp)
run('default','profitPerMonth1000', arr, timestamp)
// generateByDrawDown(timestamp,arr)
await run('default','profitPerMonth1000Start', arr, timestamp)
}
}
async function run(root,name, directory, timestamp) {
// let directory = await fs.readdirSync('last1000')
let arr2 = []
let arrFinal = []
let last = []
// console.log(directory)
for (let f = 0; f < directory.length; f++) {
if (typeof directory[f] === "undefined")
continue
console.log(directory[f])
arrFinal.push(readFile(root,name, directory[f]))
}
arrFinal = await Promise.all(arrFinal)
for (let i = 0; i < arrFinal.length; i++) {
let inline = arrFinal[i]
// console.log(inline)
for (let z = 0; z < inline.length; z++)
arr2.push(inline[z])
}
// console.log(arr2)
let t=name.toLowerCase()
if (t.includes('per') || name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start')
last = _.orderBy(arr2, ['profitPerMonthDrawDown'], ['desc']);
// if (name === 'percentage1000')
// last = _.orderBy(arr2, ['percentage'], ['asc']);
if (t.includes('compound') || name === 'compound1000' || name === 'allocatedReserveCompoundUnder3' || name === 'allocatedReserveCompoundUnder2' || name === 'compound1000Start')
last = _.orderBy(arr2, ['CompoundPerMonthDrawDown'], ['desc']);
let las = []
for (let i = 0; i < 1000; i++) {
if (i < last.length)
las.push(last[i])
}
createfileADV(root,timestamp, name, JSON.stringify(las, null, 2))
last = []
}
async function readFile(root,name, directory,conf) {
let sortByProfit = []
let file = await fs.readFileSync('./last1000/' + directory + '/'+root+'/' + name + '.json', 'utf8')
file = JSON.parse(file)
// file = _.orderBy(file, sort, ['desc']);
for (let j = 0; j < file.length; j++) {
sortByProfit.push(file[j])
}
return file
}
function createfileADV(root,timestamp, filename, data) {
return new Promise(function (resolve, reject) {
fs.writeFile('end'+'/' + timestamp + '/'+root+'/' + filename + '.json', data, 'utf8', function (err) {
if (err) reject(err);
else resolve(data);
});
});
}
\ 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