adding txns & fees chart

This commit is contained in:
aglkm
2024-09-23 02:24:17 +03:00
parent d625738c7f
commit 3a08d82902
5 changed files with 118 additions and 17 deletions

View File

@@ -216,22 +216,29 @@ impl Output {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct Statistics { pub struct Statistics {
pub timing: u32, pub timing: u32,
pub date: Vec<String>,
// Node versions
pub user_agent: Vec<String>, pub user_agent: Vec<String>,
pub count: Vec<String>, pub count: Vec<String>,
pub total: u32, pub total: u32,
// Hashrate
pub hashrate: Vec<String>, pub hashrate: Vec<String>,
pub hash_date: Vec<String>, // Transactions & fees
pub txns: Vec<String>,
pub fees: Vec<String>,
} }
impl Statistics { impl Statistics {
pub fn new() -> Statistics { pub fn new() -> Statistics {
Statistics { Statistics {
timing: 0, timing: 0,
user_agent: Vec::new(), date: Vec::new(),
count: Vec::new(), user_agent: Vec::new(),
total: 0, count: Vec::new(),
hashrate: Vec::new(), total: 0,
hash_date: Vec::new(), hashrate: Vec::new(),
txns: Vec::new(),
fees: Vec::new(),
} }
} }
} }

View File

@@ -220,11 +220,13 @@ fn stats(statistics: &State<Arc<Mutex<Statistics>>>) -> Template {
Template::render("stats", context! { Template::render("stats", context! {
route: "stats", route: "stats",
date: data.date.clone(),
user_agent: data.user_agent.clone(), user_agent: data.user_agent.clone(),
count: data.count.clone(), count: data.count.clone(),
total: data.total, total: data.total,
hashrate: data.hashrate.clone(), hashrate: data.hashrate.clone(),
hash_date: data.hash_date.clone(), txns: data.txns.clone(),
fees: data.fees.clone(),
}) })
} }

View File

@@ -384,13 +384,7 @@ pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>, statistics: Arc<
} }
stats.hashrate.push(format!("{:.2}", hashrate / 1000.0)); stats.hashrate.push(format!("{:.2}", hashrate / 1000.0));
stats.hash_date.push(format!("\"{}\"", Utc::now().format("%d-%m-%Y")));
stats.timing = 0;
} }
// Increasing timing by 15 seconds (our data update period)
stats.timing = stats.timing + 15;
} }
} }
@@ -636,7 +630,8 @@ pub async fn get_block_kernels(height: &String, blocks: &mut Vec<Block>)
// Collecting: period_1h, period_24h, fees_1h, fees_24h. // Collecting: period_1h, period_24h, fees_1h, fees_24h.
pub async fn get_txn_stats(dashboard: Arc<Mutex<Dashboard>>, pub async fn get_txn_stats(dashboard: Arc<Mutex<Dashboard>>,
transactions: Arc<Mutex<Transactions>>) -> Result<(), Error> { transactions: Arc<Mutex<Transactions>>,
statistics: Arc<Mutex<Statistics>>)-> Result<(), Error> {
let mut blocks = Vec::<Block>::new(); let mut blocks = Vec::<Block>::new();
let height = get_current_height(dashboard.clone()); let height = get_current_height(dashboard.clone());
@@ -682,6 +677,19 @@ pub async fn get_txn_stats(dashboard: Arc<Mutex<Dashboard>>,
txns.period_24h = ker_count_24h.to_string(); txns.period_24h = ker_count_24h.to_string();
txns.fees_1h = format!("{:.2}", fees_1h / 1000000000.0); txns.fees_1h = format!("{:.2}", fees_1h / 1000000000.0);
txns.fees_24h = format!("{:.2}", fees_24h / 1000000000.0); txns.fees_24h = format!("{:.2}", fees_24h / 1000000000.0);
let mut stats = statistics.lock().unwrap();
// Save txns into statistics every 24H
if stats.timing == 0 || stats.timing >= 86400 {
if stats.txns.len() == 30 {
stats.txns.remove(0);
stats.fees.remove(0);
}
stats.txns.push(txns.period_24h.clone());
stats.fees.push(txns.fees_24h.clone());
}
} }
} }

View File

@@ -1,3 +1,4 @@
use chrono::Utc;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use crate::data::Block; use crate::data::Block;
@@ -19,7 +20,18 @@ pub async fn run(dash: Arc<Mutex<Dashboard>>, blocks: Arc<Mutex<Vec<Block>>>,
requests::get_disk_usage(dash.clone())?; requests::get_disk_usage(dash.clone())?;
let _ = requests::get_mining_stats(dash.clone(), stats.clone()).await?; let _ = requests::get_mining_stats(dash.clone(), stats.clone()).await?;
let _ = requests::get_recent_blocks(dash.clone(), blocks.clone()).await?; let _ = requests::get_recent_blocks(dash.clone(), blocks.clone()).await?;
let _ = requests::get_txn_stats(dash.clone(), txns.clone()).await?; let _ = requests::get_txn_stats(dash.clone(), txns.clone(), stats.clone()).await?;
let mut stats = stats.lock().unwrap();
// Push new date and restart timer every 24H
if stats.timing == 0 || stats.timing >= 86400 {
stats.date.push(format!("\"{}\"", Utc::now().format("%d-%m-%Y")));
stats.timing = 0;
}
// Increasing timing by 15 seconds (data update period)
stats.timing = stats.timing + 15;
Ok(()) Ok(())
} }

View File

@@ -24,6 +24,15 @@
</div> </div>
</div> </div>
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
<div class="card-body" align="center">
<div class="value-text">
<div class="darkorange-text"><i class="bi bi-speedometer2"></i> TRANSACTIONS & FEES</div>
<div style="position: relative; height:60vh; width:90vw"><canvas id="3"></canvas></div>
</div>
</div>
</div>
</code> </code>
<script> <script>
@@ -60,6 +69,7 @@
options: options options: options
}); });
<!-- Hashrate Chart --> <!-- Hashrate Chart -->
var options = { var options = {
maintainAspectRatio: false, maintainAspectRatio: false,
@@ -70,11 +80,23 @@
legend: { legend: {
display: false display: false
}, },
},
scales: {
x: {
grid: {
display: false
}
},
y: {
grid: {
display: false
}
},
} }
}; };
var data = { var data = {
labels: {{ hash_date }}, labels: {{ date }},
datasets: [{ datasets: [{
label: 'Hashrate (kG/s)', label: 'Hashrate (kG/s)',
data: {{ hashrate }}, data: {{ hashrate }},
@@ -91,6 +113,56 @@
options: options options: options
}); });
<!-- Transactions & Fees Chart -->
var options = {
maintainAspectRatio: false,
interaction: {
intersect: false,
},
plugins: {
legend: {
display: true
},
},
scales: {
x: {
grid: {
display: false
}
},
y: {
grid: {
display: false
}
},
}
};
var data = {
labels: {{ date }},
datasets: [
{
label: 'Transactions',
data: {{ txns }},
fill: false,
tension: 0.1
},
{
label: 'Fees',
data: {{ fees }},
fill: false,
tension: 0.1
}
]
};
new Chart(document.getElementById("3"), {
type: 'line',
data: data,
options: options
});
</script> </script>