separate log labels for noise and hail

This commit is contained in:
Данила Горнушко 2024-05-31 18:12:49 +03:00
parent 8c4537086c
commit ae8691cf84

View file

@ -42,7 +42,7 @@ impl fmt::Display for StatsOnDetect {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"New signal detected! Hail (total/10 min): {}/{}. Noise detected (total/10 min): {}/{}.",
"stats: Hail (total/10 min): {}/{}. Noise (total/10 min): {}/{}.",
self.hail_since_startup,
self.hail_in_10min,
self.noise_since_startup,
@ -61,11 +61,11 @@ impl fmt::Display for Stats10Min {
}
}
impl StatsOnDetect {
fn eq(&self, other: &Self, noise_logging: bool) -> bool {
impl PartialEq for StatsOnDetect {
fn eq(&self, other: &Self) -> bool {
let hail_cmp = self.hail_since_startup == other.hail_since_startup;
let noise_cmp = self.noise_since_startup == other.noise_since_startup;
hail_cmp && (!noise_logging || noise_cmp)
hail_cmp && noise_cmp
}
}
@ -242,8 +242,25 @@ fn main() {
StatsOptions::Stats(val) => info!("{val}"),
StatsOptions::DetectedNew(cur_stats) => {
err_counter = err_counter.saturating_sub(1);
if prev_stats.map_or(true, |v| !v.eq(&cur_stats, args.noise_logging)) {
info!("{cur_stats}");
if prev_stats.map_or(true, |v| v != cur_stats) {
match prev_stats {
Some(prev_stats) => {
match (
cur_stats.hail_since_startup > prev_stats.hail_since_startup,
cur_stats.noise_since_startup > prev_stats.noise_since_startup,
) {
(true, true) => info!("Hail and noise detected, {cur_stats}"),
(true, false) => info!("Hail detected, {cur_stats}"),
(false, true) => {
if args.noise_logging {
info!("Noise detected, {cur_stats}")
}
}
(false, false) => (),
}
}
None => info!("Initial {cur_stats}"),
}
if samples_needed
&& prev_stats.map_or(args.first_sample, |v| {
v.hail_since_startup != cur_stats.hail_since_startup