mirror of
https://github.com/transatoshi-mw/grin-explorer.git
synced 2025-10-21 05:23:41 +00:00
charts code refactoring
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
|
||||
// Dashboard data
|
||||
#[derive(Debug)]
|
||||
pub struct Dashboard {
|
||||
@@ -215,7 +214,6 @@ impl Output {
|
||||
// Statistics data
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Statistics {
|
||||
pub timing: u32,
|
||||
pub date: Vec<String>,
|
||||
// Node versions
|
||||
pub user_agent: Vec<String>,
|
||||
@@ -231,7 +229,6 @@ pub struct Statistics {
|
||||
impl Statistics {
|
||||
pub fn new() -> Statistics {
|
||||
Statistics {
|
||||
timing: 0,
|
||||
date: Vec::new(),
|
||||
user_agent: Vec::new(),
|
||||
count: Vec::new(),
|
||||
|
@@ -377,8 +377,8 @@ pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>, statistics: Arc<
|
||||
|
||||
let mut stats = statistics.lock().unwrap();
|
||||
|
||||
// Save hashrate into statistics every 24H
|
||||
if stats.timing == 0 || stats.timing >= 86400 {
|
||||
// Collect stats every day, by checking if new date was pushed into the date vector
|
||||
if stats.date.len() != stats.hashrate.len() {
|
||||
if stats.hashrate.len() == 30 {
|
||||
stats.hashrate.remove(0);
|
||||
}
|
||||
@@ -680,8 +680,8 @@ pub async fn get_txn_stats(dashboard: Arc<Mutex<Dashboard>>,
|
||||
|
||||
let mut stats = statistics.lock().unwrap();
|
||||
|
||||
// Save txns into statistics every 24H
|
||||
if stats.timing == 0 || stats.timing >= 86400 {
|
||||
// Collect stats every day, by checking if new date was pushed into the date vector
|
||||
if stats.date.len() != stats.txns.len() {
|
||||
if stats.txns.len() == 30 {
|
||||
stats.txns.remove(0);
|
||||
stats.fees.remove(0);
|
||||
|
@@ -24,15 +24,17 @@ pub async fn run(dash: Arc<Mutex<Dashboard>>, blocks: Arc<Mutex<Vec<Block>>>,
|
||||
|
||||
let mut stats = stats.lock().unwrap();
|
||||
|
||||
// Push new date and restart timer every 24H
|
||||
if stats.timing == 0 || stats.timing >= 86400 {
|
||||
// Every day push new date into the vector
|
||||
if let Some(v) = stats.date.last() {
|
||||
// If new day, pushing date into the vector
|
||||
if *v != format!("\"{}\"", Utc::now().format("%d-%m-%Y")) {
|
||||
stats.date.push(format!("\"{}\"", Utc::now().format("%d-%m-%Y")));
|
||||
}
|
||||
} else {
|
||||
// Vector is empty, pushing current date
|
||||
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(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user