Administrator
2023-12-18 90c01d8326c3c4a7952de694def6ed1c15aa13cc
输出接口优化
3个文件已修改
59 ■■■■ 已修改文件
third_data/data_server.py 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/history_k_data_util.py 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_data_manager.py 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/data_server.py
@@ -514,24 +514,35 @@
            # 获取上个交易日的相同涨停原因的代码信息
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
            code = ps_dict["code"]
            day = HistoryKDatasUtils.get_previous_trading_date(tool.get_now_date_str())
            # 获取涨停数据
            # 获取昨日涨停数据
            day = HistoryKDatasUtils.get_previous_trading_date_cache(tool.get_now_date_str())
            limit_up_records = kpl_data_manager.KPLLimitUpDataRecordManager.list_all_cache(day)
            reasons = []
            for d in limit_up_records:
                if d[3] == code:
                    reasons.append(d)
            # 获取代码的原因
            reasons = kpl_data_manager.KPLLimitUpDataRecordManager.list_by_code(code, day)
            if reasons:
                reasons = list(reasons)
                reasons.sort(key=lambda x: x[9])
                reason = reasons[-1][2]
                datas = self.__kplDataManager.get_from_file(kpl_util.KPLDataType.LIMIT_UP, day)
                # 获取涨停数据
                datas = self.__kplDataManager.get_from_file_cache(kpl_util.KPLDataType.LIMIT_UP, day)
                # (代码,名称,首次涨停时间,最近涨停时间,几板,涨停原因,板块,实际流通,主力净额,涨停原因代码,涨停原因代码数量)
                result_list = []
                yesterday_result_list = []
                if datas:
                    for d in datas:
                        if d[5] == reason and d[0] != code:
                            # (代码,名称)
                            result_list.append((d[0], d[1]))
                response_data = json.dumps({"code": 0, "data": {"reason": reason, "data": result_list}})
                            yesterday_result_list.append((d[0], d[1]))
                current_limit_up_list = kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas
                current_result_list = []
                if current_limit_up_list:
                    for c in current_limit_up_list:
                        if c[5] == reason and c[0] != code:
                            current_result_list.append((c[0], c[1]))
                response_data = json.dumps({"code": 0, "data": {"reason": reason, "data": {"yesterday": yesterday_result_list,"current":current_result_list}}})
            else:
                response_data = json.dumps({"code": 1, "msg": "昨日未涨停"})
third_data/history_k_data_util.py
@@ -194,6 +194,7 @@
class HistoryKDatasUtils(object):
    __previous_trading_date_cache={}
    @classmethod
    def get_gp_latest_info(cls, codes, fields=None):
@@ -212,6 +213,15 @@
    def get_previous_trading_date(cls, date):
        return JueJinApi.get_previous_trading_date(date)
    @classmethod
    def get_previous_trading_date_cache(cls, date):
        if date in cls.__previous_trading_date_cache:
            return cls.__previous_trading_date_cache.get(date)
        fdata = cls.get_previous_trading_date(date)
        if fdata:
            cls.__previous_trading_date_cache[date] = fdata
        return fdata
    # 返回指定日期的下个交易日
    @classmethod
    def get_next_trading_date(cls, date):
third_data/kpl_data_manager.py
@@ -49,6 +49,7 @@
    __CodesPlateKeysManager = CodesHisReasonAndBlocksManager()
    __current_code_reason_dict = {}
    __current_reason_codes_dict = {}
    __records_cache = {}
    @classmethod
    def __load_hist_and_blocks(cls, code):
@@ -146,10 +147,20 @@
        mysqldb = mysql_data.Mysqldb()
        return mysqldb.select_all(f"select * from kpl_limit_up_record where _day='{day}'")
    @classmethod
    def list_all_cache(cls, day):
        if day in cls.__records_cache:
            return cls.__records_cache[day]
        fdata = cls.list_all(day)
        if fdata:
            cls.__records_cache[day] = fdata
        return fdata
    @staticmethod
    def list_by_code(code, day):
        mysqldb = mysql_data.Mysqldb()
        return mysqldb.select_all(f"select * from kpl_limit_up_record where _code='{code}' and _day='{day}'")
    @staticmethod
    def list_by_block(block_name, day):
@@ -224,6 +235,7 @@
class KPLDataManager:
    __latest_datas = {}
    kpl_data_update_info = {}
    __file_content_cache = {}
    @classmethod
    def __save_in_file(cls, key, datas):
@@ -257,6 +269,18 @@
        return None
    @classmethod
    def get_from_file_cache(cls, type, day):
        key = f"{type}-{day}"
        if key in cls.__file_content_cache:
            return cls.__file_content_cache.get(key)
        fdata = cls.get_from_file(type, day)
        if fdata:
            cls.__file_content_cache[key] = fdata
        return fdata
    @classmethod
    # 获取最近几天的数据,根据日期倒序返回
    def get_latest_from_file(cls, type, count):
        files = os.listdir(constant.CACHE_PATH)