butcher/trend_setter: tweak algorithm to make min_after_mentions depend on period

This commit is contained in:
Astro 2023-10-30 00:35:23 +01:00
parent c567cb62e9
commit 57da2139c1
3 changed files with 13 additions and 7 deletions

View File

@ -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::<HashSet<String>>();
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()

View File

@ -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"),
"/",

View File

@ -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 {