<commit_before>import pymongo
import pandas as pd
from math import log
from time import time
import sys
from scipy.stats import linregress
import pickle

# TODO
# trade count feature
# time-weight trades

client = pymongo.MongoClient()
db = client['bitmicro']


def get_book_df(symbol, limit, sort_order, convert_timestamps=False):
    '''
    Returns a DataFrame of book data for symbol
    '''
    books_db = db[symbol+'_books']
    cursor = books_db.find().sort('_id', sort_order).limit(limit)
    books = pd.DataFrame(list(cursor))
    books = books.set_index('_id')
    if convert_timestamps:
        books.index = pd.to_datetime(books.index, unit='s')
    return books.applymap(pd.DataFrame)


def get_width_and_mid(books):
    '''
    Returns width of best market and midpoint for each data point in
    DataFrame of book data
    '''<commit_msg>only use 10 orders on each side for dataframe map<commit_after>import pymongo
import pandas as pd
from math import log
from time import time
import sys
from scipy.stats import linregress
import pickle

# TODO
# trade count feature
# time-weight trades

client = pymongo.MongoClient()
db = client['bitmicro']


def get_book_df(symbol, limit, sort_order, convert_timestamps=False):
    '''
    Returns a DataFrame of book data for symbol
    '''
    books_db = db[symbol+'_books']
    cursor = books_db.find().sort('_id', sort_order).limit(limit)
    books = pd.DataFrame(list(cursor))
    books = books.set_index('_id')
    if convert_timestamps:
        books.index = pd.to_datetime(books.index, unit='s')

    def to_df(x):
        return pd.DataFrame(x[:10])
    return books.applymap(to_df)


def get_width_and_mid(books):
    '''
    Returns width of best market and midpoint for each data point in
    DataFrame of book data
    '''
{'fraction_non_alphanumeric': 0.09944134078212291, 'fraction_numerical': 0.0022346368715083797, 'mean_word_length': 3.8536585365853657, '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': '5170795', 'n_tokens_mistral': 579, 'n_tokens_neox': 564, 'n_words': 171}