From 3edd6f23a556edcc34795f981114d4af6dffa2dd Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 16 Jul 2022 11:32:48 +0200 Subject: [PATCH] Add capacity per AS --- backend/src/api/explorer/nodes.api.ts | 7 +++++-- .../nodes-per-as-chart.component.html | 16 +++++++++------- .../nodes-per-as-chart.component.ts | 6 +++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index 3bfa4d50e..c3b3f8124 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -96,10 +96,12 @@ class NodesApi { public async $getNodesAsShare() { try { - let query = `SELECT names, COUNT(*) as nodesCount from nodes + let query = `SELECT names, COUNT(DISTINCT nodes.public_key) as nodesCount, SUM(capacity) as capacity + FROM nodes JOIN geo_names ON geo_names.id = nodes.as_number + JOIN channels ON channels.node1_public_key = nodes.public_key OR channels.node2_public_key = nodes.public_key GROUP BY as_number - ORDER BY COUNT(*) DESC + ORDER BY COUNT(DISTINCT nodes.public_key) DESC `; const [nodesCountPerAS]: any = await DB.query(query); @@ -112,6 +114,7 @@ class NodesApi { name: JSON.parse(as.names), count: as.nodesCount, share: Math.floor(as.nodesCount / nodesWithAS[0].total * 10000) / 100, + capacity: as.capacity, }) } diff --git a/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.html b/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.html index 16ba4fea6..3ea6f1e29 100644 --- a/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.html +++ b/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.html @@ -21,18 +21,20 @@ - - - - + + + + + - + - - + + +
RankNameHashrateNodesRankNameShareNodesCapacity
{{ asEntry.rank }}{{ asEntry.rank }} {{ asEntry.name }}{{ asEntry.share }}%{{ asEntry.count }}{{ asEntry.share }}%{{ asEntry.count }}
diff --git a/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.ts b/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.ts index cc8d5e759..ac94dfac4 100644 --- a/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.ts +++ b/frontend/src/app/lightning/nodes-per-as-chart/nodes-per-as-chart.component.ts @@ -5,6 +5,7 @@ import { chartColors } from 'src/app/app.constants'; import { ApiService } from 'src/app/services/api.service'; import { SeoService } from 'src/app/services/seo.service'; import { download } from 'src/app/shared/graphs.utils'; +import { AmountShortenerPipe } from 'src/app/shared/pipes/amount-shortener.pipe'; @Component({ selector: 'app-nodes-per-as-chart', @@ -30,6 +31,7 @@ export class NodesPerAsChartComponent implements OnInit { constructor( private apiService: ApiService, private seoService: SeoService, + private amountShortenerPipe: AmountShortenerPipe ) { } @@ -89,7 +91,9 @@ export class NodesPerAsChartComponent implements OnInit { borderColor: '#000', formatter: () => { return `${as.name} (${as.share}%)
` + - $localize`${as.count.toString()} nodes`; + $localize`${as.count.toString()} nodes
` + + $localize`${this.amountShortenerPipe.transform(as.capacity / 100000000, 2)} BTC capacity` + ; } }, data: as.slug,