Skip to content

Commit

Permalink
feat: mining status duration as human-time
Browse files Browse the repository at this point in the history
adds a dep on the humantime crate in order to display durations
as eg 3d 5h 25s instead of xxx seconds.
  • Loading branch information
dan-da committed Feb 19, 2025
1 parent d44fa97 commit 59304ed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ systemstat = "0.2.3"
sysinfo = "0.31.4"
thread-priority = "1.2.0"
rayon = "1.10"
humantime = "2.1.0"

[dev-dependencies]

Expand Down
2 changes: 1 addition & 1 deletion src/bin/dashboard_src/overview_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl Widget for OverviewScreen {
.unwrap()
.as_secs();
let uptime = Duration::from_secs(now - upsince);
format!("{:?}", uptime)
format!("{}", humantime::format_duration(uptime))
} else {
"-".to_string()
};
Expand Down
15 changes: 12 additions & 3 deletions src/models/state/mining_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum MiningStatus {

impl Display for MiningStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let elapsed_time = match self {
let elapsed_time_exact = match self {
MiningStatus::Guessing(guessing_work_info) => Some(
guessing_work_info
.work_start
Expand All @@ -66,6 +66,9 @@ impl Display for MiningStatus {
),
MiningStatus::Inactive => None,
};
// remove sub-second component, so humantime ends with seconds.
let elapsed_time =
elapsed_time_exact.map(|v| v - Duration::from_nanos(v.subsec_nanos().into()));
let input_output_info = match self {
MiningStatus::Guessing(info) => {
format!(" {}/{}", info.num_inputs, info.num_outputs)
Expand All @@ -75,10 +78,16 @@ impl Display for MiningStatus {

let work_type_and_duration = match self {
MiningStatus::Guessing(_) => {
format!("guessing for {} seconds", elapsed_time.unwrap().as_secs(),)
format!(
"guessing for {}",
humantime::format_duration(elapsed_time.unwrap())
)
}
MiningStatus::Composing(_) => {
format!("composing for {} seconds", elapsed_time.unwrap().as_secs())
format!(
"composing for {}",
humantime::format_duration(elapsed_time.unwrap())
)
}
MiningStatus::Inactive => "inactive".to_owned(),
};
Expand Down

0 comments on commit 59304ed

Please sign in to comment.