Merge branch 'master' into junderw/fix-paths

This commit is contained in:
wiz 2023-11-12 17:22:39 +09:00 committed by GitHub
commit ee90a96d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 54 deletions

View File

@ -81,6 +81,7 @@ class Blocks {
private async $getTransactionsExtended( private async $getTransactionsExtended(
blockHash: string, blockHash: string,
blockHeight: number, blockHeight: number,
blockTime: number,
onlyCoinbase: boolean, onlyCoinbase: boolean,
txIds: string[] | null = null, txIds: string[] | null = null,
quiet: boolean = false, quiet: boolean = false,
@ -101,6 +102,12 @@ class Blocks {
if (!onlyCoinbase) { if (!onlyCoinbase) {
for (const txid of txIds) { for (const txid of txIds) {
if (mempool[txid]) { if (mempool[txid]) {
mempool[txid].status = {
confirmed: true,
block_height: blockHeight,
block_hash: blockHash,
block_time: blockTime,
};
transactionMap[txid] = mempool[txid]; transactionMap[txid] = mempool[txid];
foundInMempool++; foundInMempool++;
totalFound++; totalFound++;
@ -608,7 +615,7 @@ class Blocks {
} }
const blockHash = await bitcoinApi.$getBlockHash(blockHeight); const blockHash = await bitcoinApi.$getBlockHash(blockHeight);
const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash);
const transactions = await this.$getTransactionsExtended(blockHash, block.height, true, null, true); const transactions = await this.$getTransactionsExtended(blockHash, block.height, block.timestamp, true, null, true);
const blockExtended = await this.$getBlockExtended(block, transactions); const blockExtended = await this.$getBlockExtended(block, transactions);
newlyIndexed++; newlyIndexed++;
@ -701,7 +708,7 @@ class Blocks {
const verboseBlock = await bitcoinClient.getBlock(blockHash, 2); const verboseBlock = await bitcoinClient.getBlock(blockHash, 2);
const block = BitcoinApi.convertBlock(verboseBlock); const block = BitcoinApi.convertBlock(verboseBlock);
const txIds: string[] = verboseBlock.tx.map(tx => tx.txid); const txIds: string[] = verboseBlock.tx.map(tx => tx.txid);
const transactions = await this.$getTransactionsExtended(blockHash, block.height, false, txIds, false, true) as MempoolTransactionExtended[]; const transactions = await this.$getTransactionsExtended(blockHash, block.height, block.timestamp, false, txIds, false, true) as MempoolTransactionExtended[];
// fill in missing transaction fee data from verboseBlock // fill in missing transaction fee data from verboseBlock
for (let i = 0; i < transactions.length; i++) { for (let i = 0; i < transactions.length; i++) {
@ -890,7 +897,7 @@ class Blocks {
const blockHash = await bitcoinApi.$getBlockHash(height); const blockHash = await bitcoinApi.$getBlockHash(height);
const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash);
const transactions = await this.$getTransactionsExtended(blockHash, block.height, true); const transactions = await this.$getTransactionsExtended(blockHash, block.height, block.timestamp, true);
const blockExtended = await this.$getBlockExtended(block, transactions); const blockExtended = await this.$getBlockExtended(block, transactions);
if (Common.indexingEnabled()) { if (Common.indexingEnabled()) {
@ -902,7 +909,7 @@ class Blocks {
public async $indexStaleBlock(hash: string): Promise<BlockExtended> { public async $indexStaleBlock(hash: string): Promise<BlockExtended> {
const block: IEsploraApi.Block = await bitcoinApi.$getBlock(hash); const block: IEsploraApi.Block = await bitcoinApi.$getBlock(hash);
const transactions = await this.$getTransactionsExtended(hash, block.height, true); const transactions = await this.$getTransactionsExtended(hash, block.height, block.timestamp, true);
const blockExtended = await this.$getBlockExtended(block, transactions); const blockExtended = await this.$getBlockExtended(block, transactions);
blockExtended.canonical = await bitcoinApi.$getBlockHash(block.height); blockExtended.canonical = await bitcoinApi.$getBlockHash(block.height);

View File

@ -63,7 +63,8 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On
return; return;
} }
this.windowPreference = this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference'); this.windowPreference = this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference');
this.MA = this.calculateMA(this.data.series[0]); const windowSize = Math.max(10, Math.floor(this.data.series[0].length / 8));
this.MA = this.calculateMA(this.data.series[0], windowSize);
this.mountChart(); this.mountChart();
} }
@ -74,33 +75,22 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On
this.isLoading = false; this.isLoading = false;
} }
/// calculate the moving average of maData /// calculate the moving average of the provided data based on windowSize
calculateMA(maData): number[][] { calculateMA(data: number[][], windowSize: number = 100): number[][] {
//update const variables that are not changed //update const variables that are not changed
const ma: number[][] = []; const ma: number[][] = [];
let sum = 0; let sum = 0;
let i = 0; let i = 0;
const len = maData.length;
//Adjust window length based on the length of the data
//5% appeared as a good amount from tests
//TODO: make this a text box in the UI
const maWindowLen = Math.ceil(len * 0.05);
//calculate the center of the moving average window
const center = Math.floor(maWindowLen / 2);
//calculate the centered moving average //calculate the centered moving average
for (i = center; i < len - center; i++) { for (i = 0; i < data.length; i++) {
sum = 0; sum += data[i][1];
//build out ma as we loop through the data if (i >= windowSize) {
ma[i] = []; sum -= data[i - windowSize][1];
ma[i].push(maData[i][0]); const midpoint = i - Math.floor(windowSize / 2);
for (let j = i - center; j <= i + center; j++) { const avg = sum / windowSize;
sum += maData[j][1]; ma.push([data[midpoint][0], avg]);
} }
ma[i].push(sum / maWindowLen);
} }
//return the moving average array //return the moving average array
@ -138,36 +128,22 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On
} }
}], }],
} }
}, });
{ if (this.template !== 'widget') {
zlevel: 0, seriesGraph.push({
name: 'MA', zlevel: 0,
data: this.MA, name: 'MA',
type: 'line', data: this.MA,
smooth: false, type: 'line',
showSymbol: false, smooth: false,
symbol: 'none', showSymbol: false,
lineStyle: {
width: 1,
color: "white",
},
markLine: {
silent: true,
symbol: 'none', symbol: 'none',
lineStyle: { lineStyle: {
color: '#fff',
opacity: 1,
width: 2, width: 2,
}, color: "white",
data: [{ }
yAxis: 1667, });
label: { }
show: false,
color: '#ffffff',
}
}],
}
});
this.mempoolStatsChartOption = { this.mempoolStatsChartOption = {
grid: { grid: {

View File

@ -1,7 +1,7 @@
// Import tree-shakeable echarts // Import tree-shakeable echarts
import * as echarts from 'echarts/core'; import * as echarts from 'echarts/core';
import { LineChart, LinesChart, BarChart, TreemapChart, PieChart, ScatterChart } from 'echarts/charts'; import { LineChart, LinesChart, BarChart, TreemapChart, PieChart, ScatterChart } from 'echarts/charts';
import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, GeoComponent, DataZoomComponent, VisualMapComponent } from 'echarts/components'; import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, GeoComponent, DataZoomComponent, VisualMapComponent, MarkLineComponent } from 'echarts/components';
import { SVGRenderer, CanvasRenderer } from 'echarts/renderers'; import { SVGRenderer, CanvasRenderer } from 'echarts/renderers';
// Typescript interfaces // Typescript interfaces
import { EChartsOption, TreemapSeriesOption, LineSeriesOption, PieSeriesOption } from 'echarts'; import { EChartsOption, TreemapSeriesOption, LineSeriesOption, PieSeriesOption } from 'echarts';
@ -11,7 +11,7 @@ echarts.use([
SVGRenderer, CanvasRenderer, SVGRenderer, CanvasRenderer,
TitleComponent, TooltipComponent, GridComponent, TitleComponent, TooltipComponent, GridComponent,
LegendComponent, GeoComponent, DataZoomComponent, LegendComponent, GeoComponent, DataZoomComponent,
VisualMapComponent, VisualMapComponent, MarkLineComponent,
LineChart, LinesChart, BarChart, TreemapChart, PieChart, ScatterChart LineChart, LinesChart, BarChart, TreemapChart, PieChart, ScatterChart
]); ]);
export { echarts, EChartsOption, TreemapSeriesOption, LineSeriesOption, PieSeriesOption }; export { echarts, EChartsOption, TreemapSeriesOption, LineSeriesOption, PieSeriesOption };