File tree Expand file tree Collapse file tree 3 files changed +30
-8
lines changed
Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -164,18 +164,23 @@ defmodule Batches do
164164 end
165165 end
166166
167- def get_verified_proofs_in_last_24_hours ( ) do
167+ def get_last_24h_verified_proof_stats ( ) do
168168 minutes_in_a_day = 1440
169169 threshold_datetime = DateTime . utc_now ( ) |> DateTime . add ( - 1 * minutes_in_a_day , :minute ) # Last 24 hours
170170
171171 query = from ( b in Batches ,
172172 where: b . is_verified == true and b . submission_timestamp > ^ threshold_datetime ,
173- select: sum ( b . amount_of_proofs ) )
173+ select: { sum ( b . amount_of_proofs ) , avg ( b . fee_per_proof ) } )
174174
175- case Explorer.Repo . one ( query ) do
176- nil -> 0
175+ { amount_of_proofs , avg_fee_per_proof } = case Explorer.Repo . one ( query ) do
176+ nil -> { 0 , 0.0 }
177177 result -> result
178178 end
179+
180+ % {
181+ amount_of_proofs: amount_of_proofs ,
182+ avg_fee_per_proof: avg_fee_per_proof
183+ }
179184 end
180185
181186 def insert_or_update ( batch_changeset , proofs ) do
Original file line number Diff line number Diff line change @@ -2,7 +2,20 @@ defmodule ExplorerWeb.DataController do
22 use ExplorerWeb , :controller
33
44 def verified_proofs_in_last_24_hours ( conn , _params ) do
5- verified_proofs_in_last_24_hours = Batches . get_verified_proofs_in_last_24_hours ( )
6- render ( conn , :show , count: verified_proofs_in_last_24_hours )
5+ % {
6+ amount_of_proofs: amount_of_proofs ,
7+ avg_fee_per_proof: avg_fee_per_proof
8+ } = Batches . get_last_24h_verified_proof_stats ( )
9+
10+ avg_fee_per_proof_usd =
11+ case EthConverter . wei_to_usd_sf ( avg_fee_per_proof , 2 ) do
12+ { :ok , value } -> value
13+ _ -> 0
14+ end
15+
16+ render ( conn , :show , % {
17+ amount_of_proofs: amount_of_proofs ,
18+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
19+ } )
720 end
821end
Original file line number Diff line number Diff line change 11defmodule ExplorerWeb.DataJSON do
2- def show ( % { count: last_verified_proofs_count } ) do
2+ def show ( % {
3+ amount_of_proofs: amount_of_proofs ,
4+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
5+ } ) do
36 % {
4- count: last_verified_proofs_count
7+ amount_of_proofs: amount_of_proofs ,
8+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
59 }
610 end
711end
You can’t perform that action at this time.
0 commit comments