Exemplo n.º 1
0
class Statistics(object):
    """
    Holds the statistics about the stream.
    """
    def __init__(self, cfg):
        logging.debug('Statistics initiated')
        self.wc = WordsCounter(cfg['output_count'])
        self.mf = MedianFinder(cfg['output_median'])
        self.num_processed = 0

    def median(self, line):
        """
        Call the median finder stats
        :param line: a list of words in the tweet
        """
        self.mf.process_tweet(line)
        self.mf.write_results()
        self.num_processed += 1

    def word_count(self, line):
        """
        Call the median finder stats
        :param line: number of unique words for the line
        """
        self.wc.process_tweet(line)

    def save_info(self):
        """
        Write the word count to file
        :return:
        """
        logging.info('Number of tweets processed %d' % self.num_processed)
        self.wc.write_results()
Exemplo n.º 2
0
class Statistics(object):
    """
    Holds the statistics about the stream.
    """
    def __init__(self, cfg):
        logging.debug('Statistics initiated')
        self.wc = WordsCounter(cfg['output_count'])
        self.mf = MedianFinder(cfg['output_median'])
        self.num_processed = 0

    def median(self, line):
        """
        Call the median finder stats
        :param line: a list of words in the tweet
        """
        self.mf.process_tweet(line)
        self.mf.write_results()
        self.num_processed += 1

    def word_count(self, line):
        """
        Call the median finder stats
        :param line: number of unique words for the line
        """
        self.wc.process_tweet(line)

    def save_info(self):
        """
        Write the word count to file
        :return:
        """
        logging.info('Number of tweets processed %d' % self.num_processed)
        self.wc.write_results()