Example #1
0
 def start_download(self, ts_code, download_task_list, need_check_dates, basic_merge_trade_date_df, need_download_dates):
     need_donwload_count = len(download_task_list)
     # tushare账号只能使用五次一分钟
     if need_donwload_count == 0:
         print('No Task')
         return
     for task in download_task_list:
         start = task[0]
         end = task[1]
         # step1
         df = TsTool.instance().ts_get_oms_price(ts_code, start, end)
         # 筛选需要保存的数据
         need_save_df = df[df.trade_date.isin(need_check_dates+need_download_dates)]
         OmsMysqlTool.instance().insert_data(ts_code, need_save_df)
         # step2
         # 保存到checkDB的数据
         # all_dates = tmdt.get_everyday(start, end)
         download_data_days = need_save_df.drop_duplicates(subset='trade_date', keep='first').trade_date
         wait_for_check_days = list(set(download_data_days)-set(need_download_dates))
         basic_merge_trade_date_df['has_data'] = 0
         # basic_merge_trade_date_df.cal_date.isin(wait_for_check_days)
         basic_merge_trade_date_df.loc[basic_merge_trade_date_df.cal_date.isin(wait_for_check_days), 'has_data'] = 1
         # 保存到数据check数据库
         CheckTradeDateMysqlTool.instance().insert_data(basic_merge_trade_date_df)
         # step3
         # json文件修改
         tmjs.finishTaskTellJsonFile(ts_code, task)
     NotificationCenter.instance().postNotification(PipState.download_task_finish)
Example #2
0
    def check_trade_dates(self, lost_day, ts_code):
        # 数据库缺少日期
        check_dates = lost_day
        # 获取最长时间段
        start, end = tmdt.get_early_and_late_date(check_dates)
        # 缺少的最长时间段交易日期数据
        ts_trade_df = TsTool.instance().ts_get_trade_date(start, end)
        # # 保存交易日期数据,等验证完数据以后,需要保存到数据库
        # self.ts_trade_df = ts_trade_df
        # 获取check_data数据库
        # checkMysqlTool = CheckTradeDateMysqlTool()
        check_db_df = CheckTradeDateMysqlTool.instance().get_data_from_db_by_date_list(ts_code, lost_day)
        CheckTradeDateMysqlTool.instance().disconnect_db()

        ts_trade_df_dates = list(ts_trade_df.cal_date)
        check_db_df_dates = list(check_db_df.cal_date)

        # need_check_dates 是checks数据库没有验证过的数据
        need_check_dates = list(set(ts_trade_df_dates) - set(check_db_df_dates))
        # 需要验证的时间段的基础数据在ts_trade_df中,其中包含is_opne==0的数据
        basic_merge_trade_date_df = ts_trade_df[ts_trade_df['cal_date'].isin(need_check_dates)]
        basic_merge_trade_date_df['ts_code'] = ts_code

        # check_db_df中包含已经验证有数据的内容,这部分内容还有保存到oms数据库,需要添加到下载列表
        # 本地check存在需要下载的数据
        check_box_need_download_dates = list(check_db_df[check_db_df.has_data == 1].cal_date)
        return basic_merge_trade_date_df, need_check_dates, check_box_need_download_dates