diff --git a/server/controllers/BlockchainBlock.ts b/server/controllers/BlockchainBlock.ts index 6c52720..2215502 100644 --- a/server/controllers/BlockchainBlock.ts +++ b/server/controllers/BlockchainBlock.ts @@ -225,6 +225,41 @@ export class BlockchainBlockController { this.TotalDifficultyNBlock, ); + /** + * @swagger + * /epic_explorer/v1/blockchain_block/stackblock: + * get: + * tags: + * - name: STACK_BLOCK | STACK_BLOCK CONTROLLER + * description: To get Total Difficulty and Number of Blocks + * summary: To get Total Difficulty and Number of Blocks + * consumes: + * - application/json + * produces: + * - application/json + * parameters: + * - name: FromDate + * description: Enter the From date + * in: query + * type: string + * - name: ToDate + * description: Enter the To date + * in: query + * type: string + * - name: Interval + * description: Try to give Intevals such as 1 week/ 15 days/ 30 days/ 60 days/ 3 months + * in: query + * type: string + * responses: + * 200: + * description: Total Difficulty and No. of blocks fetched successfully + */ + this.router.get( + `${this.path}/stackblock`, + validationMiddleware(TotalDifficultyNBlockDto, true), + this.StackBlock, + ); + /** * @swagger * /epic_explorer/v1/blockchain_block/hashrate: @@ -968,6 +1003,85 @@ export class BlockchainBlockController { } }; + private StackBlock = async ( + request: Request, + response: Response, + next: NextFunction, + ) => { + try { + const TotalDifficultyNBlockRequestData: TotalDifficultyNBlockDto = + request.query; + if (TotalDifficultyNBlockRequestData.Interval) { + var timeIntervalQry = + "timestamp at time zone '" + + process.env.TIME_ZONE + + "' > current_date - interval '" + + TotalDifficultyNBlockRequestData.Interval + + "'"; + } else if ( + TotalDifficultyNBlockRequestData.FromDate || + TotalDifficultyNBlockRequestData.ToDate + ) { + let fromdate = moment(TotalDifficultyNBlockRequestData.FromDate) + .utc() + .format('YYYY-MM-DD'); + let todate = moment(TotalDifficultyNBlockRequestData.ToDate) + .utc() + .format('YYYY-MM-DD'); + + var timeIntervalQry = + "timestamp at time zone '" + + process.env.TIME_ZONE + + "' BETWEEN SYMMETRIC '" + + fromdate + + "' AND '" + + todate + + "'"; + } else { + var timeIntervalQry = + "timestamp at time zone '" + + process.env.TIME_ZONE + + "' > current_date - interval '30 days'"; + } + const stackNBlockQuery = await getConnection() + .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 '" + + process.env.TIME_ZONE + + "')) 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 = 'ProgPow' THEN 1 ELSE NULL END) AS ProgPow \ + from blockchain_block where " + + timeIntervalQry + + "group by DATE_TRUNC('day', timestamp at time zone '" + + process.env.TIME_ZONE + + "') order by date", + ) + .catch(err_msg => { + next(err_msg); + }); + let date = [], + Difficulty = [], + blocks = []; + stackNBlockQuery.forEach(e => { + date.push(moment(e.date).format('YYYY-MM-DD')); + Difficulty.push(parseInt(e.total_difficulty)); + blocks.push(parseInt(e.blocks)); + }); + response.status(200).json({ + status: 200, + timestamp: Date.now(), + message: 'Total Difficulty and Blocks Data fetched Successfully', + response: { + Date: date, + Blocks: blocks, + TotalDifficulty: Difficulty, + }, + }); + } catch (error) { + next(new InternalServerErrorException(error)); + } + }; + private HashRate = async ( request: Request, response: Response, diff --git a/src/app/view/home/graph-list/graph-list.component.html b/src/app/view/home/graph-list/graph-list.component.html index 21d22cd..890a05a 100644 --- a/src/app/view/home/graph-list/graph-list.component.html +++ b/src/app/view/home/graph-list/graph-list.component.html @@ -391,4 +391,53 @@ + +
+
+
+

{{'home.TRANSACTIONS_VS_DATE' | translate}}

+ {{ + this.tg_last | number + }} + +
+ + + +
+
+ + +
+
+ diff --git a/src/app/view/home/graph-list/graph-list.component.ts b/src/app/view/home/graph-list/graph-list.component.ts index 28e2eaa..a870575 100644 --- a/src/app/view/home/graph-list/graph-list.component.ts +++ b/src/app/view/home/graph-list/graph-list.component.ts @@ -21,6 +21,7 @@ export class GraphListComponent implements OnInit { public growthGraphData: any = []; public heatMapGrowthData: any = []; public transcationGraphData: any = []; + public stackGraphData: any = []; public lg_last: any = ''; public ag_last: any = ''; @@ -32,6 +33,7 @@ export class GraphListComponent implements OnInit { public gg_last: any = ''; public tg_last: any = ''; public hg_last: any = ''; + public sg_last: any = ''; public selectedItem: Number = 3; public selectedItem3: Number = 3; @@ -41,6 +43,7 @@ export class GraphListComponent implements OnInit { public selectedItem7: Number = 3; public selectedItem8: Number = 1; public selectedItem9: Number = 3; + public selectedItem10: Number = 3; public tInput: any; public tOutput: any; @@ -75,9 +78,42 @@ export class GraphListComponent implements OnInit { /* Transaction2line chart fetching */ this.Transactiondoublelinechartreq(); - this.bubbleGraphdData = {}; + /* Stack chart fetching */ + this.stackchartreq(); + } + stackchartreq( + fromDate = '', + ToDate = '', + interval = '', + ) { + return new Promise((resolve, reject) => { + let params = new HttpParams(); + params = params.append('FromDate', fromDate); + params = params.append('ToDate', ToDate); + params = params.append('Interval', interval); + this.chartService + .apiGetRequest(params, '/blockchain_block/stackblock') + .subscribe( + res => { + if (res['status'] == 200) { + let DifficultychartDate = res.response.Date; + let Difficultychartval = res.response.TotalDifficulty; + this.lg_last = + Difficultychartval[Difficultychartval.length - 1]; + this.stackchartFunc( + DifficultychartDate, + Difficultychartval, + ); + resolve(); + } + }, + error => {}, + ); + }); + } + Transactiondoublelinechartreq(fromDate = '', ToDate = '', interval = '') { return new Promise((resolve, reject) => { let params = new HttpParams(); @@ -358,6 +394,56 @@ export class GraphListComponent implements OnInit { }; } + stackchartFunc(DifficultychartDate, Blockval) { + this.stackGraphData = { + data: [ + { + x: ['giraffes', 'orangutans', 'monkeys'], + y: [20, 14, 23], + name: 'SF Zoo', + type: 'bar', + marker: { + color: Blockval, + colorscale: 'Viridis', + }, + }, + { + x: ['giraffes', 'orangutans', 'monkeys'], + y: [12, 18, 29], + name: 'LA Zoo', + type: 'bar', + marker: { + color: Blockval, + colorscale: 'Viridis', + }, + } + + ], + layout: { + hovermode: 'closest', + height: 250, + autosize: true, + showlegend: false, + barmode: 'stack', + xaxis: { + tickangle: -45, + tickformat: '%m-%d', + }, + yaxis: { + title: 'Block', + }, + margin: { + l: 50, + r: 50, + b: 50, + t: 50, + }, + }, + options: null, + }; + } + + totalBlocksFunc(DifficultychartDate, Blockval) { this.barGraphData = { data: [