From 57da2139c1e8b700d9d28653737ecfa9ecfec057 Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 30 Oct 2023 00:35:23 +0100 Subject: [PATCH] butcher/trend_setter: tweak algorithm to make min_after_mentions depend on period --- butcher/src/trend_setter.rs | 6 +++--- buzzback/src/main.rs | 2 +- cave/src/trend_tag.rs | 12 +++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/butcher/src/trend_setter.rs b/butcher/src/trend_setter.rs index b60ab83..fc7bf95 100644 --- a/butcher/src/trend_setter.rs +++ b/butcher/src/trend_setter.rs @@ -15,7 +15,7 @@ use cave::{ }; #[cfg(not(debug))] -const MIN_INTERVAL: Duration = Duration::from_secs(10); +const MIN_INTERVAL: Duration = Duration::from_secs(30); #[cfg(debug)] const MIN_INTERVAL: Duration = Duration::from_secs(5); @@ -157,8 +157,8 @@ async fn run( let old_tags = old_tags.into_iter().collect::>(); let mut keep = TREND_POOL_SIZE.min(scores.len()); - // shrink sorted set of tags as long as score is 0 - while keep > 0 && scores[keep - 1].0 <= 0. { + // shrink sorted set of tags as long as score is less than 1 + while keep > 0 && scores[keep - 1].0 < 1.0 { keep -= 1; } let remove = scores[keep..].iter() diff --git a/buzzback/src/main.rs b/buzzback/src/main.rs index 2a4b95f..42f7a6e 100644 --- a/buzzback/src/main.rs +++ b/buzzback/src/main.rs @@ -64,7 +64,7 @@ async fn main() { let client = Arc::new( reqwest::Client::builder() - .timeout(Duration::from_secs(5)) + .timeout(Duration::from_secs(10)) .user_agent(concat!( env!("CARGO_PKG_NAME"), "/", diff --git a/cave/src/trend_tag.rs b/cave/src/trend_tag.rs index 8dcfb45..183967d 100644 --- a/cave/src/trend_tag.rs +++ b/cave/src/trend_tag.rs @@ -1,7 +1,11 @@ use std::collections::BTreeSet; use crate::PERIOD_COMPARE_WINDOW; -const MIN_AFTER_MENTIONS: usize = 5; +const MIN_AFTER_MENTIONS: &[(u64, usize)] = &[ + (4, 7), + (24, 17), + (168, 57) +]; #[derive(Debug)] pub struct TrendTag { @@ -53,8 +57,10 @@ impl TrendTag { } } - if after_mentions < MIN_AFTER_MENTIONS { - return 0.; + for (min_period, min_after_mentions) in MIN_AFTER_MENTIONS { + if period >= *min_period && after_mentions < *min_after_mentions { + return 0.; + } } let before = if before_hours > 0 && before_mentions > 0 {