Commit 3f94feaa authored by therealwolf's avatar therealwolf 💯
Browse files

fixed transfers

parent 93662d12
......@@ -2,10 +2,10 @@ import * as db_data from '../../database/data.db'
import { query, TIME_GROUP_ORDER_QUERY, TIME_GROUP_QUERY, TIMESTAMP, convert_grouped } from './query'
export let rewards_benefactor = async (app: string, account: string, asset: string, queryAsset: string, last_update) => {
export let rewards_benefactor = async (app: string, account: string, asset: string, last_update) => {
try {
console.log(`REWARDS_BENEFACTOR_${asset}`)
const column_name = (queryAsset.toLowerCase() === 'vests' ? 'vesting' : queryAsset.toLowerCase()) + '_payout'
const column_name = (asset.toLowerCase() === 'vests' ? 'vesting' : asset.toLowerCase()) + '_payout'
let q = `SELECT SUM(${column_name}), ${TIMESTAMP()} FROM VOCommentBenefactorRewards WHERE[benefactor] = '${account}' AND ${column_name} > 0 ${TIME_GROUP_ORDER_QUERY(last_update)}`
const result = await query(q)
const data_type = `REWARDS_BENEFACTOR_${asset}`.toLowerCase()
......
......@@ -7,17 +7,17 @@ import { query, TIME_GROUP_ORDER_QUERY, TIME_GROUP_QUERY, TIMESTAMP, convert_gro
/**
* TX of transfers to account
*/
export let tx_transfers = async (app: string, account: string, asset: string, queryAsset: string, last_update) => {
export let tx_transfers = async (app: string, account: string, asset: string, last_update) => {
try {
let THRESHOLD = process.env.TRANSFER_THRESHOLD
console.log(`TX_TRANSFERS_${asset}`)
let query_incoming = `SELECT COUNT(*), ${TIMESTAMP()} FROM TxTransfers WHERE[to] = '${account}' AND amount_symbol = '${queryAsset}' AND amount >= ${THRESHOLD} ${TIME_GROUP_ORDER_QUERY(last_update)}`
let query_outgoing = `SELECT COUNT(*), ${TIMESTAMP()} FROM TxTransfers WHERE[from] = '${account}' AND amount_symbol = '${queryAsset}' AND amount >= ${THRESHOLD} ${TIME_GROUP_ORDER_QUERY(last_update)}`
let query_incoming = `SELECT COUNT(*), ${TIMESTAMP()} FROM TxTransfers WHERE[to] = '${account}' AND amount_symbol = '${asset}' AND amount >= ${THRESHOLD} ${TIME_GROUP_ORDER_QUERY(last_update)}`
let query_outgoing = `SELECT COUNT(*), ${TIMESTAMP()} FROM TxTransfers WHERE[from] = '${account}' AND amount_symbol = '${asset}' AND amount >= ${THRESHOLD} ${TIME_GROUP_ORDER_QUERY(last_update)}`
const result_incoming = await query(query_incoming)
const result_outgoing = await query(query_outgoing)
const data_type = `TX_TRANSFERS_${queryAsset}`.toLowerCase()
const data_type = `TX_TRANSFERS_${asset}`.toLowerCase()
const data_incoming = convert_grouped(result_incoming)
const data_outgoing = convert_grouped(result_outgoing)
......
......@@ -5,10 +5,10 @@ import { query, TIME_GROUP_ORDER_QUERY, TIME_GROUP_QUERY, TIMESTAMP, convert_gro
/**
* Sum of all transfers to account
*/
export let volume_transfers = async (app: string, account: string, asset: string, queryAsset: string, last_update) => {
export let volume_transfers = async (app: string, account: string, asset: string, last_update) => {
try {
console.log(`VOLUME_TRANSFERS_${asset}`)
let q = `SELECT SUM(amount), ${TIMESTAMP()} FROM TxTransfers WHERE[to] = '${account}' AND amount_symbol = '${queryAsset}' ${TIME_GROUP_ORDER_QUERY(last_update)}`
let q = `SELECT SUM(amount), ${TIMESTAMP()} FROM TxTransfers WHERE[to] = '${account}' AND amount_symbol = '${asset}' ${TIME_GROUP_ORDER_QUERY(last_update)}`
const result = await query(q)
const data_type = `VOLUME_TRANSFERS_${asset}`.toLowerCase()
const data = convert_grouped(result)
......@@ -19,7 +19,7 @@ export let volume_transfers = async (app: string, account: string, asset: string
}
export let volume_payouts = async (app: string, account: string, asset: string, queryAsset: string, last_update) => {
export let volume_payouts = async (app: string, account: string, asset: string, last_update) => {
console.log(`VOLUME_PAYOUTS_${asset}`)
let q = `SELECT SUM(amount), ${TIMESTAMP()} FROM TxTransfers WHERE[to] = '${account}' AND amount_symbol = '${queryAsset}' ${TIME_GROUP_ORDER_QUERY(last_update)}`
let q = `SELECT SUM(amount), ${TIMESTAMP()} FROM TxTransfers WHERE[to] = '${account}' AND amount_symbol = '${asset}' ${TIME_GROUP_ORDER_QUERY(last_update)}`
}
\ No newline at end of file
......@@ -37,7 +37,7 @@ export let update_data = async () => {
for (let app of apps) {
try {
if (moment.utc().dayOfYear() <= moment.utc(app.last_update_data).dayOfYear() && moment.utc().year() <= moment.utc(app.last_update_data).year()) {
// continue
continue
}
let missing_days = 62 // moment.utc().dayOfYear() - moment.utc(app.last_update_data).dayOfYear()
......@@ -46,15 +46,13 @@ export let update_data = async () => {
let last_update_data = moment.utc().subtract(missing_days + 2, 'd').toISOString()
console.log('Updating data', app.name, last_update_data)
for (let acc of app.accounts) {
try {
// Incoming Transfers
if (acc.transfer || acc.transfer_only_dau) {
if (!acc.transfer_only_dau) {
for (let asset of ['HBD', 'HIVE']) {
const queryAsset = getQueryAsset(asset)
await volume_transfers(app.name, acc.name, asset, queryAsset, last_update_data)
await tx_transfers(app.name, acc.name, asset, queryAsset, last_update_data)
await volume_transfers(app.name, acc.name, asset, last_update_data)
await tx_transfers(app.name, acc.name, asset, last_update_data)
}
}
await dau_transfers(app.name, acc.name, last_update_data)
......@@ -70,8 +68,7 @@ export let update_data = async () => {
if (acc.benefactor) {
await dau_benefactor(app.name, acc.name, last_update_data)
for (let asset of ['HBD', 'HIVE', 'VESTS']) {
const queryAsset = getQueryAsset(asset)
await rewards_benefactor(app.name, acc.name, asset, queryAsset, last_update_data)
await rewards_benefactor(app.name, acc.name, asset, last_update_data)
}
}
......
Supports Markdown
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