<commit_before>def deserialize_thing_id(thing_id):
    return tuple(int(x, base=36) for x in thing_id[1:].split('_'))


def update_sr_tables(cursor, subreddit):
    _, subreddit_id = deserialize_thing_id(subreddit.fullname)
    cursor.execute(
        'INSERT OR IGNORE INTO subreddits (id, display_name) VALUES(?,?)',
        (subreddit_id, str(subreddit)))
    cursor.execute('UPDATE subreddits SET subscribers = ? '
                   'WHERE id = ?',
                   (subreddit.subscribers, subreddit_id))

    cursor.execute('DELETE FROM subreddit_moderator '
                   'WHERE subreddit_id = ?', (subreddit_id,))

    for moderator in subreddit.moderator:
        cursor.execute('INSERT OR IGNORE INTO users (username) '
                       'VALUES(?)', (str(moderator),))
        cursor.execute('SELECT id FROM users WHERE username = ?',
                       (str(moderator),))
        moderator_id = cursor.fetchone()[0]
        cursor.execute('INSERT OR IGNORE INTO subreddit_moderator '
                       '(subreddit_id, moderator_id) VALUES(?,?)',
                       (subreddit_id, moderator_id))
<commit_msg>Docstrings and comments for helpers.py<commit_after>def deserialize_thing_id(thing_id):
    "Convert base36 str representation of reddit 'thing id' into int tuple."
    return tuple(int(x, base=36) for x in thing_id[1:].split('_'))


def update_sr_tables(cursor, subreddit):
    "Update tables of subreddits and subreddit-moderator relationships."
    _, subreddit_id = deserialize_thing_id(subreddit.fullname)

    # Add subreddits and update subscriber counts
    cursor.execute(
        'INSERT OR IGNORE INTO subreddits (id, display_name) VALUES(?,?)',
        (subreddit_id, str(subreddit)))
    cursor.execute('UPDATE subreddits SET subscribers = ? '
                   'WHERE id = ?',
                   (subreddit.subscribers, subreddit_id))

    # Refresh listing of subreddits' moderators
    cursor.execute('DELETE FROM subreddit_moderator '
                   'WHERE subreddit_id = ?', (subreddit_id,))

    for moderator in subreddit.moderator:
        cursor.execute('INSERT OR IGNORE INTO users (username) '
                       'VALUES(?)', (str(moderator),))
        cursor.execute('SELECT id FROM users WHERE username = ?',
                       (str(moderator),))
        moderator_id = cursor.fetchone()[0]
        cursor.execute('INSERT OR IGNORE INTO subreddit_moderator '
                       '(subreddit_id, moderator_id) VALUES(?,?)',
                       (subreddit_id, moderator_id))

{'fraction_non_alphanumeric': 0.11046057767369243, 'fraction_numerical': 0.0039032006245121, 'mean_word_length': 2.6666666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7442036', 'n_tokens_mistral': 791, 'n_tokens_neox': 765, 'n_words': 173}