pub fn update_from_json(
		&mut self,
		json: serde_json::Value,
		elapsed: Duration,
	) -> Result<(), Box<dyn Error + Send + Sync>> {
		let actions = json.get("actions").ok_or(eyre!("missing actions"))?;
		let spam_cnt =
			update_specific_from_json(&mut self.spam_stats, actions, ["reject"].as_slice(), elapsed, 1000.0_f64)?;
		let ham_cnt =
			update_specific_from_json(&mut self.ham_stats, actions, ["no action"].as_slice(), elapsed, 1000.0_f64)?;
		let junk_cnt = update_specific_from_json(
			&mut self.junk_stats,
			actions,
			["add header", "rewrite subject"].as_slice(),
			elapsed,
			1000.0_f64,
		)?;
		self.total.update((spam_cnt + ham_cnt + junk_cnt) as f64, elapsed)?;

		if let Some(scan_times) = json.get("scan_times") {
			if scan_times.is_array() {
				let scan_times = scan_times.as_array().unwrap();

				let avg_times = scan_times
					.iter()
					.map(|json_num| json_num.as_f64().unwrap_or(f64::NAN))
					.filter(|num| !num.is_nan())
					.collect::<Vec<_>>();
				if !avg_times.is_empty() {
					let cnt = avg_times.len() as f64;
					let avg_time = avg_times.sum_with_accumulator::<Sum2<_>>() / cnt;
					self.avg_time.update(avg_time, elapsed)?;
				}
			}
		}

		Ok(())
	}
/// Update stats from JSON received from Rspamd
Update stats from JSON received from Rspamd
Update stats from JSON received from Rspamd
pub fn update_from_json(
		&mut self,
		json: serde_json::Value,
		elapsed: Duration,
	) -> Result<(), Box<dyn Error + Send + Sync>> {
		let actions = json.get("actions").ok_or(eyre!("missing actions"))?;
		let spam_cnt =
			update_specific_from_json(&mut self.spam_stats, actions, ["reject"].as_slice(), elapsed, 1000.0_f64)?;
		let ham_cnt =
			update_specific_from_json(&mut self.ham_stats, actions, ["no action"].as_slice(), elapsed, 1000.0_f64)?;
		let junk_cnt = update_specific_from_json(
			&mut self.junk_stats,
			actions,
			["add header", "rewrite subject"].as_slice(),
			elapsed,
			1000.0_f64,
		)?;
		self.total.update((spam_cnt + ham_cnt + junk_cnt) as f64, elapsed)?;
		if let Some(scan_times) = json.get("scan_times") {
			if scan_times.is_array() {
				let scan_times = scan_times.as_array().unwrap();
				let avg_times = scan_times
					.iter()
					.map(|json_num| json_num.as_f64().unwrap_or(f64::NAN))
					.filter(|num| !num.is_nan())
					.collect::<Vec<_>>();
				if !avg_times.is_empty() {
					let cnt = avg_times.len() as f64;
					let avg_time = avg_times.sum_with_accumulator::<Sum2<_>>() / cnt;
					self.avg_time.update(avg_time, elapsed)?;
				}
			}
		}
		Ok(())
	}
pub fn update_from_json ( & mut self , json : serde_json :: Value , elapsed : Duration , ) -> Result < ( ) , Box < dyn Error + Send + Sync > > { let actions = json . get ( " " ) . ok_or ( eyre ! ( " " ) ) ? ; let spam_cnt = update_specific_from_json ( & mut self . spam_stats , actions , [ " " ] . as_slice ( ) , elapsed , 1000.0_f64 ) ? ; let ham_cnt = update_specific_from_json ( & mut self . ham_stats , actions , [ " " ] . as_slice ( ) , elapsed , 1000.0_f64 ) ? ; let junk_cnt = update_specific_from_json ( & mut self . junk_stats , actions , [ " " , " " ] . as_slice ( ) , elapsed , 1000.0_f64 , ) ? ; self . total . update ( ( spam_cnt + ham_cnt + junk_cnt ) as f64 , elapsed ) ? ; if let Some ( scan_times ) = json . get ( " " ) { if scan_times . is_array ( ) { let scan_times = scan_times . as_array ( ) . unwrap ( ) ; let avg_times = scan_times . iter ( ) . map ( | json_num | json_num . as_f64 ( ) . unwrap_or ( f64 :: NAN ) ) . filter ( | num | ! num . is_nan ( ) ) . collect :: < Vec < _ > > ( ) ; if ! avg_times . is_empty ( ) { let cnt = avg_times . len ( ) as f64 ; let avg_time = avg_times . sum_with_accumulator :: < Sum2 < _ > > ( ) / cnt ; self . avg_time . update ( avg_time , elapsed ) ? ; } } } Ok ( ( ) ) }
Update stats from JSON received from Rspamd
Update stats from JSON received from Rspamd
&mut self
json
serde_json::Value
elapsed
Duration
&mut self
json
serde_json::Value
elapsed
Duration