<commit_before># -*- coding: utf-8 -*-
import pandas as pd

from .bar import BarObject


class RqDataProxy(object):
    def __init__(self):
        import rqdata
        self.rqdata = rqdata
        rqdata.init()
        self.cache = {}

    def get_data(self, order_book_id, dt):
        # should use a better cache here
        rqdata = self.rqdata

        data = self.cache.get(order_book_id)
        if data is None:
            data = rqdata.get_price(order_book_id)
            self.cache[order_book_id] = data

        try:
            bar_data = data.ix[dt]
        except KeyError:
            bar_data = data[data.index <= dt].iloc[-1]

        bar = BarObject()
        bar.datetime = dt

        mapping = {
            "ClosingPx": "close",
            "OpeningPx": "open",
            "HighPx": "high",
            "LowPx": "low",
            "TotalVolumeTraded": "volume",
            "TotalTurnover": "total_turnover",
            # TODO: fill bar
        }
        for origin_key, new_key in mapping.items():
            setattr(bar, new_key, bar_data[origin_key])

        return bar


class MyDataProxy(object):
    def __init__(self):
        from quantor import model, dblogic as dbl

        self.db = model.new_mongo_db()
        self.cache = {}

    def get_data(self, order_book_id, dt):
        from quantor import model, dblogic as dbl
        db = self.db

        code, _ = order_book_id.split(".")<commit_msg>use str to access rqdata dataframe<commit_after># -*- coding: utf-8 -*-
import pandas as pd

from .bar import BarObject


class RqDataProxy(object):
    def __init__(self):
        import rqdata
        self.rqdata = rqdata
        rqdata.init()
        self.cache = {}

    def get_data(self, order_book_id, dt):
        # should use a better cache here
        rqdata = self.rqdata

        data = self.cache.get(order_book_id)
        if data is None:
            data = rqdata.get_price(order_book_id)
            self.cache[order_book_id] = data

        str_date = dt.strftime("%Y-%m-%d")
        try:
            bar_data = data.ix[str_date]
        except KeyError:
            bar_data = data[data.index <= str_date].iloc[-1]

        bar = BarObject()
        bar.datetime = dt

        mapping = {
            "ClosingPx": "close",
            "OpeningPx": "open",
            "HighPx": "high",
            "LowPx": "low",
            "TotalVolumeTraded": "volume",
            "TotalTurnover": "total_turnover",
            # TODO: fill bar
        }
        for origin_key, new_key in mapping.items():
            setattr(bar, new_key, bar_data[origin_key])

        return bar


class MyDataProxy(object):
    def __init__(self):
        from quantor import model, dblogic as dbl

        self.db = model.new_mongo_db()
        self.cache = {}

    def get_data(self, order_book_id, dt):
        from quantor import model, dblogic as dbl
        db = self.db

        code, _ = order_book_id.split(".")
{'fraction_non_alphanumeric': 0.10859269282814614, 'fraction_numerical': 0.0013531799729364006, 'mean_word_length': 1.8432692307692307, 'pattern_counts': {'":': 12, '<': 5, '<?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': '7039453', 'n_tokens_mistral': 953, 'n_tokens_neox': 923, 'n_words': 226}