From a152439cc9840b8548faff3f3ca4109c5e6492e3 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Wed, 28 Sep 2022 21:43:40 +0900 Subject: [PATCH] separate two columnt Count and Percent #707 - 1. [] Unified output one table with -s and -d option - 2. [] add channel column to table output - 3. [] Remove First Timestamp and Last Timestamp with -d option - 4. [] Output csv with -o and -s option - 5. [x] Separete two column Count and Percent - 6. [x] change table format output crate from prettytable-rs to comfy_table. --- src/timeline/timelines.rs | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/timeline/timelines.rs b/src/timeline/timelines.rs index b010324a..eb10e1e6 100644 --- a/src/timeline/timelines.rs +++ b/src/timeline/timelines.rs @@ -48,22 +48,25 @@ impl Timeline { sammsges.push(format!("Total Event Records: {}\n", self.stats.total)); sammsges.push(format!("First Timestamp: {}", self.stats.start_time)); sammsges.push(format!("Last Timestamp: {}\n", self.stats.end_time)); - sammsges.push("Count (Percent)\tID\tEvent\t".to_string()); - sammsges.push("--------------- ------- ---------------".to_string()); + + let mut stats_tb = Table::new(); + stats_tb.load_preset(UTF8_FULL).apply_modifier(UTF8_ROUND_CORNERS) + .set_style(TableComponent::VerticalLines, ' '); + stats_tb.set_header(vec!["Count", "Percent", "ID", "Event"]); + // 集計件数でソート let mut mapsorted: Vec<_> = self.stats.stats_list.iter().collect(); mapsorted.sort_by(|x, y| y.1.cmp(x.1)); // イベントID毎の出力メッセージ生成 - let stats_msges: Vec = self.tm_stats_set_msg(mapsorted); + let stats_msges: Vec> = self.tm_stats_set_msg(mapsorted); for msgprint in sammsges.iter() { println!("{}", msgprint); } - for msgprint in stats_msges.iter() { - println!("{}", msgprint); - } + stats_tb.add_rows(stats_msges); + println!("{stats_tb}"); } pub fn tm_logon_stats_dsp_msg(&mut self) { @@ -86,8 +89,8 @@ impl Timeline { } // イベントID毎の出力メッセージ生成 - fn tm_stats_set_msg(&self, mapsorted: Vec<(&std::string::String, &usize)>) -> Vec { - let mut msges: Vec = Vec::new(); + fn tm_stats_set_msg(&self, mapsorted: Vec<(&std::string::String, &usize)>) -> Vec> { + let mut msges: Vec> = Vec::new(); for (event_id, event_cnt) in mapsorted.iter() { // 件数の割合を算出 @@ -101,34 +104,31 @@ impl Timeline { .get_event_id(*event_id) .is_some(); // event_id_info.txtに登録あるものは情報設定 + // 出力メッセージ1行作成 if conf { - // 出力メッセージ1行作成 - msges.push(format!( - "{0} ({1:.1}%)\t{2}\t{3}", - event_cnt, - (rate * 1000.0).round() / 10.0, - event_id, - &CONFIG + msges.push(vec! + [event_cnt.to_string(), + format!("{:.1}%", (rate * 1000.0).round() / 10.0), + event_id.to_string(), + CONFIG .read() .unwrap() .event_timeline_config .get_event_id(*event_id) .unwrap() - .evttitle, - )); + .evttitle.to_string(), + ] + ); } else { - // 出力メッセージ1行作成 - msges.push(format!( - "{0} ({1:.1}%)\t{2}\t{3}", - event_cnt, - (rate * 1000.0).round() / 10.0, - event_id, - "Unknown", - )); + msges.push( + vec![ + event_cnt.to_string(), + format!("{:.1}%", (rate * 1000.0).round() / 10.0), + event_id.to_string(), + "Unknown".to_string(), + ]); } } - - msges.push("---------------------------------------".to_string()); msges }