本文整理汇总了Python中event_manager.EventManager.record方法的典型用法代码示例。如果您正苦于以下问题:Python EventManager.record方法的具体用法?Python EventManager.record怎么用?Python EventManager.record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event_manager.EventManager
的用法示例。
在下文中一共展示了EventManager.record方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TwitterStreamer
# 需要导入模块: from event_manager import EventManager [as 别名]
# 或者: from event_manager.EventManager import record [as 别名]
class TwitterStreamer(StreamListener):
def __init__(self, node, southwest, northeast, extras):
logging.info("Beginning TwitterStreamer init")
StreamListener.__init__(self)
# Lock and target location
self.lock = threading.Lock()
self.buckets = {}
self.deltas = {}
self.uploaders = {}
self.location = [southwest[LONG],southwest[LAT],northeast[LONG],northeast[LAT]]
self.event_manager = EventManager()
# Upload handler
self.node = node
logging.info("TwitterStreamer init successful")
#
# Threading Functiosn
#
# Start node
def start(self):
logging.info("Starting TwitterStreamer")
# This handles Twitter authetification and the connection to Twitter Streaming API
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# 2nd parameter self serves as the StreamListener object
self.stream = Stream(auth, self)
logging.debug("Created Stream object")
# Start streaming with right parameters
#self.stream.filter(locations=self.location, async=True)
t = threading.Thread(target=self.stream.filter, kwargs={'locations':self.location, 'async':False})
t.daemon = True
t.start()
logging.info("TwitterStreamer started successfully")
return t
def stop(self):
logging.info("Stopping TwitterStreamer")
# Disconnect the stream
self.stream.disconnect()
# Cancel our uploading threads
for t in self.uploaders:
self.uploaders[t].cancel()
logging.info("TwitterStreamer stopped")
#
# Data Management
#
def find_location(self, json):
# Primary check
coordinates = json['place']['bounding_box']['coordinates'][0]
return coordinates
def record_event(self,long,lat):
key = str(long) + "," + str(lat)
# If this is the first time recording for bucket, launch updater
if key not in self.buckets:
self.buckets[key] = self.buckets.get(key,0) + 1
self.deltas[key] = datetime.datetime.now()
self.post_bucket(key)
else:
self.buckets[key] += 1
def post_bucket(self, key):
#now = datetime.datetime.now()
#period = (now - self.deltas[key]).total_seconds()
#self.deltas[key] = now
period = 10
velocity = float(self.buckets[key]) / float(period)
accel, torque = self.event_manager.record(velocity)
x, y = [int(i) for i in key.split(',')]
#.........这里部分代码省略.........