<commit_before>from datetime import datetime

from flask import g
from pymongo import ASCENDING, MongoClient

from app.utils import rand_str


def init_db():
    db = connect_db()
    db.counters.insert_one({'_id': 'uid', 'next_uid': 1000})
    db.auth.create_index([('uid', ASCENDING)], unique=True)
    db.members.create_index([('uid', ASCENDING)], unique=True)
    from app.auth import Auth
    from app.profile import Member
    admin_username = 'admin'
    admin_password = <PASSWORD>(8)
    encrypted = Auth.encrypt_password(admin_password)
    db.auth.insert_one({
        'uid': 0, 'username': admin_username,
        'password': <PASSWORD>, 'auth_level': 'admin'})
    empty_info = Member().to_info()
    empty_info['uid'] = 0
    empty_info['created_time'] = datetime.utcnow()
    empty_info['updated_time'] = datetime.utcnow()
    empty_info['publications'] = []
    db.members.insert_one(empty_info)
    return (admin_username, admin_password)


def connect_db():
    client = MongoClient('localhost', 27017)
    return client['mmlab']


def get_db():
    if not hasattr(g, 'db'):
        g.db = connect_db()
    return g.db<commit_msg>add collection index after adding documents<commit_after>from datetime import datetime

from flask import g
from pymongo import ASCENDING, MongoClient

from app.utils import rand_str


def init_db():
    db = connect_db()
    # create counter collection and add uid counter
    db.counters.insert_one({'_id': 'uid', 'next_uid': 1000})
    # add an admin account
    from app.auth import Auth
    from app.profile import Member
    admin_username = 'admin'
    admin_password = <PASSWORD>(8)
    encrypted = Auth.encrypt_password(admin_password)
    db.auth.insert_one({
        'uid': 0, 'username': admin_username,
        'password': <PASSWORD>, 'auth_level': 'admin'})
    # add an empty admin memebr
    empty_info = Member().to_info()
    empty_info['uid'] = 0
    empty_info['created_time'] = datetime.utcnow()
    empty_info['updated_time'] = datetime.utcnow()
    empty_info['publications'] = []
    db.members.insert_one(empty_info)
    # create indexes
    db.auth.create_index([('uid', ASCENDING)], unique=True)
    db.members.create_index([('uid', ASCENDING)], unique=True)
    return (admin_username, admin_password)


def connect_db():
    client = MongoClient('localhost', 27017)
    return client['mmlab']


def get_db():
    if not hasattr(g, 'db'):
        g.db = connect_db()
    return g.db
{'fraction_non_alphanumeric': 0.13100081366965013, 'fraction_numerical': 0.009764035801464606, 'mean_word_length': 3.878968253968254, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6105360', 'n_tokens_mistral': 825, 'n_tokens_neox': 781, 'n_words': 190}