调整衰减函数
This commit is contained in:
@ -1,10 +1,17 @@
|
||||
import base64
|
||||
import math
|
||||
import random
|
||||
import time
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def dec_func(t: float) -> float:
|
||||
if t < 86400:
|
||||
return 0.5 * (1 + math.tanh(t / 43200 - 1))
|
||||
return math.exp(-0.00000043 * (t - 86400))
|
||||
|
||||
|
||||
class RandomTextManager:
|
||||
_cache: list[tuple[float, str]]
|
||||
|
||||
@ -55,7 +62,8 @@ class RandomTextManager:
|
||||
|
||||
for ts, cn in self._cache:
|
||||
contents.append(cn)
|
||||
weights.append((abs(now - ts) + 0.01) ** (-1))
|
||||
# weights.append((abs(now - ts) + 0.01) ** (-1))
|
||||
weights.append(dec_func(now - ts))
|
||||
|
||||
return random.choices(contents, weights)[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user