<commit_before># coding :utf-8

"""
定义一些可以扩展的数据结构

方便序列化/相互转换

"""

import itertools
import os
import sys
import webbrowser
from functools import reduce
import platform
import numpy as np
import pandas as pd
import six
import talib
from pyecharts import Kline
from QUANTAXIS.QAData.data_fq import QA_data_stock_to_fq
from QUANTAXIS.QAData.data_resample import QA_data_tick_resample
from QUANTAXIS.QAData.proto import stock_day_pb2  # protobuf import
from QUANTAXIS.QAData.proto import stock_min_pb2
from QUANTAXIS.QAIndicator import EMA, HHV, LLV, SMA
from QUANTAXIS.QAUtil import (QA_Setting, QA_util_log_info,
                              QA_util_to_json_from_pandas, trade_date_sse)


class __stock_hq_base():
    def __init__(self, DataFrame):
        self.data = DataFrame
        self.type = ''
        self.if_fq = 'bfq'
        self.mongo_coll = QA_Setting.client.quantaxis

    def __repr__(self):
        return 'QA_Base_DataStruct with %s securities' % len(self.code)

    def __call__(self):
        return self.data

    # 使用property进行懒运算
    @property
    def open(self):
        return self.data['open']

    @property
    def high(self):
        return self.data['high']

    @property
    def low(self):
        return self.data['low']

    @property
    def close(self):
        return self.data['close']

    @property
    def vol(self):
        if 'volume' in self.data.columns:
            return self.data['volume']
        else:
            return self.data['vol']

    @property
    def date(self):

        return self.data.index.levels[self.data.index.names.index(
            'date')] if 'date' in self.data.index.names else self.data['date']

    @property
    def datetime(self):

        return self.data.index.levels[self.data.index.names.index(
            'datetime')] if 'datetime' in self.data.index.names else self.data.index.levels[self.data.index.names.index(
                'date')]

    @property
    def index(self):
        return self.data.index

    @property
    def code(self):
        return self.data.index.levels[self.data.index.names.index('code')]

    def plot(self, code=None):
        if code is None:
            if platform.system() == 'Windows':
                path_name='.\QA_'+self.type+'_codepackage_'+self.if_fq+'.html'
            else:
                path_name='./QA_'+self.type+'_codepackage_'+self.if_fq+'.html'
            
            kline=Kline('CodePackage_'+self.if_fq+'_'+self.type,width=1360,height=700,page_title='QUANTAXIS')
            
            data_splits=self.splits()
            for i_ in range(len(data_splits)):
                data=[]
                axis=[]
                for dates,row in data_splits[i_].data.iterrows():
                    open,high,low,close=row[1:5]
                    datas=[open,close,low,high]
                    axis.append(dates[0])
                    data.append(datas)
                
                
                kline.add(self.code[i_],axis,data,mark_point=["max","min"], is_datazoom_show=True,datazoom_orient='horizontal')
            kline.render(path_name)
            webbrowser.open(path_name)
            QA_util_log_info('The Pic has been saved to your path: %s'%path_name)
        else:
            data=[]
            axis=[]
            for dates,row in self.select_code(code).data.iterrows():
                open,high,low,close=row[1:5]
                datas=[open,close,low,high]
                axis.append(dates[0])
                data.append(datas)
            if platform.system() == 'Windows':
                path_name='.\QA_'+self.type+'_'+code+'_'+self.if_fq+'.html'
            else:
                path_name='./QA_'+self.type+'_'+code+'_'+self.if_fq+'.html'
            kline=Kline(code+'__'+self.if_fq+'__'+self.type,width=1360,height=700,page_title='QUANTAXIS')
            kline.add(code,axis,data,mark_point=["max","min"], is_datazoom_show=True,datazoom_orient='horizontal')
            kline.render(path_name)
            webbrowser.open(path_name)
            QA_util_log_info('The Pic has been saved to your path: %s'%path_name)
        

<commit_msg>os.sep 修改<commit_after># coding :utf-8

"""
定义一些可以扩展的数据结构

方便序列化/相互转换

"""

import itertools
import os
import sys
import webbrowser
from functools import reduce
import platform
import numpy as np
import pandas as pd
import six
import talib
from pyecharts import Kline
from QUANTAXIS.QAData.data_fq import QA_data_stock_to_fq
from QUANTAXIS.QAData.data_resample import QA_data_tick_resample
from QUANTAXIS.QAData.proto import stock_day_pb2  # protobuf import
from QUANTAXIS.QAData.proto import stock_min_pb2
from QUANTAXIS.QAIndicator import EMA, HHV, LLV, SMA
from QUANTAXIS.QAUtil import (QA_Setting, QA_util_log_info,
                              QA_util_to_json_from_pandas, trade_date_sse)


class __stock_hq_base():
    def __init__(self, DataFrame):
        self.data = DataFrame
        self.type = ''
        self.if_fq = 'bfq'
        self.mongo_coll = QA_Setting.client.quantaxis

    def __repr__(self):
        return 'QA_Base_DataStruct with %s securities' % len(self.code)

    def __call__(self):
        return self.data

    # 使用property进行懒运算
    @property
    def open(self):
        return self.data['open']

    @property
    def high(self):
        return self.data['high']

    @property
    def low(self):
        return self.data['low']

    @property
    def close(self):
        return self.data['close']

    @property
    def vol(self):
        if 'volume' in self.data.columns:
            return self.data['volume']
        else:
            return self.data['vol']

    @property
    def date(self):

        return self.data.index.levels[self.data.index.names.index(
            'date')] if 'date' in self.data.index.names else self.data['date']

    @property
    def datetime(self):

        return self.data.index.levels[self.data.index.names.index(
            'datetime')] if 'datetime' in self.data.index.names else self.data.index.levels[self.data.index.names.index(
                'date')]

    @property
    def index(self):
        return self.data.index

    @property
    def code(self):
        return self.data.index.levels[self.data.index.names.index('code')]

    def plot(self, code=None):
        if code is None:
            path_name='.'+os.sep+'QA_'+self.type+'_codepackage_'+self.if_fq+'.html'
            kline=Kline('CodePackage_'+self.if_fq+'_'+self.type,width=1360,height=700,page_title='QUANTAXIS')
            
            data_splits=self.splits()
            for i_ in range(len(data_splits)):
                data=[]
                axis=[]
                for dates,row in data_splits[i_].data.iterrows():
                    open,high,low,close=row[1:5]
                    datas=[open,close,low,high]
                    axis.append(dates[0])
                    data.append(datas)
                
                
                kline.add(self.code[i_],axis,data,mark_point=["max","min"], is_datazoom_show=True,datazoom_orient='horizontal')
            kline.render(path_name)
            webbrowser.open(path_name)
            QA_util_log_info('The Pic has been saved to your path: %s'%path_name)
        else:
            data=[]
            axis=[]
            for dates,row in self.select_code(code).data.iterrows():
                open,high,low,close=row[1:5]
                datas=[open,close,low,high]
                axis.append(dates[0])
                data.append(datas)
            
            path_name='.'+os.sep+'QA_'+self.type+'_codepackage_'+self.if_fq+'.html'
            kline=Kline(code+'__'+self.if_fq+'__'+self.type,width=1360,height=700,page_title='QUANTAXIS')
            kline.add(code,axis,data,mark_point=["max","min"], is_datazoom_show=True,datazoom_orient='horizontal')
            kline.render(path_name)
            webbrowser.open(path_name)
            QA_util_log_info('The Pic has been saved to your path: %s'%path_name)
        


{'fraction_non_alphanumeric': 0.11855670103092783, 'fraction_numerical': 0.0057832537088257484, 'mean_word_length': 2.296726067136345, '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': '7535112', 'n_tokens_mistral': 2726, 'n_tokens_neox': 2607, 'n_words': 455}