Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| afda0680ec |
@ -1,10 +1,17 @@
|
|||||||
import base64
|
import base64
|
||||||
|
import math
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pathlib import Path
|
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:
|
class RandomTextManager:
|
||||||
_cache: list[tuple[float, str]]
|
_cache: list[tuple[float, str]]
|
||||||
|
|
||||||
@ -55,7 +62,8 @@ class RandomTextManager:
|
|||||||
|
|
||||||
for ts, cn in self._cache:
|
for ts, cn in self._cache:
|
||||||
contents.append(cn)
|
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]
|
return random.choices(contents, weights)[0]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user