Permalink
Browse files

acceleration rate less sensitive to noise

  • Loading branch information...
1 parent 82094db commit 58db2d5ffffcbc0f3a3b931152ea6ae1c706a23a @Swizec committed Apr 25, 2012
Showing with 14 additions and 9 deletions.
  1. +13 −8 src/chitchat.py
  2. +1 −1 src/settings.py
View
@@ -74,24 +74,29 @@ def should_speak(self):
%self.CHATTINESS_LONG]
# calculate rate of acceleration change
- last_3 = [self.recent_timestamps[(i+j)%self.CHATTINESS_LONG]
- for j in range(i, i+3)]
- v1 = abs(now-last_3[0])
- v2 = abs(last_3[0]-last_3[1])
- v3 = abs(last_3[1]-last_3[2])
+ # TODO: code could be prettier
+ last_15 = [self.recent_timestamps[(i+j)%self.CHATTINESS_LONG]
+ for j in range(i, i+15)]
+ v1 = sum([abs(now-last_15[j]) for j in range(5)])/5.0
+ v2 = sum([abs(now-last_15[j]) for j in range(5, 10)])/5.0
+ v3 = sum([abs(now-last_15[j]) for j in range(10, 15)])/5.0
a1 = v1-v2
a2 = v3-v2
try:
- rate = float(a2)/float(a1)
+ accel = float(a2)/float(a1)
+ if accel < 0:
+ accel = 0.0001
except ZeroDivisionError:
- rate = 0.1
+ accel = 0.0001
# add new timestamp
self.recent_timestamps[i] = now
# ratio between speed of last <10> messages and speed of last <60>
# determines probability of speaking
- return random.random() < 10*rate*float(now-oldest_10)/float(now-oldest)
+ speed = float(now-oldest_10)/float(now-oldest)
+
+ return random.random() < max(accel, speed)
def mentioned(self, msg):
return settings.BOT_NICK in msg
View
@@ -9,6 +9,6 @@
BOT_NICK = "_chatty-botko_"
BOT_NAME = "chatty-botko"
#CHANNEL = "#smotko-testing"
-CHANNEL = "#swizec-testing"
+CHANNEL = "#psywerx"
IRC_SERVER = 'irc.freenode.org'
IRC_PORT = 6667

0 comments on commit 58db2d5

Please sign in to comment.