Changes in stacked bar api

This commit is contained in:
SuriyaR 2019-07-30 12:43:24 +05:30
parent 6a1a08f59d
commit 23004bd1f1

View File

@ -976,7 +976,10 @@ export class BlockchainBlockController {
} }
const TotalDifficultyNBlockQuery = await getConnection() const TotalDifficultyNBlockQuery = await getConnection()
.query( .query(
"select 1 as hash, max(total_difficulty) as total_difficulty, date(DATE_TRUNC('day', timestamp at time zone '" + "select 1 as hash, max(total_difficulty_cuckaroo) as total_difficulty_cuckaroo, \
max(total_difficulty_cuckatoo) as total_difficulty_cuckatoo, \
max(total_difficulty_progpow) as total_difficulty_progpow, \
max(total_difficulty_randomx) as total_difficulty_randomx, date(DATE_TRUNC('day', timestamp at time zone '" +
process.env.TIME_ZONE + process.env.TIME_ZONE +
"')) as date, count(hash) as blocks \ "')) as date, count(hash) as blocks \
from blockchain_block where " + from blockchain_block where " +
@ -989,11 +992,17 @@ export class BlockchainBlockController {
next(err_msg); next(err_msg);
}); });
let date = [], let date = [],
Difficulty = [], DifficultyCuckaroo = [],
DifficultyCuckatoo = [],
DifficultyProgpow = [],
DifficultyRandomx = [],
blocks = []; blocks = [];
TotalDifficultyNBlockQuery.forEach(e => { TotalDifficultyNBlockQuery.forEach(e => {
date.push(moment(e.date).format('YYYY-MM-DD')); date.push(moment(e.date).format('YYYY-MM-DD'));
Difficulty.push(parseInt(e.total_difficulty)); DifficultyCuckaroo.push(parseInt(e.total_difficulty_cuckaroo));
DifficultyCuckatoo.push(parseInt(e.total_difficulty_cuckatoo));
DifficultyProgpow.push(parseInt(e.total_difficulty_progpow));
DifficultyRandomx.push(parseInt(e.total_difficulty_randomx));
blocks.push(parseInt(e.blocks)); blocks.push(parseInt(e.blocks));
}); });
response.status(200).json({ response.status(200).json({
@ -1003,7 +1012,10 @@ export class BlockchainBlockController {
response: { response: {
Date: date, Date: date,
Blocks: blocks, Blocks: blocks,
TotalDifficulty: Difficulty, DifficultyCuckaroo: DifficultyCuckaroo,
DifficultyCuckatoo: DifficultyCuckatoo,
DifficultyProgpow: DifficultyProgpow,
DifficultyRandomx: DifficultyRandomx
}, },
}); });
} catch (error) { } catch (error) {
@ -1053,10 +1065,11 @@ export class BlockchainBlockController {
} }
const stackNBlockQuery = await getConnection() const stackNBlockQuery = await getConnection()
.query( .query(
"select 1 as hash, max(total_difficulty_cuckaroo) as total_difficulty_cuckaroo, max(total_difficulty_cuckatoo) as total_difficulty_cuckatoo, max(total_difficulty_progpow) as total_difficulty_progpow, max(total_difficulty_randomx) as total_difficulty_randomx, date(DATE_TRUNC('day', timestamp at time zone '" + "select 1 as hash, date(DATE_TRUNC('day', timestamp at time zone '" +
process.env.TIME_ZONE + process.env.TIME_ZONE +
"')) as date, Count( CASE WHEN proof = 'RandomX' THEN 1 ELSE NULL END) AS RandomX, \ "')) as date, Count( CASE WHEN proof = 'RandomX' THEN 1 ELSE NULL END) AS RandomX, \
Count( CASE WHEN proof = 'Cuckoo' THEN 1 ELSE NULL END) AS Cuckoo,\ Count( CASE WHEN proof = 'Cuckaroo' THEN 1 ELSE NULL END) AS Cuckaroo,\
Count( CASE WHEN proof = 'Cuckatoo' THEN 1 ELSE NULL END) AS Cuckatoo,\
Count( CASE WHEN proof = 'ProgPow' THEN 1 ELSE NULL END) AS ProgPow \ Count( CASE WHEN proof = 'ProgPow' THEN 1 ELSE NULL END) AS ProgPow \
from blockchain_block where " + from blockchain_block where " +
timeIntervalQry + timeIntervalQry +
@ -1068,12 +1081,18 @@ export class BlockchainBlockController {
next(err_msg); next(err_msg);
}); });
let date = [], let date = [],
Difficulty = [], Blocks = [],
blocks = []; Cuckaroo = [],
Cuckatoo = [],
ProgPow = [],
RandomX = [];
stackNBlockQuery.forEach(e => { stackNBlockQuery.forEach(e => {
date.push(moment(e.date).format('YYYY-MM-DD')); date.push(moment(e.date).format('YYYY-MM-DD'));
Difficulty.push(parseInt(e.total_difficulty)); Blocks.push({Cuckaroo: parseInt(e.cuckaroo), Cuckatoo : parseInt(e.cuckatoo), ProgPow : parseInt(e.progpow), RandomX : parseInt(e.randomx)})
blocks.push(parseInt(e.blocks)); Cuckaroo.push(parseInt(e.cuckaroo));
Cuckatoo.push(parseInt(e.cuckatoo));
ProgPow.push(parseInt(e.progpow));
RandomX.push(parseInt(e.randomx));
}); });
response.status(200).json({ response.status(200).json({
status: 200, status: 200,
@ -1081,8 +1100,7 @@ export class BlockchainBlockController {
message: 'Total Difficulty and Blocks Data fetched Successfully', message: 'Total Difficulty and Blocks Data fetched Successfully',
response: { response: {
Date: date, Date: date,
Blocks: blocks, Blocks
TotalDifficulty: Difficulty,
}, },
}); });
} catch (error) { } catch (error) {