Skip to content

Commit 5d57299

Browse files
author
Peter Pratscher
committed
Generate statistics always for the current and previous day
1 parent 1f023e9 commit 5d57299

File tree

7 files changed

+10
-29
lines changed

7 files changed

+10
-29
lines changed

db/db.go

-7
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,6 @@ func GenerateAndSaveStatistics(date time.Time) error {
582582
return fmt.Errorf("error executing %s statistics query for day %v: %w", indicator, startDate, err)
583583
}
584584

585-
// Total number of active staked coda per day
586-
indicator = "TOTAL_STAKED"
587-
_, err = tx.Exec(`INSERT INTO statistics (indicator, ts, value) SELECT $1, $2, COALESCE(sum(balance), 0) from accounts where publickey in (select distinct creator from blocks where ts >= $2 AND ts <= $3) ON CONFLICT (indicator, ts) DO UPDATE SET value = EXCLUDED.value;`, indicator, startDate, endDate)
588-
if err != nil {
589-
return fmt.Errorf("error executing %s statistics query for day %v: %w", indicator, startDate, err)
590-
}
591-
592585
err = tx.Commit()
593586
if err != nil {
594587
return fmt.Errorf("error committing statistics transaction for day %v: %w", startDate, err)

indexer/indexer.go

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func updateStatistics(intv time.Duration) {
5656
if err != nil {
5757
logger.Errorf("error generating statistics: %w", err)
5858
}
59+
err = db.GenerateAndSaveStatistics(time.Now())
60+
if err != nil {
61+
logger.Errorf("error generating statistics: %w", err)
62+
}
5963
}
6064
}
6165
}

services/services.go

-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ func getIndexPageData() (*types.IndexPageData, error) {
120120
return nil, fmt.Errorf("error retrieving active validators data: %w", err)
121121
}
122122

123-
err = db.DB.Get(&data.TotalStaked, "select COALESCE(sum(balance), 0) from accounts where publickey in (select distinct creator from blocks where ts > now() - interval '1 day');")
124-
if err != nil {
125-
return nil, fmt.Errorf("error retrieving total staked data: %w", err)
126-
}
127-
128123
err = db.DB.Get(&data.Peers, "select peerscount from daemonstatus order by ts desc limit 1;")
129124
if err != nil {
130125
return nil, fmt.Errorf("error retrieving peerscount data: %w", err)

templates/accounts.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-user mr-2"></i>Accounts</h1>
6161
<tr>
6262
<th>Address</th>
6363
<th>Balance</th>
64-
<th>First Seen</th>
65-
<th>Last Seen</th>
64+
<th>Added to Ledger</th>
65+
<th>Most Recent Activity</th>
6666
<th>Block proposed</th>
6767
<th>Snark Jobs</th>
6868
<th>Tx Sent</th>

templates/charts.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@
5050
return numbro(val).format({thousandSeparated: true});
5151
}))
5252

53-
charts.push(drawChart([{name: "Total Staked", data: chartData["TOTAL_STAKED"]}], "Total Staked", "#chart-total-staked", function (val) {
54-
return numbro(val).format({thousandSeparated: true});
55-
}))
56-
57-
charts.push(drawChart([{name: "Peers Seen", data: chartData["PEERS"]}], "Peers Seen", "#chart-peers", function (val) {
53+
charts.push(drawChart([{name: "Daily Peers Seen", data: chartData["PEERS"]}], "Daily Peers Seen", "#chart-peers", function (val) {
5854
return val;
5955
}))
6056

@@ -137,10 +133,10 @@ <h1 class="h4 mb-1 mb-md-0">
137133
<div id="chart-new-accounts" class="border-bottom mb-2"></div>
138134
<div id="chart-snark-workers" class="border-bottom mb-2"></div>
139135
<div id="chart-snark-fees" class="border-bottom mb-2"></div>
140-
<div id="chart-total-staked" class="border-bottom mb-2"></div>
141136
<div id="chart-peers" class="border-bottom mb-2"></div>
142137
<span class="ml-2" style="font-size: 14px; font-weight: 900; font-family: Helvetica, Arial, sans-serif; opacity: 1;">Peer Map</span>
143138
<div id="map-peers" class="border-bottom mb-2" style="position: relative; margin: 0 auto; width: 750px; height: 500px;"></div>
139+
<small class="text-muted">This site includes IP2Location LITE data available from <a href="https://lite.ip2location.com">https://lite.ip2location.com</a>.</small>
144140
</div>
145141
</div>
146142
{{end}}

templates/index.html

+2-8
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ <h5 class="font-weight-normal mb-0">
183183
<span data-toggle="tooltip" data-placement="top" title="The number of currently active validators">${ page.active_validators }</span>
184184
</h5>
185185
</div>
186-
<div class="text-center p-2">
187-
<div class="text-secondary mb-0">Peers</div>
188-
<h5 class="font-weight-normal mb-0">
189-
<span data-toggle="tooltip" data-placement="top" title="The most recent slot">${ page.peers }</span>
190-
</h5>
191-
</div>
192186
<div class="text-right p-2">
193187
<div class="text-secondary mb-0">Active Snark Workers</div>
194188
<h5 class="font-weight-normal mb-0">
@@ -200,9 +194,9 @@ <h5 class="font-weight-normal mb-0">
200194
<div class="col-md-4">
201195
<div class="d-flex justify-content-between">
202196
<div class="p-2">
203-
<div class="text-secondary mb-0">Staked Coda</div>
197+
<div class="text-secondary mb-0">Peers</div>
204198
<h5 class="font-weight-normal mb-0">
205-
<span data-toggle="tooltip" data-placement="top" title="Lower bound of the amount of coda currently staking">${ page.total_staked | formatCurrency }</span>
199+
<span data-toggle="tooltip" data-placement="top" title="The most recent slot">${ page.peers }</span>
206200
</h5>
207201
</div>
208202
<div class="text-right p-2">

types/templates.go

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ type IndexPageData struct {
4949
CurrentHeight int `json:"current_height"`
5050
ActiveValidators int `json:"active_validators"`
5151
ActiveWorkers int `json:"active_workers"`
52-
TotalStaked int `json:"total_staked"`
5352
TotalSupply int `json:"total_supply"`
5453
Peers int `json:"peers"`
5554
Blocks []*Block `json:"blocks"`

0 commit comments

Comments
 (0)