def read_data(cls, table_name, field=None, **kw): """ 一个简易的数据读取接口 :param table_name: :param field: :param kw: :return: """ try: cursor = BaseModel(table_name, cls.location, cls.dbname).query(kw, field) data = pd.DataFrame() if cursor.count(): data = pd.DataFrame(list(cursor)) except Exception as e: ExceptionInfo(e) finally: cursor.close() return data
def min(cls, table_name, field='_id', **kw): """ 找到满足kw条件的field列上的最小值 :param table_name: :param field: :param kw: :return: """ try: if not isinstance(field, str): raise TypeError('field must be an instance of str') cursor = BaseModel(table_name, cls.location, cls.dbname).query(sql=kw, field={field: True}) if cursor.count(): d = pd.DataFrame(list(cursor)) m = d.loc[:, [field]].min()[field] else: m = None cursor.close() return m except Exception as e: raise e
def read_data(cls, code, start_date, end_date, field=None, timemerge=False, **kw): """ :param field: :param code: :param start_date: :param end_date: :param timemerge: :return: """ try: sql = dict(stock_code=code, date={ '$gte': start_date, '$lte': end_date }) sql = dict(sql, **kw) cursor = BaseModel('kline_tick', cls.location, cls.dbname).query(sql, field) if cursor.count(): data = pd.DataFrame(list(cursor)) data = cls.merge_time(data) if timemerge else data cursor.close() return data else: cursor.close() return pd.DataFrame() except Exception as e: ExceptionInfo(e) return pd.DataFrame()