Commit e6692ca7 authored by Ahmad Nemati's avatar Ahmad Nemati

git pu

parent 1909439d
let fs = require('fs') let fs = require('fs')
let _ = require('lodash') let _ = require('lodash')
let moment=require('moment-timezone') let moment = require('moment-timezone')
run() run()
async function run() { async function run() {
...@@ -8,14 +8,13 @@ async function run() { ...@@ -8,14 +8,13 @@ async function run() {
let configs = await fs.readdirSync('uniq/') let configs = await fs.readdirSync('uniq/')
let arr = [] let arr = []
let arrDate = [] let arrDate = []
let levels=[] let levels = []
let types=[] let types = []
for (let i = 0; i < configs.length; i++) { for (let i = 0; i < configs.length; i++) {
let config = await fs.readFileSync('./uniq/' + configs[i] + '/default/compound1000.json', 'utf8')
let config = await fs.readFileSync('./uniq/' + configs[i]+'/default/compound1000.json', 'utf8')
config = JSON.parse(config) config = JSON.parse(config)
...@@ -24,7 +23,7 @@ async function run() { ...@@ -24,7 +23,7 @@ async function run() {
types.push(config[j].type.split('targetPercentage:false')[1]) types.push(config[j].type.split('targetPercentage:false')[1])
let dateString = config[j].dateString.split('_') let dateString = config[j].dateString.split('_')
for (let z = 0; z < dateString.length-1; z++) for (let z = 0; z < dateString.length - 1; z++)
arrDate.push(dateString[z]) arrDate.push(dateString[z])
arr.push(config[j]) arr.push(config[j])
} }
...@@ -37,60 +36,58 @@ async function run() { ...@@ -37,60 +36,58 @@ async function run() {
arr = _.uniqBy(arr, 'platform'); arr = _.uniqBy(arr, 'platform');
arrDate = _.uniq(arrDate); arrDate = _.uniq(arrDate);
let uniqLevels = _.uniq(levels); let uniqLevels = _.uniq(levels);
let uniqType= _.uniq(types); let uniqType = _.uniq(types);
arrDate = _.orderBy(arrDate) arrDate = _.orderBy(arrDate)
let levelSort=[]
let typeSort=[] await createfileADV()
for (let i=0;i<uniqLevels.length;i++) let levelSort = []
{ let typeSort = []
let counter=0 for (let i = 0; i < uniqLevels.length; i++) {
for (let j=0;j<levels.length;j++) let counter = 0
for (let j = 0; j < levels.length; j++)
if (uniqLevels[i] === levels[j]) if (uniqLevels[i] === levels[j])
counter++ counter++
levelSort.push({level:uniqLevels[i],count:counter}) levelSort.push({level: uniqLevels[i], count: counter})
} }
for (let i=0;i<uniqType.length;i++) for (let i = 0; i < uniqType.length; i++) {
{ let counter = 0
let counter=0 for (let j = 0; j < types.length; j++)
for (let j=0;j<types.length;j++)
if (uniqType[i] === types[j]) if (uniqType[i] === types[j])
counter++ counter++
typeSort.push({type:uniqType[i],count:counter}) typeSort.push({type: uniqType[i], count: counter})
} }
typeSort=_.orderBy(typeSort, ['count'], ['desc']); typeSort = _.orderBy(typeSort, ['count'], ['desc']);
console.log('All Uniq Platform:' + arr.length) console.log('All Uniq Platform:' + arr.length)
console.log('All Uniq Date:' + arrDate.length) console.log('All Uniq Date:' + arrDate.length)
console.log(arrDate) console.log(arrDate)
console.log(levelSort) console.log(levelSort)
console.log(typeSort) console.log(typeSort)
let maxDiff=0 createfileADV(JSON.stringify(arrDate, null, 2))
for (let i=0;i<arrDate.length-1;i++) let maxDiff = 0
{ for (let i = 0; i < arrDate.length - 1; i++) {
let diff=getDaysDiff(arrDate[i],arrDate[i+1]) let diff = getDaysDiff(arrDate[i], arrDate[i + 1])
if (diff>maxDiff) if (diff > maxDiff)
maxDiff=diff maxDiff = diff
} }
console.log('Max Diff Day:' + maxDiff) console.log('Max Diff Day:' + maxDiff)
let levelBaseDays=[] let levelBaseDays = []
for(let l=0;l<uniqLevels.length;l++) for (let l = 0; l < uniqLevels.length; l++) {
{ let levelInline = []
let levelInline=[]
for (let i = 0; i < configs.length; i++) { for (let i = 0; i < configs.length; i++) {
let config = await fs.readFileSync('./uniq/' + configs[i]+'/default/compound1000.json', 'utf8') let config = await fs.readFileSync('./uniq/' + configs[i] + '/default/compound1000.json', 'utf8')
config = JSON.parse(config) config = JSON.parse(config)
for (let j = 0; j < config.length; j++) { for (let j = 0; j < config.length; j++) {
if (config[j].maxLevel ===uniqLevels[l]) if (config[j].maxLevel === uniqLevels[l]) {
{
let dateString = config[j].dateString.split('_') let dateString = config[j].dateString.split('_')
for (let z = 0; z < dateString.length-1; z++) for (let z = 0; z < dateString.length - 1; z++)
levelInline.push(dateString[z]) levelInline.push(dateString[z])
} }
...@@ -98,10 +95,9 @@ let maxDiff=0 ...@@ -98,10 +95,9 @@ let maxDiff=0
} }
} }
levelInline=_.uniq(levelInline) levelInline = _.uniq(levelInline)
levelBaseDays.push({level:uniqLevels[l],uniqDaysRun:levelInline.length}) levelBaseDays.push({level: uniqLevels[l], uniqDaysRun: levelInline.length})
} }
console.log(levelBaseDays) console.log(levelBaseDays)
...@@ -111,8 +107,8 @@ let maxDiff=0 ...@@ -111,8 +107,8 @@ let maxDiff=0
function getDaysDiff(start, closed) { function getDaysDiff(start, closed) {
//2019-05-25T05:34:27+04:30 //2019-05-25T05:34:27+04:30
var now = moment(moment(closed,'YYYY-MM-DD').format()); var now = moment(moment(closed, 'YYYY-MM-DD').format());
var end = moment.duration(now.diff(moment(start,'YYYY-MM-DD'))); var end = moment.duration(now.diff(moment(start, 'YYYY-MM-DD')));
// console.log(parseInt(end.asDays())) // console.log(parseInt(end.asDays()))
return parseInt(end.asDays()) return parseInt(end.asDays())
...@@ -122,7 +118,7 @@ function getDaysDiff(start, closed) { ...@@ -122,7 +118,7 @@ function getDaysDiff(start, closed) {
function createfileADV(data) { function createfileADV(data) {
// console.log(data) // console.log(data)
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
fs.writeFile('configs/last.json', data, 'utf8', function (err) { fs.writeFile('date.json', data, 'utf8', function (err) {
if (err) reject(err); if (err) reject(err);
else resolve(data); else resolve(data);
}); });
......
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