Commit 4c341555 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent c0a7b5d2
node --max-old-space-size=9999999999 final1000.js
\ No newline at end of file
let fs = require('fs')
let _ = require('lodash')
let sort = 'profitPerMonth'
let alocatedReserve = 3
let alocatedReserveCompound = 3
work()
async function work() {
let directory = await fs.readdirSync('final1000')
for (let i = 0; i < directory.length; i = i + 1000) {
// console.log('hi')
let arr = []
for (let j = 0; j < 1000; j++) {
try {
if ((j + i) < directory.length)
arr.push(directory[j + i])
} catch (e) {
}
}
if (arr.length !== 0) {
let timestamp = Date.now()
try {
await fs.mkdirSync('last1000/' + timestamp)
} catch (e) {
}
run('profitPerMonth1000', arr, timestamp)
run('percentage1000', arr, timestamp)
run('compound1000', arr, timestamp)
run('allocatedReservePerMonthUnder3', arr, timestamp)
run('allocatedReserveCompoundUnder3', arr, timestamp)
run('allocatedReservePerMonthUnder2', arr, timestamp)
await run('allocatedReserveCompoundUnder2', arr, timestamp)
}
}
}
async function run(name, directory, timestamp) {
// let directory = await fs.readdirSync('result')
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(name, directory[f]))
}
arrFinal = await Promise.all(arrFinal)
for (let i = 0; i < arrFinal.length; i++) {
let inline = arrFinal[i]
for (let z = 0; z < inline.length; z++)
arr2.push(inline[z])
}
if (name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2')
last = _.orderBy(arr2, ['profitPerMonth'], ['desc']);
if (name === 'percentage1000')
last = _.orderBy(arr2, ['percentage'], ['asc']);
if (name === 'compound1000' || name === 'allocatedReserveCompoundUnder3' || name === 'allocatedReserveCompoundUnder2')
last = _.orderBy(arr2, ['compoundPerMonth'], ['desc']);
if (name === 'allocatedReservePerMonthUnder2' || name === 'allocatedReservePerMonthUnder3') {
let arr20Max = []
for (let i = 0; i < last.length; i++) {
if (name === 'allocatedReservePerMonthUnder2')
alocatedReserve = 2
else
alocatedReserve = 3
if (last[i].allocatedReserve < alocatedReserve)
arr20Max.push(last[i])
}
last = arr20Max
}
if (name === 'allocatedReserveCompoundUnder2' || name === 'allocatedReserveCompoundUnder3') {
let arr20Max = []
for (let i = 0; i < last.length; i++) {
if (name === 'allocatedReserveCompoundUnder2')
alocatedReserve = 2
else
alocatedReserve = 3
if (last[i].allocatedReserve < alocatedReserve)
arr20Max.push(last[i])
}
last = arr20Max
}
let las = []
for (let i = 0; i < 1000; i++) {
if (i < last.length)
las.push(last[i])
}
createfileADV(timestamp, name, JSON.stringify(las, null, 2))
last = []
}
async function readFile(name, directory) {
let sortByProfit = []
let file = await fs.readFileSync('./final1000/' + directory + '/' + name + '.json', 'utf8')
file = JSON.parse(file)
// file = _.orderBy(file, sort, ['desc']);
for (let j = 0; j < file.length; j++) {
sortByProfit.push(file[j])
}
// let sortByPercentage = []
// file = _.orderBy(file, ['percentage'], ['asc']);
// for (let j = 0; j < file.length; j++) {
//
// sortByPercentage.push(file[j])
// }
//
// let sortByCompound = []
// file =_.orderBy(file, ['compoundPerMonth'], ['desc']);
// for (let j = 0; j < file.length; j++) {
//
// sortByCompound.push(file[j])
// }
return file
}
function createfileADV(timestamp, filename, data) {
return new Promise(function (resolve, reject) {
fs.writeFile('last1000/' + timestamp + '/' + 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