mirror of
https://github.com/transatoshi-mw/grin-explorer.git
synced 2025-10-21 21:43:40 +00:00
adding hashrate chart
This commit is contained in:
14
src/data.rs
14
src/data.rs
@@ -213,19 +213,25 @@ impl Output {
|
|||||||
|
|
||||||
|
|
||||||
// Statistics data
|
// Statistics data
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Statistics {
|
pub struct Statistics {
|
||||||
|
pub timing: u32,
|
||||||
pub user_agent: Vec<String>,
|
pub user_agent: Vec<String>,
|
||||||
pub count: Vec<String>,
|
pub count: Vec<String>,
|
||||||
pub total: u32,
|
pub total: u32,
|
||||||
|
pub hashrate: Vec<String>,
|
||||||
|
pub hash_date: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Statistics {
|
impl Statistics {
|
||||||
pub fn new() -> Statistics {
|
pub fn new() -> Statistics {
|
||||||
Statistics {
|
Statistics {
|
||||||
user_agent: Vec::new(),
|
timing: 0,
|
||||||
count: Vec::new(),
|
user_agent: Vec::new(),
|
||||||
total: 0,
|
count: Vec::new(),
|
||||||
|
total: 0,
|
||||||
|
hashrate: Vec::new(),
|
||||||
|
hash_date: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -223,6 +223,8 @@ fn stats(statistics: &State<Arc<Mutex<Statistics>>>) -> Template {
|
|||||||
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(),
|
||||||
|
hash_date: data.hash_date.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -325,7 +325,7 @@ pub fn get_disk_usage(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), Error> {
|
|||||||
|
|
||||||
|
|
||||||
// Collecting: hashrate, difficulty, production cost, breakeven cost.
|
// Collecting: hashrate, difficulty, production cost, breakeven cost.
|
||||||
pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), anyhow::Error> {
|
pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>, statistics: Arc<Mutex<Statistics>>) -> Result<(), anyhow::Error> {
|
||||||
let difficulty_window = 1440;
|
let difficulty_window = 1440;
|
||||||
let height = get_current_height(dashboard.clone());
|
let height = get_current_height(dashboard.clone());
|
||||||
|
|
||||||
@@ -374,6 +374,23 @@ pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), an
|
|||||||
/ (120.0 / 1000.0 * (1.0 / coins_per_hour)));
|
/ (120.0 / 1000.0 * (1.0 / coins_per_hour)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut stats = statistics.lock().unwrap();
|
||||||
|
|
||||||
|
// Save hashrate into statistics every 24H
|
||||||
|
if stats.timing == 0 || stats.timing >= 86400 {
|
||||||
|
if stats.hashrate.len() == 30 {
|
||||||
|
stats.hashrate.remove(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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ pub async fn run(dash: Arc<Mutex<Dashboard>>, blocks: Arc<Mutex<Vec<Block>>>,
|
|||||||
let _ = requests::get_connected_peers(dash.clone(), stats.clone()).await?;
|
let _ = requests::get_connected_peers(dash.clone(), stats.clone()).await?;
|
||||||
let _ = requests::get_market(dash.clone()).await?;
|
let _ = requests::get_market(dash.clone()).await?;
|
||||||
requests::get_disk_usage(dash.clone())?;
|
requests::get_disk_usage(dash.clone())?;
|
||||||
let _ = requests::get_mining_stats(dash.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()).await?;
|
||||||
|
|
||||||
|
@@ -9,95 +9,30 @@
|
|||||||
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
|
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||||
<div class="card-body" align="center">
|
<div class="card-body" align="center">
|
||||||
<div class="value-text">
|
<div class="value-text">
|
||||||
<div class="darkorange-text"><i class="bi bi-pc-display-horizontal"></i> NODE VERSION STATS ({{ total }})</div>
|
<div class="darkorange-text"><i class="bi bi-pc-display-horizontal"></i> NODE VERSIONS ({{ total }})</div>
|
||||||
<div style="position: relative; height:60vh; width:90vw"><canvas id="1"></canvas></div>
|
<div style="position: relative; height:60vh; width:90vw"><canvas id="1"></canvas></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-none d-sm-block"> <!-- Show on >= sm screens -->
|
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||||
<div class="card-group">
|
<div class="card-body" align="center">
|
||||||
<div class="card border-start-0 rounded-0">
|
<div class="value-text">
|
||||||
<div class="card-body">
|
<div class="darkorange-text"><i class="bi bi-pc-display-horizontal"></i> HASHRATE (kG/s)</div>
|
||||||
<div class="darkorange-text">
|
<div style="position: relative; height:60vh; width:90vw"><canvas id="2"></canvas></div>
|
||||||
#
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card rounded-0">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="darkorange-text">
|
|
||||||
VERSION
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card border-end-0 rounded-0">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="darkorange-text">
|
|
||||||
COUNT
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% for v in user_agent %}
|
|
||||||
<div class="card-group rounded-0">
|
|
||||||
<div class="card border-top-0 border-start-0 rounded-0">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="value-text">
|
|
||||||
{{ loop.index }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card border-top-0 rounded-0">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="value-text">
|
|
||||||
{{ v }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card border-top-0 border-end-0 rounded-0">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="value-text">
|
|
||||||
{{ count[loop.index0] }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-sm-none"> <!-- Show on < sm screens-->
|
|
||||||
{% for v in user_agent %}
|
|
||||||
{% if loop.index0 == 0 %}
|
|
||||||
<div class="card border-start-0 border-end-0 rounded-0">
|
|
||||||
{% else %}
|
|
||||||
<div class="card border-top-0 border-start-0 border-end-0 rounded-0">
|
|
||||||
{% endif %}
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="d-flex justify-content-start">
|
|
||||||
<div class="darkorange-text">
|
|
||||||
#{{ loop.index }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="d-flex justify-content-between">
|
|
||||||
<div class="value-text">
|
|
||||||
{{ v }}
|
|
||||||
</div>
|
|
||||||
<div class="value-text">
|
|
||||||
{{ count[loop.index0] }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var ctx = document.getElementById('1').getContext('2d');
|
var ctx = document.getElementById('2').getContext('2d');
|
||||||
|
var gradient = ctx.createLinearGradient(0, 0, 0, 600);
|
||||||
|
gradient.addColorStop(0, 'rgba(178, 81, 16, 1)');
|
||||||
|
gradient.addColorStop(1, 'rgba(255, 158, 93, 0)');
|
||||||
|
|
||||||
|
<!-- Node Version Chart -->
|
||||||
var options = {
|
var options = {
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
plugins: {
|
plugins: {
|
||||||
@@ -125,6 +60,37 @@
|
|||||||
options: options
|
options: options
|
||||||
});
|
});
|
||||||
|
|
||||||
|
<!-- Hashrate Chart -->
|
||||||
|
var options = {
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
interaction: {
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
labels: {{ hash_date }},
|
||||||
|
datasets: [{
|
||||||
|
label: 'Hashrate (kG/s)',
|
||||||
|
data: {{ hashrate }},
|
||||||
|
fill: true,
|
||||||
|
borderColor: "#b25110",
|
||||||
|
backgroundColor: gradient,
|
||||||
|
tension: 0.1
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
new Chart(document.getElementById("2"), {
|
||||||
|
type: 'line',
|
||||||
|
data: data,
|
||||||
|
options: options
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user