Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql from 'mysql2';
- const db = mysql
- .createPool({
- host: 'database-host',
- port: process.env.DB_PORT || 3306,
- user: 'root',
- password: '#_1Hq$^DxV}x',
- database: '1win'
- })
- .promise();
- const getPreviousDate = (pastDays = 0) => {
- const dt = new Date();
- dt.setUTCHours(0, 0, 0, 0);
- dt.setDate(dt.getDate() - pastDays);
- retur
- };
- const intervals = [
- //getPreviousDate(1),
- //getPreviousDate(7),
- //getPreviousDate(30),
- // 1, 7, 30,
- 90
- ];
- intervals.forEach(async (date) => {
- console.log('Started working with %s', date);
- const [result] = await db.query(`
- SELECT id_user FROM ma_deposits
- WHERE time >= DATE_SUB(CURRENT_DATE(), INTERVAL ${5} DAY) and time <= DATE_SUB(CURRENT_DATE(), INTERVAL ${4} DAY)
- AND id_user NOT IN (
- SELECT id_user FROM ma_deposits
- WHERE time < DATE_SUB(CURRENT_DATE(), INTERVAL ${5} DAY)
- ); `);
- console.log('Got result for %s: %i', date, result.length);
- const users = new Set();
- for (let i = 0; i < result.length; i++) {
- const user = await db.query('select * from ma_users_meta where ? and ? and ?', [{id_user: result[i].id_user}, {key: 'withdrawal_block'}, {value: 'true'}]).then(r => r[0]);
- if (user.length === 0) {
- const {amount} = await db.query('select sum(amount) as amount from ma_bets where ?', {id_user: result[i].id_user}).then(r => r[0][0]);
- // console.log(date, result[i].id_user, +amount);
- if (+amount > 6600) {
- // console.log(result[i].id_user);
- users.add(result[i].id_user);
- }
- }
- }
- console.log('For %s finnally %i users', date, users.size);
- let deposits = 0;
- let withdrawals = 0;
- let balance = 0;
- for (const user of users) {
- const [deps, withd, bal] = await Promise.all([
- db.query(`select * from ma_deposits where id_user = ? and status = 1 and payment_system not in ('casino', 'money-case')`, [user]).then(r => r[0]),
- db.query(`select * from ma_withdrawal where id_user = ? and status = 1 and payment_system not in ('casino', 'money-case')`, [user]).then(r => r[0]),
- db.query(`select * from ma_balance where id_user = ?`, [user]).then(r => parseFloat(r[0][0].amount)),
- ]);
- //console.log(`select * from ma_deposits where id_user = ${user} and time > ${date.getTime()} and payment_system not in ('casino', 'money-case')`);
- deposits += deps.reduce((accum, dep) => accum += parseFloat(dep.amount), 0);
- withdrawals += withd.reduce((accum, withd) => accum += parseFloat(withd.amount), 0);
- //console.log(bal);
- balance += bal;
- }
- console.log(deposits, withdrawals, users.size, balance);
- const value1 = deposits - withdrawals;
- const value2 = deposits - withdrawals - balance;
- const avg1 = value1 / (users.size || 1);
- const avg2 = value2 / (users.size || 1);
- console.log(`Result for %s is ${avg1}, ${avg2}`, date);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement