du-data.js
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const Nedb = require('nedb-promise');
const path = require('path');
const _ = require('lodash');
const dayjs = require('dayjs');
const db = new Nedb({
filename: path.join(__dirname, 'db/data.json'),
autoload: true
});
const ids = [20, 11172, 11538, 11653, 9536, 9431, 2358, 11621, 11408, 14546, 11746, 2355, 8815, 9670, 8708];
Promise.all(ids.map(id => {
return db.cfind({productId: id}).sort({date: 1}).exec().then(result => {
const firstbuys = _.first(result).lastSoldList.map(r => r.icon);
const first = _.first(result);
const last = _.last(result);
const buys = new Set(_.flatten(_.map(result, r => r.lastSoldList.map(r => r.icon))));
const intrBuys = Array.from(buys).filter(r => !_.some(firstbuys, f => f === r));
const group = _.groupBy(result, 'soldNum');
const dates = _.map(Object.keys(group).sort(), (k) => {
const item = _.first(group[k]);
return item;
});
for (let i = 0; i < dates.length; i++) {
if (dates[i + 1]) {
const day = dayjs(dates[i].date);
const nextDay = dayjs(dates[i + 1].date);
}
}
let intrMax = 0;
for (let i = 0; i < result.length; i++) {
if (i < result.length - 1) {
const intr = result[i + 1].soldNum - result[i].soldNum;
const day = dayjs(result[i].date);
const nextDay = dayjs(result[i + 1].date);
if (intr >= 1) {
// console.log(result[i + 1].date, nextDay.format('YYYY-MM-DD HH:mm'), result[i].date, intr)
}
intrMax = intr > intrMax ? intr : intrMax;
}
}
return `soldNum:${last.soldNum - first.soldNum}, buysNum:${intrBuys.length}, eq:${last.soldNum - first.soldNum === intrBuys.length}, productId:${id}, max:${intrMax}`;
});
})).then(result => {
console.log(result);
});