Block interval

This commit is contained in:
raja.blaze 2019-08-16 17:13:15 +05:30
parent ffec592e2e
commit f2977b8823
7 changed files with 202 additions and 64 deletions

View File

@ -304,16 +304,8 @@ export class BlockchainBlockController {
* produces: * produces:
* - application/json * - application/json
* parameters: * 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 * - name: Interval
* description: Try to give Intevals such as 1 week/ 15 days/ 30 days/ 60 days/ 3 months * description: try to get Date
* in: query * in: query
* type: string * type: string
* responses: * responses:
@ -1202,71 +1194,37 @@ export class BlockchainBlockController {
const TotalDifficultyNBlockRequestData: TotalDifficultyNBlockDto = const TotalDifficultyNBlockRequestData: TotalDifficultyNBlockDto =
request.query; request.query;
if (TotalDifficultyNBlockRequestData.Interval) { if (TotalDifficultyNBlockRequestData.Interval) {
var timeIntervalQry = var IntervalDate = TotalDifficultyNBlockRequestData.Interval;
"timestamp at time zone '" + }else {
process.env.TIME_ZONE + var current_date = Date.now();
"' > current_date - interval '" + var IntervalDate = "";
TotalDifficultyNBlockRequestData.Interval + IntervalDate = moment(current_date).format('YYYY-MM-DD');
"'"; }
} 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 '1 day'";
}
const BlockQuery = await getConnection(Global.network) const BlockQuery = await getConnection(Global.network)
.query( .query(
"select 1 as hash, max(total_difficulty_cuckaroo) as total_difficulty_cuckaroo, \ "SELECT bb.height, coalesce(max(bb.alter), 0) as alter, bb.timestamp FROM (SELECT height, EXTRACT(EPOCH FROM (timestamp - LAG(timestamp) OVER (ORDER BY timestamp))) AS alter, timestamp FROM blockchain_block where timestamp::date = date '"+IntervalDate+"' order by height asc) as bb group by bb.height , bb.timestamp;",
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 => { .catch(err_msg => {
next(err_msg); next(err_msg);
}); });
let date = [], let date = [],
blockDate = [], alter = [],
blocks = []; blocks = [];
BlockQuery.forEach(e => { BlockQuery.forEach(e => {
blockDate.push(moment(e.date).format('YYYY-MM-DD')); //date.push(moment(e.timestamp).format('YYYY-MM-DD HH:MM:SS'));
blocks.push(parseInt(e.blocks)); alter.push(parseInt(e.alter));
blocks.push(parseInt(e.height));
}); });
response.status(200).json({ response.status(200).json({
status: 200, status: 200,
timestamp: Date.now(), timestamp: Date.now(),
message: 'Block Interval Data fetched Successfully', message: 'Block Interval Data fetched Successfully',
response: { response: {
Date: date, //Date: date,
Blocks: blocks, Blocks: blocks,
blockDate:blockDate alter:alter
}, },
}); });
} catch (error) { } catch (error) {

View File

@ -43,6 +43,7 @@
"TARGET_DIFFICULTY" : "Zielschwierigkeit", "TARGET_DIFFICULTY" : "Zielschwierigkeit",
"TRANSACTIONS_BY_TIME" : "Transaktionen im Zeitverlauf", "TRANSACTIONS_BY_TIME" : "Transaktionen im Zeitverlauf",
"BLOCKS" : "Blöcke", "BLOCKS" : "Blöcke",
"BLOCKSINTERVAL" : "Intervall-S / W-Blöcke",
"BLOCK" : "Block", "BLOCK" : "Block",
"BLOCKS_MINED" : "Blöcke abgebaut", "BLOCKS_MINED" : "Blöcke abgebaut",
"TRANSACTION_FEES" : "Transkationsgebühren", "TRANSACTION_FEES" : "Transkationsgebühren",

View File

@ -43,6 +43,7 @@
"TARGET_DIFFICULTY" : "Target Difficulty", "TARGET_DIFFICULTY" : "Target Difficulty",
"TRANSACTIONS_BY_TIME" : "Transactions over time", "TRANSACTIONS_BY_TIME" : "Transactions over time",
"BLOCKS" : "Blocks", "BLOCKS" : "Blocks",
"BLOCKSINTERVAL" : "Interval B/W Blocks",
"BLOCK" : "Block", "BLOCK" : "Block",
"BLOCKS_MINED" : "Blocks Mined", "BLOCKS_MINED" : "Blocks Mined",
"TRANSACTION_FEES" : "Transaction Fees", "TRANSACTION_FEES" : "Transaction Fees",

View File

@ -96,7 +96,7 @@
</div> --> </div> -->
<epic-explorer-plotly *ngIf="hashdata.data" [data]="hashdata.data" [layout]="hashdata.layout"> <epic-explorer-plotly *ngIf="hashdata.data" [data]="hashdata.data" [layout]="hashdata.layout">
</epic-explorer-plotly> </epic-explorer-plotly>
<div class="day_filter" *ngIf="this.title!='Transactions over time'"> <div class="day_filter" *ngIf="this.title!='Transactions over time' && this.title!='Interval B/W Blocks'">
<a href="JavaScript:void(0);" *ngIf="this.title=='Total Difficulty' || this.title=='Target Difficulty' || this.title == 'Blocks'" (click)=" <a href="JavaScript:void(0);" *ngIf="this.title=='Total Difficulty' || this.title=='Target Difficulty' || this.title == 'Blocks'" (click)="
ChartFromView('', '', '1 day', comp.Type); selectedItem = 6; comp.difficultyRange = '1 day';comp.TdifficultyRange = '1 day' ChartFromView('', '', '1 day', comp.Type); selectedItem = 6; comp.difficultyRange = '1 day';comp.TdifficultyRange = '1 day'
@ -137,6 +137,19 @@
[ngClass]="{ active: selectedItem8 == item3.id, day30_txt: true }">{{'home.OUTPUT' | translate}}</a> [ngClass]="{ active: selectedItem8 == item3.id, day30_txt: true }">{{'home.OUTPUT' | translate}}</a>
</div> </div>
<div class="day_filter" *ngIf="this.title=='Interval B/W Blocks'">
<a href="JavaScript:void(0);" (click)="
ChartFromView('today'); selectedInteverval = 1
" id="1" #intevalitem1 [ngClass]="{ active: selectedInteverval == intevalitem1.id, txt_primay: true }">Today</a>
<a href="JavaScript:void(0);" (click)="
ChartFromView('yesterday'); selectedInteverval = 2
" id="2" #intevalitem2 [ngClass]="{ active: selectedInteverval == intevalitem2.id, txt_primay: true }">Yesterday</a>
<a href="JavaScript:void(0);" (click)="ChartFromView('previous'); ">Pre</a>
<span>{{showcurrentIntervalDate}}</span>
<a href="JavaScript:void(0);" (click)="ChartFromView('next'); ">Next</a>
</div>
</div> </div>
</div> </div>
@ -163,6 +176,8 @@
routerLink="/chart/transactions-over-time">{{'home.TRANSACTIONS_BY_TIME' | translate}}</a></li> routerLink="/chart/transactions-over-time">{{'home.TRANSACTIONS_BY_TIME' | translate}}</a></li>
<li class="mb-1" *ngIf="this.title!='Blocks'"><a <li class="mb-1" *ngIf="this.title!='Blocks'"><a
routerLink="/chart/blocks">{{'home.BLOCKS' | translate}}</a></li> routerLink="/chart/blocks">{{'home.BLOCKS' | translate}}</a></li>
<li class="mb-1" *ngIf="this.title!='Interval B/W Blocks'"><a
routerLink="/chart/interval-between-blocks">{{'home.BLOCKSINTERVAL' | translate}}</a></li>
<li class="mb-1" *ngIf="this.title!='Blocks Mined'"><a <li class="mb-1" *ngIf="this.title!='Blocks Mined'"><a
routerLink="/chart/blocks-mined">{{'home.BLOCKS_MINED' | translate}}</a></li> routerLink="/chart/blocks-mined">{{'home.BLOCKS_MINED' | translate}}</a></li>
<li class="mb-1" *ngIf="this.title!='Transaction Fees'"><a <li class="mb-1" *ngIf="this.title!='Transaction Fees'"><a

View File

@ -27,6 +27,9 @@ export class GraphDetailComponent implements OnInit {
public Type: any = ''; public Type: any = '';
public selectedTarget: Number = 3; public selectedTarget: Number = 3;
public selectedTarget12: Number = 1; public selectedTarget12: Number = 1;
public selectedInteverval: Number = 1;
public currenyIntervalDate: any;
public showcurrentIntervalDate: any;
public GraphtInput: any; public GraphtInput: any;
public GraphtOutput: any; public GraphtOutput: any;
@ -119,6 +122,19 @@ export class GraphDetailComponent implements OnInit {
); );
}); });
break; break;
case 'interval-between-blocks':
this.comp.Blockintervalreq().then(res => {
this.hashdata = this.comp.barGraphIntevalData;
this.currenyIntervalDate = this.comp.currenyIntervalDate;
this.showcurrentIntervalDate =this.comp.showcurrentIntervalDate;
this.hashdata.layout.height = 300;
this.title = 'Interval B/W Blocks';
this.selectedInteverval = 1;
this.titleService.setTitle(
this.route.snapshot.data.title + ' - ' + this.title,
);
});
break;
case 'transaction-fees': case 'transaction-fees':
this.comp.Transcationreq().then(res => { this.comp.Transcationreq().then(res => {
this.hashdata = this.comp.transcationGraphData; this.hashdata = this.comp.transcationGraphData;
@ -257,6 +273,15 @@ export class GraphDetailComponent implements OnInit {
this.title = 'Blocks'; this.title = 'Blocks';
}); });
break; break;
case 'interval-between-blocks':
this.comp.Blockintervalreq(p1).then(res => {
this.hashdata = this.comp.barGraphIntevalData;
this.currenyIntervalDate = this.comp.currenyIntervalDate;
this.showcurrentIntervalDate =this.comp.showcurrentIntervalDate;
this.hashdata.layout.height = 300;
this.title = 'Interval B/W Blocks';
});
break;
case 'blocks-mined': case 'blocks-mined':
this.comp.Blockminedreq(p1, p2, p3).then(res => { this.comp.Blockminedreq(p1, p2, p3).then(res => {
this.hashdata = this.comp.doubleareaGraphData; this.hashdata = this.comp.doubleareaGraphData;

View File

@ -371,6 +371,50 @@
</div> </div>
</div> </div>
</div> </div>
<div *ngIf="viewchartvar" [ngClass]="{'col-md-6 col-lg-4 mb-4' : true, 'd-none' : viewchart}">
<div class="box_shadow">
<div class="blocks">
<h2 class="chart_heading d-inline-block">{{'home.BLOCKSINTERVAL' | translate}}</h2>
<span class="txn_count" *ngIf="this.blockinteval_last">{{
this.blockinteval_last | number
}}</span>
<div class="chart_show">
<epic-explorer-plotly *ngIf="barGraphIntevalData.data" [data]="barGraphIntevalData.data" [layout]="barGraphIntevalData.layout"></epic-explorer-plotly>
<div *ngIf="!barGraphIntevalData.data" class="feedback_div news_desc text-center">
<div class="graph_img background_loading mx-auto mb-3"></div>
<div class=" p-3 bg-white">
<p class="mb-2 background_loading para_load"></p>
<p class="mb-2 background_loading para_load"></p>
<p class="mb-2 background_loading para_load"></p>
<p class="mb-2 background_loading para_load"></p>
<p class="mb-2 background_loading para_load"></p>
<p class="mb-2 background_loading para_load"></p>
<p class="mb-2 background_loading para_load"></p>
</div>
</div>
</div>
</div>
<div class="day_filter">
<a href="JavaScript:void(0);" (click)="
Blockintervalreq('today'); selectedInteverval = 1
" id="1" #intevalitem1 [ngClass]="{ active: selectedInteverval == intevalitem1.id, txt_primay: true }">Today</a>
<a href="JavaScript:void(0);" (click)="
Blockintervalreq('yesterday'); selectedInteverval = 2
" id="2" #intevalitem2 [ngClass]="{ active: selectedInteverval == intevalitem2.id, txt_primay: true }">Yesterday</a>
<a href="JavaScript:void(0);" (click)="Blockintervalreq('previous'); ">Pre</a>
<span>{{showcurrentIntervalDate}}</span>
<a href="JavaScript:void(0);" (click)="Blockintervalreq('next'); ">Next</a>
</div>
<div class="explore_all text-right">
<a routerLink="/chart/interval-between-blocks"><span class="text-uppercase d-block">{{'home.EXPLORE_IT' | translate}} <i class="fa fa-long-arrow-right"></i></span></a>
</div>
</div>
</div>
<div *ngIf="viewchartvar" [ngClass]="{'col-md-6 col-lg-4 mb-4' : true, 'd-none' : viewchart}"> <div *ngIf="viewchartvar" [ngClass]="{'col-md-6 col-lg-4 mb-4' : true, 'd-none' : viewchart}">
<div class="box_shadow"> <div class="box_shadow">
<div class="blocks"> <div class="blocks">

View File

@ -3,6 +3,7 @@ import { ChartService } from '../../../shared/services/chart.service';
import { HttpClient, HttpParams } from '@angular/common/http'; import { HttpClient, HttpParams } from '@angular/common/http';
import { TransServiceService } from '../../../shared/services/trans-service.service'; import { TransServiceService } from '../../../shared/services/trans-service.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import * as moment from 'moment';
@Component({ @Component({
selector: 'epic-explorer-graph-list', selector: 'epic-explorer-graph-list',
@ -16,6 +17,7 @@ export class GraphListComponent implements OnInit {
public areaGraphData: any = []; public areaGraphData: any = [];
public doubleareaGraphData: any = []; public doubleareaGraphData: any = [];
public barGraphData: any = []; public barGraphData: any = [];
public barGraphIntevalData: any = [];
public blockGraphData: any = []; public blockGraphData: any = [];
public bubbleGraphdData: any = []; public bubbleGraphdData: any = [];
public feeGraphData: any = []; public feeGraphData: any = [];
@ -25,6 +27,8 @@ export class GraphListComponent implements OnInit {
public stackGraphData: any = []; public stackGraphData: any = [];
public pieGraphData: any = []; public pieGraphData: any = [];
public linearTotalGraphData: any = []; public linearTotalGraphData: any = [];
public currenyIntervalDate: any;
public showcurrentIntervalDate: any;
public lg_last: any; public lg_last: any;
public ag_last: any = ''; public ag_last: any = '';
@ -38,6 +42,7 @@ export class GraphListComponent implements OnInit {
public hg_last: any = ''; public hg_last: any = '';
public sg_last: any = ''; public sg_last: any = '';
public pg_last: any = ''; public pg_last: any = '';
public blockinteval_last: any = '';
public selectedItem: Number = 6; public selectedItem: Number = 6;
public selectedItem3: Number = 1; public selectedItem3: Number = 1;
@ -53,6 +58,7 @@ export class GraphListComponent implements OnInit {
public selectedItem12: Number = 4; public selectedItem12: Number = 4;
public selectedTarget: Number = 6; public selectedTarget: Number = 6;
public selectedTarget12: Number = 4; public selectedTarget12: Number = 4;
public selectedInteverval: Number = 1;
public tInput: any; public tInput: any;
public tOutput: any; public tOutput: any;
@ -80,6 +86,8 @@ export class GraphListComponent implements OnInit {
this.Difficultyreq('total'); this.Difficultyreq('total');
this.blockreq(); this.blockreq();
this.Blockintervalreq();
/* Transcation fee chart fetching */ /* Transcation fee chart fetching */
this.Transcationreq(); this.Transcationreq();
@ -497,6 +505,49 @@ export class GraphListComponent implements OnInit {
}); });
} }
Blockintervalreq(interval = ''){
//interval = '2019-08-11';
if(interval == "today"){
this.currenyIntervalDate = moment(new Date()).format('YYYY-MM-DD');
this.showcurrentIntervalDate = moment(new Date()).format('MM-DD-YYYY');
}else if(interval == "yesterday"){
this.currenyIntervalDate = moment(new Date()).subtract(1, "days").format("YYYY-MM-DD");
this.showcurrentIntervalDate = moment(new Date()).subtract(1, "days").format("MM-DD-YYYY");
}else if(interval == "previous"){
var currentdate = this.currenyIntervalDate;
this.currenyIntervalDate = moment(currentdate).subtract(1, "days").format("YYYY-MM-DD");
this.showcurrentIntervalDate = moment(currentdate).subtract(1, "days").format("MM-DD-YYYY");
}else if(interval == "next"){
var currentdate = this.currenyIntervalDate;
this.currenyIntervalDate = moment(currentdate).add(1, "days").format("YYYY-MM-DD");
this.showcurrentIntervalDate = moment(currentdate).add(1, "days").format("MM-DD-YYYY");
}else{
this.currenyIntervalDate = moment(new Date()).format('YYYY-MM-DD');
this.showcurrentIntervalDate = moment(new Date()).format('MM-DD-YYYY');
}
// console.log(this.currenyIntervalDate);
// console.log(this.showcurrentIntervalDate);
interval = this.currenyIntervalDate;
return new Promise((resolve, reject) => {
let params = new HttpParams();
params = params.append('Interval', interval);
this.chartService
.apiGetRequest(params, '/blockchain_block/blockinterval')
.subscribe(
res => {
if (res['status'] == 200) {
let BlocksChartHeight = res.response.height;
let Blockval = res.response.alter;
this.blockinteval_last = Blockval[Blockval.length - 1];
this.BlocksIntevalFunc(BlocksChartHeight, Blockval);
resolve();
}
},
error => { },
);
});
}
blockreq( blockreq(
fromDate = '', fromDate = '',
ToDate = '', ToDate = '',
@ -535,7 +586,7 @@ export class GraphListComponent implements OnInit {
autosize: true, autosize: true,
showlegend: true, showlegend: true,
legend: {"orientation": "h", legend: {"orientation": "h",
x: 0.35, y: -0.5,font :{ 'size': 10}}, x: 0.1, y: -0.5,font :{ 'size': 10}},
xaxis: { xaxis: {
tickangle: -45, tickangle: -45,
tickformat: tickformat, tickformat: tickformat,
@ -704,6 +755,49 @@ export class GraphListComponent implements OnInit {
}; };
} }
BlocksIntevalFunc(BlocksChartHeight, Blockval) {
this.barGraphIntevalData = {
data: [
{
x: BlocksChartHeight,
y: Blockval,
text: Blockval,
name: '',
hovertemplate: 'Blocks %{x}<br> Inteval : %{text:,}',
type: 'bar',
marker: {
color: Blockval,
colorscale: 'Viridis',
},
},
],
layout: {
hovermode: 'closest',
height: 250,
autosize: true,
showlegend: false,
xaxis: {
tickangle: -45,
showgrid: true,
title: 'Blocks Height',
fixedrange: true
},
yaxis: {
title: 'Seonds',
showgrid: true,
fixedrange: true
},
margin: {
l: 50,
r: 50,
b: 50,
t: 50,
},
},
options: null,
};
}
totalBlocksFunc(DifficultychartDate, Blockval) { totalBlocksFunc(DifficultychartDate, Blockval) {
this.barGraphData = { this.barGraphData = {
@ -803,7 +897,7 @@ export class GraphListComponent implements OnInit {
}, },
text: gReward, text: gReward,
hovertemplate: hovertemplate:
'%{x}<br> supply per day: %{text:,}<br> Total supply: %{y:,}', '%{x}<br> supply per day : %{text:,}<br> Total supply : %{y:,}',
}, },
], ],
layout: { layout: {
@ -890,7 +984,7 @@ export class GraphListComponent implements OnInit {
x: mDate, x: mDate,
y: Cuckooper, y: Cuckooper,
text: Cuckoo, text: Cuckoo,
hovertemplate: 'Cuckoo :%{y} % ( %{text:,} )', hovertemplate: 'Cuckoo : %{y} % ( %{text:,} )',
hoverlabel: {namelength : 0}, hoverlabel: {namelength : 0},
name: 'Cuckoo', name: 'Cuckoo',
fill: 'tozeroy', fill: 'tozeroy',
@ -915,7 +1009,7 @@ export class GraphListComponent implements OnInit {
x: mDate, x: mDate,
y: RandomXper, y: RandomXper,
text: RandomX, text: RandomX,
hovertemplate: 'RandomX :%{y} % ( %{text:,} )', hovertemplate: 'RandomX : %{y} % ( %{text:,} )',
hoverlabel: {namelength : 0}, hoverlabel: {namelength : 0},
fill: 'tozeroy', fill: 'tozeroy',
type: 'line', type: 'line',
@ -928,7 +1022,7 @@ export class GraphListComponent implements OnInit {
x: mDate, x: mDate,
y: ProgPowper, y: ProgPowper,
text: ProgPow, text: ProgPow,
hovertemplate: 'ProgPow :%{y} % ( %{text:,} )', hovertemplate: 'ProgPow : %{y} % ( %{text:,} )',
hoverlabel: {namelength : 0}, hoverlabel: {namelength : 0},
fill: 'tozeroy', fill: 'tozeroy',
type: 'line', type: 'line',
@ -1093,7 +1187,7 @@ export class GraphListComponent implements OnInit {
}, },
showlegend: true, showlegend: true,
legend: {"orientation": "h", legend: {"orientation": "h",
x: 0.35, y: -0.5,font :{ 'size': 10}} x: 0.05, y: -0.5,font :{ 'size': 10}}
}, },
options: null, options: null,
}; };
@ -1158,7 +1252,7 @@ export class GraphListComponent implements OnInit {
autosize: true, autosize: true,
showlegend: true, showlegend: true,
legend: {"orientation": "h", legend: {"orientation": "h",
x: 0.35, y: -0.5,font :{ 'size': 10}}, x: 0.1, y: -0.5,font :{ 'size': 10}},
xaxis: { xaxis: {
tickangle: -45, tickangle: -45,
tickformat: tickformat, tickformat: tickformat,