Пример #1
0
def show_submission(submission_id):
    firebasedb.init_db_connection()
    submission = firebasedb.get_submission(submission_id)
    if submission:
        timestamps = [
            int((elem1 - submission.created_utc) / 60)
            for elem1 in submission.timestamp
        ]
        line = plt.plot(timestamps, submission.score)
        plt.suptitle(f'{submission.author_name} {submission.title}')
        plt.show()
Пример #2
0
        submission = Submission_model.from_reddit_submission(reddit_submission)
        # log.info(f"GameOverBot_fetcher fetched submission: {submission}")
        try:
            firebasedb.add_active_submission(submission)
        except Exception as e:
            log.error(
                f"GameOverBot_fetcher error in add_active_submission: {e}")


if __name__ == '__main__':
    # Parsing command line arguments
    parse_args()

    global log
    log = logger_creator.init_logger("GameOverBot_fetcher_logger", is_debug)
    log.info("[[[[[  GameOverBot_fetcher v0.9.1  ]]]]]")

    # connect db
    try:
        firebasedb.init_db_connection()
    except Exception as e:
        log.error(e)

    # reddit login
    reddit = praw_auth.authenticate()
    log.info(
        f"[[[[[  GameOverBot_fetcher authenticated as  {reddit.user.me()}  ]]]]]"
    )

    # fetch submissions
    fetch_submissions(reddit)
Пример #3
0
def show_submissions():
    online = False

    if online:
        firebasedb.init_db_connection()
        submissions = firebasedb.get_frozen_submissions()

    # Dictionary for aggregating submissions author_submissions_data by author
    # Key - author_name
    # Value - list of [timestamp, score] tuples
    author_data = defaultdict(list)

    # Dictionary for counting author submissions
    # Key - author_name
    # Value - submission counter
    author_submission_counter = defaultdict(int)

    if online:
        # Aggregate all submission author_submissions_data by author
        for submission in submissions:
            # Filter out submissions that don't have author_name (deleted submissions)
            # Filter out submissions with less than 200 score
            if submission.author_name and 100 <= submission.score[-1]:
                author_submission_counter[submission.author_name] += 1
                # Timestamp normalization
                timestamps = [
                    int((timestamp - submission.created_utc) / 60)
                    for timestamp in submission.timestamp
                ]
                for i in range(0, len(timestamps)):
                    # Create [timestamp, score] tuple and append it to the list by the author name key
                    author_data[submission.author_name].append(
                        (timestamps[i], submission.score[i]))

    if online:
        # Serialize object
        json.dump(author_data, open("submissions_dump.json", 'w'))
        json.dump(author_submission_counter,
                  open("author_submission_counter_dump.json", 'w'))
    else:
        # Restore serialized object
        author_data = json.load(open("submissions_dump.json", 'r'))
        author_submission_counter = json.load(
            open("author_submission_counter_dump.json", 'r'))

    line1 = None
    fig, ax1 = plt.subplots()
    ax1.set_xscale('log')
    #ax1.set_yscale('log')

    # Iterate through author_data keys
    for author_name in author_data:
        # Filter out authors with less than 10 submissions
        if len(author_data[author_name]
               ) > 51 and author_submission_counter[author_name] >= 40:
            author_submissions_data = author_data[author_name]

            # Sort author_submissions_data by timestamp
            author_submissions_data.sort(key=lambda tup: tup[0])

            # Apply Savitzky-Golay filter
            # window size 51, polynomial order 3
            xhat = scipy.signal.savgol_filter(
                list(zip(*author_submissions_data))[0], 51, 3)
            #xhat = list(zip(*author_submissions_data))[0]
            # window size 51, polynomial order 3
            yhat = scipy.signal.savgol_filter(
                list(zip(*author_submissions_data))[1], 51, 3)

            plt.suptitle(
                f'{author_name} - {author_submission_counter[author_name]}')
            if author_name == "Eugen0242":
                ax1.plot(xhat, yhat, color='tab:blue')
            else:
                line1 = ax1.plot(xhat, yhat, color='tab:green')

            if line1[0]:
                line1[0].set_alpha(0.1)

            plt.show()

    print('the end')
Пример #4
0
def show_submissions():
    firebasedb.init_db_connection()

    submissions = firebasedb.get_frozen_submissions()
    line1 = None
    line2 = None
    #plt.xscale('log')
    #plt.yscale('log')
    fig, ax1 = plt.subplots()
    ax1.set_xscale('log')
    ax1.set_yscale('log')
    #ax1.set_xlim([0, 360])
    #ax1.set_ylim([0, 1000])

    ax2 = ax1.twinx()
    ax2.set_ylabel('ratio')
    ax2.set_ylim([0.0, 1.1])
    ax2.set_xscale('log')

    # aggregate all submission data by a single author
    total = []
    for submission in submissions:
        if submission.author_name and submission.author_name == "Lighthouse-scout":
            timestamps = [
                int((timestamp - submission.created_utc) / 60)
                for timestamp in submission.timestamp
            ]
            for i in range(0, len(timestamps)):
                total.append(
                    (timestamps[i], submission.score[i], submission.ratio[i]))

    print(total)

    # filter data by Savitzky-Golay filter
    x = []
    y = []
    for t in total:
        x.append(t[0])
        y.append(t[1])

    yhat = scipy.signal.savgol_filter(total[0], 51,
                                      3)  # window size 51, polynomial order 3

    d = []
    for submission in submissions:
        author_subs = []
        if d[submission.author_name]:
            author_subs = d[submission.author_name]
        author_subs.append(submission)

    for key in d:
        submissions = d[key]

    for submission in submissions:
        if len(submission.score) > 60 and submission.score[-1] > 200 or True:
            timestamps = [
                int((elem1 - submission.created_utc) / 60)
                for elem1 in submission.timestamp
            ]

            if submission.author_name and submission.author_name == "Lighthouse-scout":
                line1 = ax1.plot(timestamps,
                                 submission.score,
                                 color='tab:blue')
                line2 = ax2.plot(timestamps,
                                 submission.ratio,
                                 color='tab:cyan')
                #line1[0].set_alpha(0.1)
                #line2[0].set_alpha(0.1)
            else:
                line1 = ax1.plot(timestamps,
                                 submission.score,
                                 color='tab:green')
                line2 = ax2.plot(timestamps, submission.ratio, color='tab:red')
                line1[0].set_alpha(0.1)
                line2[0].set_alpha(0.1)

            plt.suptitle(f'{submission.author_name} {submission.title}')
            #print(submission)

    plt.show()
    print('the end')