Using Twitter's Streaming API, to compute trends.
Currently at a very early stage.
Authentication to Twitter's API is handled by Leah Culver's oauth module. Can
be found at: http://oauth.googlecode.com/svn/code/python/oauth/oauth.py
Main Thread: Initiates worker threads
- Thread
Listener
: Connects to the streaming API, reads the stream, splits tweets into tokens, and updates the frequency table. - Thread
Statistician
: Reads the frequency table and computer the trends.
- Thread
Classes:
trends.api.stream.Stream
: Handles authentication to Twitter API.handler
: File-like object that listens to Twitter API.connect()
: Opens the connection of thehandler
to the API.get_tweet()
: Transforms a received JSON dictionary to a Tweet instance.close()
: Closes the connection of thehandler
to the API
trends.api.stream.Tweet
: Instances of this class represent tweet information.text
: Tweet textget_tokens()
: Analyzes thetext
and returns its tokens.
trends.analysis.listener.Listener
: Facilitates the Stream class, to retrieve data from the Twitter API.stream
: AStream
instance
trends.analysis.statistician.Stats
: Wrapper class around the data structure that will store token along with their statistics._scores
: Dictionary that stores pairs of token:<TokenStats object>add(token)
: If no entry exists in dictionary_scores
for key token, an entry is created. Else, it's updated.get_stats()
: Initiates the computation of stats for the tokens in_scores
.
trends.analysis.statistician.TokenStats
: Instances of this class maintain the statistics that correspond to a single token.observation
: Observations of the token, within this roundrounds_observed
: Amount of rounds that this token has been observed at least oncemean
: Floating mean.sqr_mean
: Floating square meanstd
: Floating Standard deviationscore
: Floating average z-scoreincrease()
: Increases the amount of observations for the corresponding token, by 1.compute_scores()
: Computes the score and all the statistical parameters.zero()
: Zeros parametersobservation
andscore
trends.analysis.statistician.Statistician
: Analyzes theStats
class and computes statistics.
-------------- +--------------- Main Thread --------------+ | --------------- | | | | | | | ---------------- -------------------- Listener Thread Statistician Thread ---------------- -------------------- Stream <-----------------+ Statistician | Stats | TokenStats | | Twitter API