class Classifier:
    def __init__(self, tvshow):
        self.tvshow = tvshow
        self.nb = NBModel()
        self.client = ImdbClient()

    def classifyAll(self):
        possible_shows = ['Walking Dead', \
                      'Arrow', \
                      'Family Guy', \
                      'Big bang Theory', \
                      'South Park', \
                      'American Horror Story', \
                      'Modern Family', \
                      'Heroes Reborn']

        reviews = []
        for show in possible_shows:
            reviews.append(self.client.searchShow(show))
        self.nb.naive_bayes_train(reviews)
        self.nb.nb_classify_tweets(self.tvshow, self.client.readFromMongo(parse_show(self.tvshow), sys.maxint))

    def nbClassify(self):
        reviews = self.client.searchShow(self.tvshow)

        self.nb.naive_bayes_train(reviews)

        self.nb.nb_classify_tweets(self.tvshow, self.client.readFromMongo(parse_show(self.tvshow), sys.maxint))
class Statistics:
    def __init__(self):
        self.imdb = ImdbClient()

    # returns tuple: (sum, num_items, predicted rating, current IMDB rating, percent error)
    def get_stats(self, tvshow, sum, num_items):
        current_imdb_rating = self.imdb.getCurrentImdbRating(tvshow)
        predicted_value = float(sum) / num_items
        return sum, num_items, predicted_value, current_imdb_rating, \
               float(current_imdb_rating - predicted_value) / float(current_imdb_rating)

    def printStats(self, tvshow, sum, numItems):
        currentImdbRating = self.imdb.getCurrentImdbRating(tvshow)
        predictedValue = float(sum) / numItems
        print("---------- Statistics -----------")
        print("Sum of the ratings from Twitter: ", sum)
        print("Number of classified ratings: ", numItems)
        print("Average value: ", predictedValue)
        print("Current IMDB rating: ", currentImdbRating)
        print("Current error: ", float(currentImdbRating - predictedValue) / float(currentImdbRating))
class Classifier:
    def __init__(self, tvshow):
        self.tvshow = tvshow
        self.nb = NBModel()
        self.client = ImdbClient()

    def classifyAll(self):
        possible_shows = ['Walking Dead', \
                          'Arrow', \
                          'Family Guy', \
                          'Big bang Theory', \
                          'South Park', \
                          'American Horror Story', \
                          'Modern Family', \
                          'Heroes Reborn']

        reviews = []
        for show in possible_shows:
            reviews.append(self.client.searchShow(show))
        self.nb.nb_train_text(reviews)
        self.nb.nb_classify_tweets(self.tvshow, self.client.readFromMongo(parse_show(self.tvshow), sys.maxint))

    def nb_train(self):
            reviews = self.client.searchShow(self.tvshow)
            self.nb.nb_train_text(reviews)
            self.nb.save_model()

    def nb_train_all_episodes(self):
        # General show specific reviews
        reviews = self.client.searchShow(self.tvshow)
        episodeNames = self.client.get_all_episode_names(self.tvshow)
        for name in episodeNames:
            episodeShow = name + " " + self.tvshow #(self.tvshow).join(unicodedata.normalize('NFKD', name).encode('ascii', 'ignore'))
            query = self.client.searchShow(episodeShow)
            episodeShow = ''
            if query is not None:
                reviews.append(query)
        self.nb.nb_train_text(reviews)


    def nbClassify(self):
        return self.nb.nb_classify_tweets(self.tvshow,
                                          self.client.readFromMongo(parse_show(self.tvshow), sys.maxint))
 def __init__(self, tvshow):
     self.tvshow = tvshow
     self.nb = NBModel()
     self.client = ImdbClient()
 def __init__(self):
     self.imdb = ImdbClient()