59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import * as dotenv from 'dotenv'
|
|
const envFile = process.env.NODE_ENV && process.env.NODE_ENV === 'production' ? `.env.production` : '.env.development'
|
|
dotenv.config({ path: envFile })
|
|
console.log(process.env.DB_MAIN)
|
|
import { ScoreRecord } from 'models/ScoreRecord'
|
|
import { FixAddress } from 'models/ctrl/FixAddress'
|
|
import { SCORE_INVITE_REBATE } from 'common/Constants'
|
|
;(async () => {
|
|
try {
|
|
let begin = new Date('2024-05-10T00:00:00.000Z')
|
|
const oneDay = 24 * 60 * 60 * 1000
|
|
let end = new Date(begin.getTime() + oneDay)
|
|
let whiteSet = new Set()
|
|
let addressCursor = FixAddress.find().cursor({ batchSize: 1000 })
|
|
console.time('address')
|
|
for await (let doc of addressCursor) {
|
|
whiteSet.add(doc.user)
|
|
}
|
|
console.timeEnd('address')
|
|
console.time('score')
|
|
while (end < new Date()) {
|
|
let scoreTask = 0
|
|
let scoreShare = 0
|
|
let scoreWhite = 0
|
|
let scoresCursor = ScoreRecord.find({
|
|
$and: [{ createdAt: { $gte: begin } }, { createdAt: { $lt: end } }],
|
|
}).cursor({ batchSize: 1000 })
|
|
for await (let doc of scoresCursor) {
|
|
if (whiteSet.has(doc.user)) {
|
|
scoreWhite += doc.score
|
|
} else {
|
|
if (doc.type === SCORE_INVITE_REBATE) {
|
|
scoreShare += doc.score
|
|
} else {
|
|
scoreTask += doc.score
|
|
}
|
|
}
|
|
}
|
|
console.log(
|
|
begin.toLocaleDateString(),
|
|
'\t',
|
|
(scoreTask + scoreShare + scoreWhite) | 0,
|
|
'\t',
|
|
scoreTask | 0,
|
|
'\t',
|
|
scoreShare | 0,
|
|
'\t',
|
|
scoreWhite | 0,
|
|
)
|
|
begin = end
|
|
end = new Date(begin.getTime() + oneDay)
|
|
}
|
|
console.timeEnd('score')
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
process.exit(0)
|
|
})()
|