From d410ca2ca573b60ec4eb1b4902c200b857be19c7 Mon Sep 17 00:00:00 2001 From: SuriyaR Date: Tue, 6 Aug 2019 18:40:10 +0530 Subject: [PATCH] Changes --- server/controllers/BlockchainBlock.ts | 171 ++++++++++++++---- .../block-detail/block-detail.component.html | 2 +- .../graph-detail/graph-detail.component.html | 4 + .../graph-detail/graph-detail.component.ts | 12 +- .../home/graph-list/graph-list.component.html | 23 ++- .../home/graph-list/graph-list.component.ts | 37 +++- .../latestblocks/latestblocks.component.html | 2 +- 7 files changed, 193 insertions(+), 58 deletions(-) diff --git a/server/controllers/BlockchainBlock.ts b/server/controllers/BlockchainBlock.ts index 821c829..fbfbdf7 100644 --- a/server/controllers/BlockchainBlock.ts +++ b/server/controllers/BlockchainBlock.ts @@ -192,7 +192,7 @@ export class BlockchainBlockController { /** * @swagger - * /epic_explorer/v1/blockchain_block/totaldiffnblock: + * /epic_explorer/v1/blockchain_block/totaldiff: * get: * tags: * - name: BLOCKCHAIN_BLOCK | BLOCKCHAIN_BLOCK CONTROLLER @@ -217,13 +217,48 @@ export class BlockchainBlockController { * type: string * responses: * 200: - * description: Total Difficulty and No. of blocks fetched successfully + * description: Total Difficulty fetched successfully */ this.router.get( - `${this.path}/totaldiffnblock`, + `${this.path}/totaldiff`, validationMiddleware(TotalDifficultyNBlockDto, true), this.TotalDifficultyNBlock, ); + + /** + * @swagger + * /epic_explorer/v1/blockchain_block/blockcount: + * get: + * tags: + * - name: BLOCKCHAIN_BLOCK | BLOCKCHAIN_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 fetched successfully + */ + this.router.get( + `${this.path}/blockcount`, + validationMiddleware(TotalDifficultyNBlockDto, true), + this.BlockCount, + ); /** * @swagger @@ -970,6 +1005,87 @@ export class BlockchainBlockController { next(new InternalServerErrorException(error)); } }; + + private BlockCount = 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 BlockQuery = 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(hash) as blocks \ + 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 = [], + blockDate = [], + blocks = []; + + BlockQuery.forEach(e => { + blockDate.push(moment(e.date).format('YYYY-MM-DD')); + 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, + blockDate:blockDate + }, + }); + } catch (error) { + next(new InternalServerErrorException(error)); + } + }; private TotalDifficultyNBlock = async ( request: Request, @@ -1006,50 +1122,42 @@ export class BlockchainBlockController { todate + "'"; } else { - var timeIntervalQry = + var timeIntervalQry = "timestamp at time zone '" + process.env.TIME_ZONE + - "' > current_date - interval '30 days'"; + "' > current_date - interval '1 day'"; + } - const BlockQuery = 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(hash) as blocks \ - 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); - }); const TotalDifficultyNBlockQuery = await getConnection() .query( "select 1 as hash, total_difficulty_cuckaroo as total_difficulty_cuckaroo, \ total_difficulty_cuckatoo as total_difficulty_cuckatoo, \ total_difficulty_progpow as total_difficulty_progpow, \ - total_difficulty_randomx as total_difficulty_randomx, date(DATE_TRUNC('day', timestamp at time zone '" + + total_difficulty_randomx as total_difficulty_randomx, DATE_TRUNC('minute', timestamp at time zone '" + process.env.TIME_ZONE + - "')) as date \ + "') as date \ from blockchain_block where " + - timeIntervalQry + + timeIntervalQry + " order by date", ) .catch(err_msg => { next(err_msg); }); + console.log( "select 1 as hash, total_difficulty_cuckaroo as total_difficulty_cuckaroo, \ + total_difficulty_cuckatoo as total_difficulty_cuckatoo, \ + total_difficulty_progpow as total_difficulty_progpow, \ + total_difficulty_randomx as total_difficulty_randomx, DATE_TRUNC('minute', timestamp at time zone '" + + process.env.TIME_ZONE + + "') as date \ + from blockchain_block where " + + timeIntervalQry + + " order by date"); let date = [], - blockDate = [], DifficultyCuckaroo = [], DifficultyCuckatoo = [], DifficultyProgpow = [], - DifficultyRandomx = [], - blocks = []; + DifficultyRandomx = []; + TotalDifficultyNBlockQuery.forEach(e => { //date.indexOf(moment(e.date).format('YYYY-MM-DD')) < 0 ? date.push(moment(e.date).format('YYYY-MM-DD')); @@ -1058,18 +1166,13 @@ export class BlockchainBlockController { DifficultyProgpow.push(parseInt(e.total_difficulty_progpow)); DifficultyRandomx.push(parseInt(e.total_difficulty_randomx)); }); - BlockQuery.forEach(e => { - blockDate.push(moment(e.date).format('YYYY-MM-DD')); - 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, - blockDate:blockDate, DifficultyCuckaroo: DifficultyCuckaroo, DifficultyCuckatoo: DifficultyCuckatoo, DifficultyProgpow: DifficultyProgpow, diff --git a/src/app/view/block-view/block-detail/block-detail.component.html b/src/app/view/block-view/block-detail/block-detail.component.html index ec33b42..550be5f 100644 --- a/src/app/view/block-view/block-detail/block-detail.component.html +++ b/src/app/view/block-view/block-detail/block-detail.component.html @@ -68,7 +68,7 @@
- {{'home.DIFFICULTY' | translate}} + Target Difficulty
{{(hashdata.BlockchainBlockFetchQuery.Proof == 'Cuckoo') ? (hashdata.BlockchainBlockFetchQuery.TotalCuckoo | number) : (hashdata.BlockchainBlockFetchQuery.Proof == 'RandomX') ? (hashdata.BlockchainBlockFetchQuery.TotalDifficultyRandomx | number) : (hashdata.BlockchainBlockFetchQuery.Proof == 'ProgPow') ? (hashdata.BlockchainBlockFetchQuery.TotalDifficultyProgpow | number) : 0}}
diff --git a/src/app/view/graph-view/graph-detail/graph-detail.component.html b/src/app/view/graph-view/graph-detail/graph-detail.component.html index 68cfdc3..9daf040 100644 --- a/src/app/view/graph-view/graph-detail/graph-detail.component.html +++ b/src/app/view/graph-view/graph-detail/graph-detail.component.html @@ -12,6 +12,10 @@
+ + 1 Day 1 {{'home.WEEK' | translate}} diff --git a/src/app/view/graph-view/graph-detail/graph-detail.component.ts b/src/app/view/graph-view/graph-detail/graph-detail.component.ts index 9050016..49dac50 100644 --- a/src/app/view/graph-view/graph-detail/graph-detail.component.ts +++ b/src/app/view/graph-view/graph-detail/graph-detail.component.ts @@ -36,7 +36,11 @@ export class GraphDetailComponent implements OnInit { private comp: GraphListComponent, private titleService: Title, public translate: TransServiceService - ) {} + ) { + if(this.title=='Total Difficulty'){ + this.selectedItem = 6; + } + } ngOnInit() { var self = this; var x = setInterval(function() { @@ -81,7 +85,7 @@ export class GraphDetailComponent implements OnInit { }); break; case 'blocks': - this.comp.Difficultyreq().then(res => { + this.comp.blockreq().then(res => { this.hashdata = this.comp.barGraphData; this.hashdata.layout.height = 500; this.title = 'Blocks'; @@ -193,7 +197,7 @@ export class GraphDetailComponent implements OnInit { switch (this.chartType) { case 'total-difficulty': - this.comp.Difficultyreq(p1, p2, p3, p4, p5).then(res => { + this.comp.Difficultyreq(p1, p2, p3).then(res => { this.hashdata = this.comp.linearGraphData; this.hashdata.layout.height = 500; this.title = 'Total Difficulty'; @@ -210,7 +214,7 @@ export class GraphDetailComponent implements OnInit { }); break; case 'blocks': - this.comp.Difficultyreq(p1, p2, p3, false, true).then(res => { + this.comp.Difficultyreq(p1, p2, p3).then(res => { this.hashdata = this.comp.barGraphData; this.hashdata.layout.height = 500; this.title = 'Blocks'; 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 6e2a151..36eb059 100644 --- a/src/app/view/home/graph-list/graph-list.component.html +++ b/src/app/view/home/graph-list/graph-list.component.html @@ -25,19 +25,22 @@
1 Day + 1 {{'home.WEEK' | translate}} 15 {{'home.DAYS' | translate}} 30 {{'home.DAYS' | translate}} 60 {{'home.DAYS' | translate}} 3 {{'home.MONTHS' | translate}}
@@ -108,19 +111,19 @@
1 {{'home.WEEK' | translate}} 15 {{'home.DAYS' | translate}} 30 {{'home.DAYS' | translate}} 60 {{'home.DAYS' | translate}} 3 {{'home.MONTHS' | translate}}
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 828931d..53714c1 100644 --- a/src/app/view/home/graph-list/graph-list.component.ts +++ b/src/app/view/home/graph-list/graph-list.component.ts @@ -38,7 +38,7 @@ export class GraphListComponent implements OnInit { public sg_last: any = ''; public pg_last: any = ''; - public selectedItem: Number = 3; + public selectedItem: Number = 6; public selectedItem3: Number = 3; public selectedItem2: Number = 3; public selectedItem4: Number = 3; @@ -70,6 +70,8 @@ export class GraphListComponent implements OnInit { /* Total Difficulty and blocks chart fetching */ this.Difficultyreq(); + this.blockreq(); + /* Transcation fee chart fetching */ this.Transcationreq(); @@ -374,8 +376,6 @@ export class GraphListComponent implements OnInit { fromDate = '', ToDate = '', interval = '', - fordifficult = true, - forblocks = true, ) { return new Promise((resolve, reject) => { let params = new HttpParams(); @@ -383,13 +383,12 @@ export class GraphListComponent implements OnInit { params = params.append('ToDate', ToDate); params = params.append('Interval', interval); this.chartService - .apiGetRequest(params, '/blockchain_block/totaldiffnblock') + .apiGetRequest(params, '/blockchain_block/totaldiff') .subscribe( res => { if (res['status'] == 200) { let DifficultychartDate = res.response.Date; let BlocksChartDate = res.response.blockDate; - if (fordifficult) { let DifficultyCuckaroo = res.response.DifficultyCuckaroo; let DifficultyCuckatoo = res.response.DifficultyCuckatoo; let DifficultyProgpow = res.response.DifficultyProgpow; @@ -403,12 +402,34 @@ export class GraphListComponent implements OnInit { DifficultyProgpow, DifficultyRandomx ); - } - if (forblocks) { + resolve(); + } + }, + error => {}, + ); + }); + } + + blockreq( + 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/blockcount') + .subscribe( + res => { + if (res['status'] == 200) { + let DifficultychartDate = res.response.Date; + let BlocksChartDate = res.response.blockDate; let Blockval = res.response.Blocks; this.brg_last = Blockval[Blockval.length - 1]; this.totalBlocksFunc(BlocksChartDate, Blockval); - } resolve(); } }, diff --git a/src/app/view/home/latestblocks/latestblocks.component.html b/src/app/view/home/latestblocks/latestblocks.component.html index 174ee1c..904b39f 100644 --- a/src/app/view/home/latestblocks/latestblocks.component.html +++ b/src/app/view/home/latestblocks/latestblocks.component.html @@ -76,7 +76,7 @@
Difficulty
{{(hashvalue.powalgo == 'Cuckoo') ? (hashvalue.totalcuckoo | number) : (hashvalue.powalgo == 'RandomX') ? (hashvalue.blockchain_block_total_difficulty_randomx | number) : (hashvalue.powalgo == 'ProgPow') ? (hashvalue.blockchain_block_total_difficulty_progpow | number) : 0}} + class="blck_value">{{(hashvalue.powalgo == 'Cuckoo') ? (hashvalue.target_difficulty_cuckatoo | number) : (hashvalue.powalgo == 'RandomX') ? (hashvalue.target_difficulty_randomx | number) : (hashvalue.powalgo == 'ProgPow') ? (hashvalue.target_difficulty_progpow | number) : 0}}