@@ -19,17 +19,19 @@ export class TrendService {
1919 ) { }
2020
2121 private readonly WEIGHTS = {
22- VOLUME : 0.35 ,
23- ACCELERATION : 0.4 ,
24- RECENCY : 0.25 ,
22+ VOLUME : 0.7 , // Most important
23+ ACCELERATION : 0.25 , // Growth matters
24+ RECENCY : 0.05 , // Just a small boost
2525 } ;
26-
2726 private readonly CATEGORIES = [ 'Sports' , 'News' , 'Entertainment' ] ;
2827 private readonly GENERAL_CATEGORY = 'Only on Yapper' ;
28+ private readonly RECENCY_MIN_SCORE = 5 ;
29+ private readonly TRENDING_WINDOW_HOURS = 6 ;
2930
3031 private readonly TOP_N = 30 ;
3132 private readonly MIN_BUCKETS = 30 * 60 * 1000 ;
3233 private readonly CATEGORY_THRESHOLD = 30 ;
34+ private readonly RECENCY_FULL_SCORE_MINUTES = 30 ;
3335
3436 async getTrending ( category ?: string , limit : number = 30 ) {
3537 const normalized_category = category ?. trim ( )
@@ -188,7 +190,7 @@ export class TrendService {
188190 try {
189191 console . log ( 'Calculate Trend.....' ) ;
190192 const now = Date . now ( ) ;
191- const hours_ago = now - 24 * 60 * 60 * 1000 ;
193+ const hours_ago = now - this . TRENDING_WINDOW_HOURS * 60 * 60 * 1000 ;
192194
193195 // 1. Get active candidates (last hour)
194196 const active_hashtags = await this . redis_service . zrangebyscore (
@@ -364,11 +366,17 @@ export class TrendService {
364366
365367 const minutes_ago = ( Date . now ( ) - last_seen ) / ( 60 * 1000 ) ;
366368
367- if ( minutes_ago <= 1 ) return 100 ;
369+ // Full score for recent hashtags
370+ if ( minutes_ago <= this . RECENCY_FULL_SCORE_MINUTES ) return 100 ;
371+
372+ // Linear decay over the trending window
373+ const hours_ago = minutes_ago / 60 ;
368374
369- const score = 100 - ( minutes_ago / 60 ) * 100 ;
375+ // Decay from 100 to RECENCY_MIN_SCORE instead of 0
376+ const score =
377+ 100 - ( hours_ago / this . TRENDING_WINDOW_HOURS ) * ( 100 - this . RECENCY_MIN_SCORE ) ;
370378
371- return Math . max ( 0 , score ) ;
379+ return Math . max ( this . RECENCY_MIN_SCORE , Math . min ( 100 , score ) ) ;
372380 }
373381
374382 private calculateFinalScore ( volume : number , acceleration : number , recency : number ) : number {
0 commit comments