コード例 #1
0
    def testGetRedditData(self):

        model.retrieve_data(True, 100)
        model.populate_reddit_data(model.reddit_cache)
        data = model.get_reddit_data()
        data2 = model.get_reddit_data("score")

        self.assertEqual(data2[0], data[0])

        data3 = model.get_reddit_data("date")

        self.assertNotEqual(data3[0], data[0])

        data4 = model.get_reddit_data("subreddit")

        self.assertNotEqual(data4[0], data[0])

        data5 = model.get_reddit_data("postid")

        self.assertNotEqual(data5[0], data[0])

        self.assertEqual(len(data[0]), 7)
        self.assertEqual(len(data2[0]), 7)
        self.assertEqual(len(data3[0]), 2)
        self.assertEqual(len(data4[0]), 2)
        self.assertEqual(len(data5[0]), 1)
コード例 #2
0
    def testRedditLimit(self):

        model.retrieve_data(False, 100)
        model.populate_reddit_data(model.reddit_cache)
        data = model.get_reddit_data()

        self.assertEqual(len(data), 100)

        model.retrieve_data(False, 150)
        model.populate_reddit_data(model.reddit_cache)
        data = model.get_reddit_data()

        self.assertEqual(len(data), 150)

        model.retrieve_data(False, 200)
        model.populate_reddit_data(model.reddit_cache)
        data = model.get_reddit_data()

        self.assertEqual(len(data), 200)
コード例 #3
0
    def testRedditCache(self):

        model.retrieve_data(False, 100)
        model.populate_reddit_data(model.reddit_cache)
        data = model.get_reddit_data()

        self.assertEqual(len(data), 100)

        model.retrieve_data(True, 200)
        model.populate_reddit_data(model.reddit_cache)
        data2 = model.get_reddit_data()

        self.assertEqual(len(data2), len(data))
        self.assertEqual(data2[0], data[0])
        self.assertEqual(data2[1], data[1])

        model.retrieve_data(False, 101)
        model.populate_reddit_data(model.reddit_cache)
        data3 = model.get_reddit_data()

        self.assertNotEqual(len(data3), len(data))
コード例 #4
0
def results_time_plot():
    data = model.get_reddit_data("date")
    date = []
    score = []
    for d in data:
        date.append(d[0])
        score.append(d[1])

    plot_div = plot([Scatter(x=date, y=score)], output_type='div')

    return render_template('results_time_plot.html',
                           line_plot=Markup(plot_div))
コード例 #5
0
    def testTweetData(self):
        rdata = model.get_reddit_data()
        post_id = rdata[0][0]
        post_title = rdata[0][1]

        model.populate_tweets_for_post(post_title, post_id)
        data = model.get_tweet_data(post_id)

        self.assertNotEqual(len(data), 0)

        self.assertGreaterEqual(data[0][2], data[1][2])
        self.assertGreaterEqual(data[1][2], data[2][2])
        self.assertGreaterEqual(data[2][2], data[3][2])
        self.assertGreaterEqual(data[3][2], data[4][2])

        self.assertEqual(len(data[0]), 5)
コード例 #6
0
def results_tweets_graph():
    twitter_data = []
    if request.method == 'POST':
        post_number = int(request.form['postnumber']) - 1
        r_data = model.get_reddit_data()
        reddit_data = r_data[post_number]
        reddit_id = reddit_data[0]
        reddit_title = reddit_data[1]

        model.populate_tweets_for_post(reddit_title, reddit_id)

        twitter_data = model.get_tweet_data(reddit_id)
    else:
        twitter_data = []

    return render_template('results_tweets_graph.html',
                           twitterdata=twitter_data)
コード例 #7
0
def results_subreddits():

    data = model.get_reddit_data("subreddit")
    subreddit = []
    score = []
    for d in data:
        subreddit.append(d[0])
        score.append(d[1])
    sorted_subreddit = [
        subreddit
        for _, subreddit in sorted(zip(score, subreddit), reverse=True)
    ]
    sorted_score = sorted(score, reverse=True)

    plot_div = plot([Bar(x=sorted_subreddit, y=sorted_score)],
                    output_type='div')

    return render_template('results_subreddits.html',
                           bar_graph=Markup(plot_div))
コード例 #8
0
def results_tweets():
    data = model.get_reddit_data()

    return render_template('results_tweets.html', redditdata=data)
コード例 #9
0
def results_reddit_table():

    data = model.get_reddit_data()
    return render_template("results_reddit_table.html", redditdata=data)