Skip to content

Commit

Permalink
hotfix: dedupe total
Browse files Browse the repository at this point in the history
  • Loading branch information
bck01215 committed Jun 28, 2024
1 parent 37f3843 commit 818cfa4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "elasticnow"
version = "0.3.0"
version = "0.4.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
3 changes: 1 addition & 2 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ pub fn get_week_start() -> String {
)
}

pub fn pretty_print_time_worked(time_worked: HashMap<String, i64>, top: usize) {
let total: i64 = time_worked.values().sum();
pub fn pretty_print_time_worked(time_worked: HashMap<String, i64>, top: usize, total: i64) {
let human_total = seconds_to_pretty(total);
let total_str = ansi_term::Colour::Blue.bold().paint("Total:").to_string();
let top_ten = group_top_x(time_worked, top);
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use elasticnow::cli::{self, args, config};
use elasticnow::elasticnow::elasticnow::ChooseOptions;
use elasticnow::elasticnow::elasticnow::{ElasticNow, SearchResult};
use elasticnow::elasticnow::servicenow::ServiceNow;
use elasticnow::elasticnow::servicenow_structs::TimeWorked;
use std::collections::HashMap;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

Expand Down Expand Up @@ -176,6 +177,7 @@ async fn run_report(
}
let mut task_cat_time: HashMap<String, i64> = HashMap::new();
let tasks = tasks.unwrap();
let total = get_total(&tasks);
let mut tasks_ids: HashMap<String, i64> = HashMap::new();
for time_work in tasks {
match time_work.task.as_ref() {
Expand Down Expand Up @@ -204,7 +206,7 @@ async fn run_report(
.entry(cost_center.cost_center.display_value)
.or_insert(0) += time;
}
args::pretty_print_time_worked(task_cat_time, top.unwrap_or(10));
args::pretty_print_time_worked(task_cat_time, top.unwrap_or(10), total);
std::process::exit(0);
}
async fn run_setup(
Expand Down Expand Up @@ -360,3 +362,10 @@ fn check_config() -> (config::Config, ServiceNow) {
);
(config, sn_client)
}

fn get_total(tasks: &Vec<TimeWorked>) -> i64 {
tasks
.iter()
.map(|t| t.time_in_seconds.parse::<i64>().unwrap_or_default())
.sum()
}

0 comments on commit 818cfa4

Please sign in to comment.