Added statistics to main screen.

pull/124/head v0.5.8
Revertron 3 years ago
parent ebcb7174fe
commit 88404a635b

@ -37,6 +37,8 @@ const SQL_GET_LAST_FULL_BLOCK_FOR_KEY: &str = "SELECT * FROM blocks WHERE id < ?
const SQL_GET_DOMAIN_OWNER_BY_ID: &str = "SELECT signing FROM domains WHERE id < ? AND identity = ? ORDER BY id DESC LIMIT 1;";
const SQL_GET_DOMAIN_BY_ID: &str = "SELECT * FROM domains WHERE identity = ? ORDER BY id DESC LIMIT 1;";
const SQL_GET_DOMAINS_BY_KEY: &str = "SELECT * FROM domains WHERE signing = ? ORDER BY id;";
const SQL_GET_DOMAINS_COUNT: &str = "SELECT count(DISTINCT identity) FROM domains;";
const SQL_GET_USERS_COUNT: &str = "SELECT count(DISTINCT pub_key) FROM blocks;";
const SQL_GET_OPTIONS: &str = "SELECT * FROM options;";
@ -601,6 +603,22 @@ impl Chain {
}
}
pub fn get_domains_count(&self) -> i64 {
let mut statement = self.db.prepare(SQL_GET_DOMAINS_COUNT).unwrap();
while let State::Row = statement.next().unwrap() {
return statement.read::<i64>(0).unwrap();
}
0
}
pub fn get_users_count(&self) -> i64 {
let mut statement = self.db.prepare(SQL_GET_USERS_COUNT).unwrap();
while let State::Row = statement.next().unwrap() {
return statement.read::<i64>(0).unwrap();
}
0
}
pub fn get_my_domains(&self, keystore: Option<&Keystore>) -> HashMap<Bytes, (String, i64, DomainData)> {
if keystore.is_none() {
return HashMap::new();

@ -12,7 +12,7 @@ pub enum Event {
BlockchainChanged { index: u64 },
ActionStopMining,
ActionQuit,
NetworkStatus { nodes: usize, blocks: u64 },
NetworkStatus { blocks: u64, domains: i64, keys: i64, nodes: usize },
Syncing { have: u64, height: u64 },
SyncFinished,
}

@ -119,6 +119,7 @@ fn main() {
}
return;
}
info!("Blocks count: {}, domains count: {}, users count: {}", chain.get_height(), chain.get_domains_count(), chain.get_users_count());
let settings_copy = settings.clone();
let mut keys = Vec::new();
if settings.key_files.len() > 0 {

@ -129,8 +129,10 @@ impl Network {
token => {
if !handle_connection_event(Arc::clone(&context), &mut peers, &poll.registry(), &event) {
let _ = peers.close_peer(poll.registry(), &token);
let blocks_count = context.lock().unwrap().chain.get_height();
post(crate::event::Event::NetworkStatus { nodes: peers.get_peers_active_count(), blocks: blocks_count });
let blocks = context.lock().unwrap().chain.get_height();
let keys = context.lock().unwrap().chain.get_users_count();
let domains = context.lock().unwrap().chain.get_domains_count();
post(crate::event::Event::NetworkStatus { blocks, domains, keys, nodes: peers.get_peers_active_count() });
}
}
}
@ -151,13 +153,16 @@ impl Network {
// Send pings to idle peers
let (height, hash) = {
let context = context.lock().unwrap();
let height = context.chain.get_height();
let blocks = context.chain.get_height();
let nodes = peers.get_peers_active_count();
let banned = peers.get_peers_banned_count();
post(crate::event::Event::NetworkStatus { nodes, blocks: height });
let keys = context.chain.get_users_count();
let domains = context.chain.get_domains_count();
post(crate::event::Event::NetworkStatus { blocks, domains, keys, nodes });
if log_timer.elapsed().as_secs() > LOG_REFRESH_DELAY_SEC {
info!("Active nodes count: {}, banned count: {}, blocks count: {}", nodes, banned, height);
info!("Active nodes count: {}, banned count: {}, blocks count: {}", nodes, banned, blocks);
let elapsed = last_events_time.elapsed().as_secs();
if elapsed >= 10 {
warn!("Last network events time {} seconds ago", elapsed);
@ -168,7 +173,7 @@ impl Network {
peers.connect_new_peers(poll.registry(), &mut unique_token, yggdrasil_only);
connect_timer = Instant::now();
}
(height, context.chain.get_last_hash())
(blocks, context.chain.get_last_hash())
};
peers.update(poll.registry(), height, hash);
ui_timer = Instant::now();
@ -534,7 +539,9 @@ fn handle_block(context: Arc<Mutex<Context>>, peers: &mut Peers, token: &Token,
let event = crate::event::Event::Syncing { have: my_height, height: max(max_height, my_height) };
post(event);
}
post(crate::event::Event::NetworkStatus { nodes: peers_count, blocks: my_height });
let domains = context.chain.get_domains_count();
let keys = context.chain.get_users_count();
post(crate::event::Event::NetworkStatus { blocks: my_height, domains, keys, nodes: peers_count });
}
BlockQuality::Twin => { debug!("Ignoring duplicate block {}", block.index); }
BlockQuality::Future => { debug!("Ignoring future block {}", block.index); }

@ -303,11 +303,11 @@ fn action_loaded(context: &Arc<Mutex<Context>>, web_view: &mut WebView<()>) {
format!("setLeftStatusBarText('Idle'); showMiningIndicator(false, false);")
}
}
Event::NetworkStatus { nodes, blocks } => {
Event::NetworkStatus { blocks, domains, keys, nodes } => {
if status.mining || status.syncing || nodes < 3 {
format!("setRightStatusBarText('Nodes: {}, Blocks: {}')", nodes, blocks)
format!("setStats({}, {}, {}, {});", blocks, domains, keys, nodes)
} else {
format!("setLeftStatusBarText('Idle'); setRightStatusBarText('Nodes: {}, Blocks: {}')", nodes, blocks)
format!("setLeftStatusBarText('Idle'); setStats({}, {}, {}, {});", blocks, domains, keys, nodes)
}
}
Event::BlockchainChanged {index} => {
@ -343,6 +343,9 @@ fn action_loaded(context: &Arc<Mutex<Context>>, web_view: &mut WebView<()>) {
let _ = web_view.eval(&format!("zonesChanged('{}');", &zones));
}
send_keys_to_ui(&c, &web_view.handle());
if let Err(e) = web_view.eval(&format!("setStats({}, {}, {}, {});", c.chain.get_height(), c.chain.get_domains_count(), c.chain.get_users_count(), 0)) {
error!("Error evaluating stats: {}", e);
}
event_info(web_view, "Application loaded");
}

@ -82,6 +82,33 @@
</div>
</div>
<p class="help">To mine domains you need to mine a strong pair of signing keys and a pair of encryption keys.</p>
<nav class="level is-mobile">
<div class="level-item has-text-centered">
<div>
<p class="heading">Blocks in chain</p>
<p class="title" id="stat_blocks">?</p>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Domains</p>
<p class="title" id="stat_domains">?</p>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Users/Keys</p>
<p class="title" id="stat_keys">?</p>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Connected nodes</p>
<p class="title" id="stat_nodes">0</p>
</div>
</div>
</nav>
</div>
<!-- Domain mining -->
@ -138,7 +165,7 @@
</div>
<div class="row status is-family-code">
<div class="level">
<div class="level is-mobile">
<div class="level-left">
<div class="level-item" id="indicator_parent">
<div class="busy_indicator busy_blue" id="busy_indicator" onclick="miningIndicatorClick(this)">
@ -152,7 +179,7 @@
</div>
<div class="level-right">
<div class="level-item" id="status_bar_right">No data</div>
<div class="level-item" id="status_bar_right">🚀</div>
</div>
</div>
</div>

@ -510,9 +510,11 @@ function setLeftStatusBarText(text) {
bar.innerHTML = text;
}
function setRightStatusBarText(text) {
var bar = document.getElementById("status_bar_right");
bar.innerHTML = text;
function setStats(blocks, domains, keys, nodes) {
document.getElementById("stat_blocks").innerHTML = blocks;
document.getElementById("stat_domains").innerHTML = domains;
document.getElementById("stat_keys").innerHTML = keys;
document.getElementById("stat_nodes").innerHTML = nodes;
}
function addEvent(type, time, message) {

@ -148,6 +148,12 @@ th, td {
background-color: rgba(250, 250, 250, 0.7);
}
nav.level {
width: 100%;
position: absolute;
bottom: 6em;
}
.list {
overflow-y: auto;
}

Loading…
Cancel
Save