from JohnsonUtil import LoggerFactory as LoggerFactory from JohnsonUtil import commonTips as cct if __name__ == "__main__": # parsehtml(downloadpage(url_s)) # StreamHandler(sys.stdout).push_application() log = LoggerFactory.getLogger('Autodata') # log.setLevel(LoggerFactory.DEBUG) # handler=StderrHandler(format_string='{record.channel}: {record.message) [{record.extra[cwd]}]') # log.level = log.debug # error_handler = SyslogHandler('Sina-M-Log', level='ERROR') try: if cct.get_work_day_status() and cct.get_now_time_int() < 1505: # tdx_data=tdd.get_tdx_all_day_DayL_DF(market='cyb', dayl=1) print sina_data.Sina().get_stock_code_data('300006') tdx_data = rl.get_sina_Market_json('cyb') if len(tdx_data) < 1: raise KeyboardInterrupt("StopTime") else: print tdx_data[-2:] code = '300366' except (KeyboardInterrupt) as e: pass except (IOError, EOFError, Exception) as e: print "Error", e #traceback.print_exc() sleeptime = random.randint(5, 15) print "Error2sleep:%s" % (sleeptime) cct.sleep(sleeptime)
def get_roll_mean_all(single=True, tdx=False, app=True, duration=100, ma_250_l=1.02, ma_250_h=1.11): # df = tdd.search_Tdx_multi_data_duration('tdx_all_df_300', 'all_300', df=None,code_l=code_list, start=start, end=None, freq=None, col=None, index='date') block_path = tdd.get_tdx_dir_blocknew() + '060.blk' if not app and cct.get_file_size( block_path) > 100 and cct.creation_date_duration(block_path) == 0: print "It's Today Update" return True code_list = sina_data.Sina().market('all').index.tolist() print "all code:", len(code_list) if duration < 300: h5_fname = 'tdx_all_df' + '_' + str(300) h5_table = 'all' + '_' + str(300) else: h5_fname = 'tdx_all_df' + '_' + str(900) h5_table = 'all' + '_' + str(900) # df = tdd.search_Tdx_multi_data_duration('tdx_all_df_300', 'all_300', df=None,code_l=code_list, start='20150501', end=None, freq=None, col=None, index='date') df = tdd.search_Tdx_multi_data_duration(h5_fname, h5_table, df=None, code_l=code_list, start=None, end=None, freq=None, col=None, index='date') # df = tdd.search_Tdx_multi_data_duration(h5_fname, h5_table, df=None,code_l=code_list, start=None, end=None, freq=None, col=None, index='date',tail=1) code_uniquelist = df.index.get_level_values('code').unique() code_select = code_uniquelist[random.randint(0, len(code_uniquelist) - 1)] print round(time.time() - time_s, 2), df.index.get_level_values( 'code').unique().shape, code_select, df.loc[code_select].shape # df.groupby(level=[0]),df.index.get_level_values(0) # len(df.index.get_level_values('code').unique()) # df = df[~df.index.duplicated(keep='first')] dfs = df def get_groupby_mean_median_close(dfs): groupd = dfs.groupby(level=[0]) df = groupd['close'].agg({'median': 'median', 'mean': 'mean'}) df['close'] = groupd.tail(1).reset_index().set_index(['code'])['close'] # dfs['mean'] = groupd['close'].agg('mean') # dfs['median'] = groupd['close'].agg('median') # dfs = dfs.fillna(0) # idx = pd.IndexSlice # mask = ( (dfs['mean'] > dfs['median']) # & (dfs['close'] > dfs['mean']) # ) # df=dfs.loc[idx[mask, :]] df = df[(df['mean'] > df['median']) & (df['close'] > df['mean'])] # dt_low = None # if dl == 1: # dfs = groupd.tail(1) # print("dfs tail1") # else: # dl = 30 # dindex = tdd.get_tdx_Exp_day_to_df( # '999999', dl=dl).sort_index(ascending=False) # dt = tdd.get_duration_price_date('999999', df=dindex) # dt = dindex[dindex.index >= dt].index.values # dt_low = dt[-1] # dtlen = len(dt) if len(dt) >0 else 1 # dfs = groupd.tail(dtlen) # print("dfs tail:%s dt:%s"%(dtlen,dt)) # dfs = get_multi_date_duration(dfs,dt[-1]) return df groupd = dfs.groupby(level=[0]) # rollma = ['5','10','60','100','200'] # rollma = ['5','10','250'] if duration < 300: rollma = ['10'] else: rollma = ['10', '250'] rollma.extend([str(duration)]) # import ipdb;ipdb.set_trace() # df.loc['300130'][:2] # dfs['mean'] = groupd['close'].agg('mean') # dfs['median'] = groupd['close'].agg('median') for da in rollma: cumdays = int(da) dfs['ma%d' % cumdays] = groupd['close'].apply(pd.rolling_mean, cumdays) if cumdays == 10: dfs['upper'] = dfs['ma%d' % cumdays].apply(lambda x: round( (1 + 11.0 / 100) * x, 1)) dfs['lower'] = dfs['ma%d' % cumdays].apply(lambda x: round( (1 - 9.0 / 100) * x, 1)) dfs['ene'] = map(lambda x, y: round((x + y) / 2, 1), dfs['upper'], dfs['lower']) # df['upper'] = map(lambda x: round((1 + 11.0 / 100) * x, 1), df.ma10d) # df['lower'] = map(lambda x: round((1 - 9.0 / 100) * x, 1), df.ma10d) # df['ene'] = map(lambda x, y: round((x + y) / 2, 1), df.upper, df.lower) # dfs['amount%d'%cumdays] = groupd['amount'].apply(pd.rolling_mean, cumdays) # df.ix[df.index.levels[0]] #df.ix[df.index[len(df.index)-1][0]] #last row # dfs = tdd.search_Tdx_multi_data_duration(df=dfs,code_l=code_list, start='20170918', end='20170918', freq=None, col=None, index='date') # print dfs[:1],len(dfs) # groupd.agg({'low': 'min'}) # '''idx mask filter''' # ''' dt_low = None df_idx = None if single: dfs = groupd.tail(1) print("dfs tail1") else: dl = 30 dindex = tdd.get_tdx_Exp_day_to_df('999999', dl=dl).sort_index(ascending=False) dt = tdd.get_duration_price_date('999999', df=dindex) dt = dindex[dindex.index >= dt].index.values dt_low = dt[-1] dtlen = len(dt) if len(dt) > 0 else 1 dfs = groupd.tail(dtlen) # import ipdb;ipdb.set_trace() df_idx = get_groupby_mean_median_close(dfs) print("dfs tail:%s dt:%s" % (dtlen, dt)) dfs = get_multi_date_duration(dfs, dt[-1]) # groupd2 = dfs.groupby(level=[0]) # dfs['ma%d'%cumdays] = groupd['close'].apply(pd.rolling_mean, cumdays) # dfs.reset_index().groupby(['code'])['date'].transform('count') single = True dfs = dfs.fillna(0) idx = pd.IndexSlice # mask = (dfs[('ma%s')%(rollma[0])] > dfs[('ma%s')%(rollma[1])]) & (dfs[('ma%s')%(rollma[-1])] > 0) & (dfs[('close')] > dfs[('ma%s')%(rollma[0])]) & (dfs[('close')] > dfs[('ma%s')%(rollma[-1])]) # mask = (dfs[('ma%s')%(rollma[0])] > dfs[('ma%s')%(rollma[1])]) & (dfs[('ma%s')%(rollma[-1])] > 0) & (dfs[('close')] > dfs[('ma%s')%(rollma[1])]) & (dfs[('close')] > dfs[('ma%s')%(rollma[-1])]) # mask = (dfs[('ma%s')%(rollma[0])] > dfs[('ma%s')%(rollma[1])]) & (dfs[('ma%s')%(rollma[-1])] > 0) & (dfs[('close')] > dfs[('ma%s')%(rollma[-1])]) # mask = ( (dfs[('ma%s')%(rollma[0])] > 0) & (dfs[('ma%s')%(rollma[-1])] > 0) & (dfs[('close')] > dfs[('ma%s')%(rollma[-1])]) & (dfs[('close')] > dfs[('ma%s')%(rollma[0])])) # mask = ( (dfs[('ma%s')%(rollma[0])] > 0) & (dfs[('ma%s')%(rollma[-1])] > 0) # & (dfs[('close')] > dfs[('ma%s')%(rollma[-1])]*ma_250_l) # & (dfs[('close')] < dfs[('ma%s')%(rollma[-1])]*ma_250_h) # & (dfs[('close')] > dfs[('ma%s')%(rollma[0])])) # & (dfs['mean'] > dfs['median']) # & (dfs['close'] > dfs['mean']) if len(rollma) > 1: mask = ((dfs[('ma%s') % (rollma[0])] > 0) & (dfs[('ma%s') % (rollma[-1])] > 0) & (dfs[('ma%s') % (rollma[0])] > dfs[('ma%s') % (rollma[-1])]) & (dfs[('close')] > dfs[('ma%s') % (rollma[0])]) & (dfs[('close')] > dfs[('ma%s') % (rollma[-1])] * ma_250_h) & ((dfs[('close')] > dfs['ene']) | (dfs[('close')] > dfs['upper']))) else: mask = ((dfs[('ma%s') % (rollma[0])] > 0) & (dfs[('close')] > dfs[('ma%s') % (rollma[0])]) & ((dfs[('close')] > dfs['ene']) | (dfs[('close')] > dfs['upper']))) # mask = ((dfs[('close')] > dfs[('ma%s')%(rollma[-1])])) df = dfs.loc[idx[mask, :]] df = get_multi_code_count(df) print(df.couts[:5]) # import ipdb;ipdb.set_trace() # df.sort_values(by='couts',ascending=0) # groupd.first()[:2],groupd.last()[:2] # groupd = df250.groupby(level=[0]) # ''' # groupd.transform(lambda x: x.iloc[-1]) # groupd.last() # groupd.apply(lambda x: x.close > x.ma250) # df.shape,df.sort_index(ascending=False)[:5] # ?groupd.agg # groupd = df.groupby(level=[0]) # groupd['close'].apply(pd.rolling_mean, 250, min_periods=1) #ex:# Group df by df.platoon, then apply a rolling mean lambda function to df.casualties # df.groupby('Platoon')['Casualties'].apply(lambda x:x.rolling(center=False,window=2).mean()) code_uniquelist = df.index.get_level_values('code').unique() code_select = code_uniquelist[random.randint(0, len(code_uniquelist) - 1)] if app: print round(time.time() - time_s, 2), 's', df.index.get_level_values( 'code').unique().shape, code_select, df.loc[code_select][-1:] if single: # groupd = df.groupby(level=[0]) if tdx: # block_path = tdd.get_tdx_dir_blocknew() + '060.blk' # if cct.get_work_time(): # codew = df[df.date == cct.get_today()].index.tolist() if dt_low is not None: groupd2 = df.groupby(level=[0]) df = groupd2.tail(1) df = df.reset_index().set_index('code') # import ipdb;ipdb.set_trace() # df = df[(df.date >= dt_low) & (df.date <= cct.get_today())] dd = df[(df.date == dt_low)] df = df[(df.date >= cct.last_tddate(1))] # import ipdb;ipdb.set_trace() print("df:%s df_idx:%s" % (len(df), len(df_idx))) if df_idx is not None and len(df_idx) > 0: df = df.loc[df_idx.index, :].dropna() print("Main Down dd :%s MainUP df:%s couts std:%0.1f " % (len(dd), len(df), df.couts.std())) # print df.date.mode()[0] df = df.sort_values(by='couts', ascending=1) df = df[df.couts > df.couts.std()] # df = df[(df.date >= df.date.mode()[0]) & (df.date <= cct.get_today())] codew = df.index.tolist() if app: print round(time.time() - time_s, 2), 'groupd2', len(df) else: df = df.reset_index().set_index('code') df = df[(df.date >= cct.last_tddate(days=10)) & (df.date <= cct.get_today())] codew = df.index.tolist() top_temp = tdd.get_sina_datadf_cnamedf(codew, df) top_temp = top_temp[(~top_temp.index.str.contains('688')) & (~top_temp.name.str.contains('ST'))] codew = top_temp.index.tolist() #clean st and 688 if app: hdf5_wri = cct.cct_raw_input("rewrite code [Y] or append [N]:") if hdf5_wri == 'y' or hdf5_wri == 'Y': append_status = False else: append_status = True else: append_status = False if len(codew) > 10: cct.write_to_blocknew(block_path, codew, append_status, doubleFile=False, keep_last=0) print "write:%s block_path:%s" % (len(codew), block_path) else: print "write error:%s block_path:%s" % (len(codew), block_path) # df['date'] = df['date'].apply(lambda x:(x.replace('-',''))) # df['date'] = df['date'].astype(int) # print df.loc[code_select].T,df.shape MultiIndex = False else: MultiIndex = True h5a.write_hdf_db('all300', df, table='roll200', index=False, baseCount=500, append=False, MultiIndex=MultiIndex) return df
def get_hot_countNew(changepercent, rzrq, fibl=None, fibc=10): global fibcount if fibcount == 0 or fibcount >= fibc: if fibcount >= fibc: fibcount = 1 else: fibcount += 1 if fibl is not None: int = 0 for f in fibl: code, op, ra, daysData, fib, st = f[0], f[1], f[2], f[3], f[ 4], f[5] int += 1 if int % 2 != 0: print "%s op:%s ra:%s d:%s fib:%s m5:%s %s" % ( code, f_print(3, op), f_print( 5, ra), f_print(2, daysData[0]), f_print( 3, fib), f_print(4, daysData[1]), st), else: print "%s op:%s ra:%s d:%s fib:%s m5:%s " % ( st, f_print(3, op), f_print( 5, ra), f_print(2, daysData[0]), f_print( 3, fib), f_print(4, daysData[1])) else: fibcount += 1 allTop = pd.DataFrame() indexKeys = ['sh', 'sz', 'cyb'] ffindex = ffu.get_dfcfw_fund_flow('all') ffall = {} ffall['zlr'] = 0 ffall['zzb'] = 0 for market in indexKeys: # market = ct.SINA_Market_KEY() # df = rd.get_sina_Market_json(market, False) df = sina_data.Sina().market(market) # count=len(df.index) log.info("market:%s" % df[:1]) df = df.dropna() df = df[df.close > 0] if 'percent' not in df.columns: df['percent'] = map(lambda x, y: round((x - y) / y * 100, 1), df.close.values, df.llastp.values) if 'percent' in df.columns.values: # and len(df[:20][df[:20]['percent']>0])>3: # if 'code' in df.columns: # top = df[df['percent'] > changepercent] # topTen = df[df['percent'] > 9.9] # crashTen = df[df['percent'] < -9.8] # crash = df[df['percent'] < -changepercent] # else: top = df[df['percent'] > changepercent] topTen = df[df['percent'] > 9.9] crashTen = df[df['percent'] < -9.8] crash = df[df['percent'] < -changepercent] else: log.info("market No Percent:%s" % df[:1]) top = '0' topTen = '0' crashTen = '0' crash = '0' # top=df[ df['changepercent'] <6] print("%s topT: %s top>%s: %s " % (f_print(4, market), f_print( 3, len(topTen)), changepercent, f_print(4, len(top)))), # url = ct.DFCFW_FUND_FLOW_URL % ct.SINA_Market_KEY_TO_DFCFW[market] # log.debug("ffurl:%s" % url) print(u"crashT:%s crash<-%s:%s" % (f_print( 4, len(crashTen)), changepercent, f_print(4, len(crash)))), ff = ffindex[market] if len(ff) > 0: zlr = float(ff['zlr']) zzb = float(ff['zzb']) ffall['zlr'] = ffall['zlr'] + zlr ffall['zzb'] = ffall['zzb'] + zzb # zt=str(ff['time']) # modfprint=lambda x:f_print(4,x) if x>0 else "-%s"%(f_print(4,str(x).replace('-',''))) # print modfprint(zlr) # print (u"流入: %s亿 比: %s%%" % (modfprint(zlr), modfprint(zzb))), print(u"流入: %s亿 比: %s%%" % (f_print(4, zlr), f_print(4, zzb))), print(u"%s %s%s" % (f_print(4, ff['close']), f_print(1, '!' if ff['open'] > ff['lastp'] else '?'), f_print(2, '!!' if ff['close'] > ff['lastp'] else '??'))) allTop = allTop.append(df, ignore_index=True) allTop = allTop.drop_duplicates() df = allTop count = len(df.index) top = df[df['percent'] > changepercent] topTen = df[df['percent'] > 9.9] crashTen = df[df['percent'] < -9.8] crash = df[df['percent'] < -changepercent] print(u" \tA:%s topT:%s top>%s:%s" % (f_print(4, count), f_print( 3, len(topTen)), changepercent, f_print(4, len(top)))), print(u"crashT:%s crash<-%s:%s" % (f_print(3, len(crashTen)), changepercent, f_print(4, len(crash)))), # ff = ffu.get_dfcfw_fund_flow(ct.DFCFW_FUND_FLOW_ALL) ffall['time'] = ff['time'] ff = ffall zzb = 0 if len(ff) > 0: zlr = round(float(ff['zlr']), 1) zzb = round(float(ff['zzb']) / 3, 1) zt = str(ff['time']) print(u"流入: %s亿 占比: %s%% %s" % (f_print(4, zlr), f_print(4, zzb), f_print(4, zt))) ff = ffu.get_dfcfw_fund_SHSZ() hgt = ffu.get_dfcfw_fund_HGT() szt = ffu.get_dfcfw_fund_HGT(url=ct.DFCFW_FUND_FLOW_SZT) log.debug("shzs:%s" % ff) log.debug("hgt:%s" % hgt) # if len(ff) > 0: # print ("\tSH: %s u:%s vo: %s sz: %s u:%s vo: %s" % ( # f_print(4, ff['scent']), f_print(4, ff['sup']), f_print(5, ff['svol']), f_print(4, ff['zcent']), # f_print(4, ff['zup']), # f_print(5, ff['zvol']))), if len(ff) > 0: print(u"\t\tSh: %s Vr:%s Sz: %s Vr:%s " % (f_print(4, ff['scent']), f_print(5, ff['svol']), f_print(4, ff['zcent']), f_print(5, ff['zvol']))) else: print(u"\t\tSh: \t%s Vr: \t%s Sz: \t%s Vr: \t%s ") % (0, 0, 0, 0) if len(hgt) > 0: print("\t\tHgt: %s Ggt: %s Sgt: %s Gst: %s" % (hgt['hgt'], hgt['ggt'], szt['hgt'], szt['ggt'])) else: print("\t\tHgt: \t%s Ggt: \t%s Sgt: %s Gst: %s" % (0, 0, 0, 0)) if len(rzrq) > 0: shpcent = round( (rzrq['shrz'] / rzrq['sh'] * 100), 1) if rzrq['sh'] > 0 else '?' szpcent = round( (rzrq['szrz'] / rzrq['sz'] * 100), 1) if rzrq['sz'] > 0 else '?' print(u"\tSh: %s rz:%s :%s%% sz: %s rz:%s :%s%% All: %s diff: %s亿" % (f_print(5, rzrq['sh']), f_print(4, rzrq['shrz']), shpcent, f_print(5, rzrq['sz']), f_print(4, rzrq['szrz']), szpcent, f_print(4, rzrq['all']), f_print(5, rzrq['dff']))) bigcount = rd.getconfigBigCount(count=None, write=True) # print bigcount cct.set_console(width, height, title=[ 'B:%s-%s V:%s' % (bigcount[0], bigcount[2], bigcount[1]), 'ZL: %s' % (zlr if len(ff) > 0 else 0), 'To:%s' % len(topTen), 'D:%s' % len(crash), 'Sh: %s ' % ff['scent'] if len(ff) > 0 else '?', 'Vr:%s%% ' % ff['svol'] if len(ff) > 0 else '?', 'MR: %s' % zzb, 'ZL: %s' % (zlr if len(ff) > 0 else '?') ]) return allTop
def get_hot_countNew(changepercent, rzrq, fibl=None, fibc=10): global fibcount INDEX_LIST_TDX = {'999999': 'sh', '399001': 'sz', '399006': 'cyb'} # {v: k for k, v in m.items()} # >>> zip(m.values(), m.keys()) # mi = dict(zip(m.values(), m.keys())) if fibcount == 0 or fibcount >= fibc: if fibcount >= fibc: fibcount = 1 else: fibcount += 1 if fibl is not None: int = 0 for f in fibl: code, op, ra, daysData, fib, st = f[0], f[1], f[2], f[3], f[ 4], f[5] # cumin_index[INDEX_LIST_TDX[code]]=cumin int += 1 if int % 2 != 0: print "%s op:%s ra:%s d:%s fib:%s m5:%s %s" % ( code, f_print(3, op), f_print( 5, ra), f_print(2, daysData[0]), f_print( 3, fib), f_print(4, daysData[1]), st), else: print "%s op:%s ra:%s d:%s fib:%s m5:%s " % ( st, f_print(3, op), f_print( 5, ra), f_print(2, daysData[0]), f_print( 3, fib), f_print(4, daysData[1])) else: fibcount += 1 allTop = pd.DataFrame() indexKeys = ['sh', 'sz', 'cyb'] # ffindex = ffu.get_dfcfw_fund_flow('all') ffindex = ffu.get_dfcfw_fund_flow2020('all') ffall = {} topTen_all = 0 crashTen_all = 0 ffall['zlr'] = 0 ffall['zzb'] = 0 for market in indexKeys: # market = ct.SINA_Market_KEY() # df = rd.get_sina_Market_json(market, False) df = sina_data.Sina().market(market) # count=len(df.index) # log.info("market:%s" % df[:1]) df = df.dropna() df = df[df.close > 0] if 'percent' not in df.columns: df['percent'] = map(lambda x, y: round((x - y) / y * 100, 1), df.close.values, df.llastp.values) if 'percent' in df.columns.values: # and len(df[:20][df[:20]['percent']>0])>3: # if 'code' in df.columns: # top = df[df['percent'] > changepercent] # topTen = df[df['percent'] > 9.9] # crashTen = df[df['percent'] < -9.8] # crash = df[df['percent'] < -changepercent] # else: top = df[df['percent'] > changepercent] topTen = df[df['percent'] > 9.9] # dropcode = [ x for x in topTen.index.tolist() if x not in top_Ten_Dropcxg] # if len(dropcode) >0: # topT_l = tdd.get_tdx_exp_all_LastDF_DL(dropcode, dt=ct.duration_date_l,newdays=10,showRunTime=False) # if isinstance(topT_l, pd.DataFrame): # top_Ten_Dropcxg.extend(topT_l.index.tolist()) crashTen = df[df['percent'] < -9.8] crash = df[df['percent'] < -changepercent] else: log.info("market No Percent:%s" % df[:1]) top = '0' topTen = '0' crashTen = '0' crash = '0' topTen_all += len(topTen) crashTen_all += len(crashTen) # top=df[ df['changepercent'] <6] # print("\033[1;31;40m您输入的帐号或密码错误!\033[0m") print("%s topT: %s top>%s: %s" % (f_print(4, market), f_print( 3, len(topTen)), changepercent, f_print(4, len(top)))), # url = ct.DFCFW_FUND_FLOW_URL % ct.SINA_Market_KEY_TO_DFCFW[market] # log.debug("ffurl:%s" % url) print(u"crashT:%s crash<-%s:%s" % (f_print( 4, len(crashTen)), changepercent, f_print(4, len(crash)))), # print(u"-5:%s" % # (f_print(4, len(crash[crash < -5])))), ff = ffindex[market] if len(ff) > 0: zlr = float(ff['zlr']) zzb = float(ff['zzb']) ffall['zlr'] = ffall['zlr'] + zlr ffall['zzb'] = ffall['zzb'] + zzb # zt=str(ff['time']) # modfprint=lambda x:f_print(4,x) if x>0 else "-%s"%(f_print(4,str(x).replace('-',''))) # print modfprint(zlr) # print (u"流入: %s亿 比: %s%%" % (modfprint(zlr), modfprint(zzb))), print(u"流入: %s亿 比: %s%% " % (f_print(6, zlr, 32), f_print(4, zzb, 32))), if 'close' in ff.keys(): if ff['close'] == 0: _percent = 0 else: _percent = round( (ff['close'] - ff['lastp']) * 100 / ff['close'], 2) else: _percent = 0 ff['close'] = 0.0 ff['open'] = 0.0 ff['lastp'] = 0.0 # print (u" %s"%(f_print(2,cumin_index[market],31))), print( u"%s %s%% %s%s" % (f_print(7, ff['close']), f_print(4, _percent, 31), f_print(1, '!' if ff['open'] > ff['lastp'] else '?'), f_print(2, '!!' if ff['close'] > ff['lastp'] else '??', 32))) allTop = allTop.append(df.reset_index(), ignore_index=True) allTop = allTop.drop_duplicates() df = allTop df = tdd.get_single_df_lastp_to_df(df.set_index('code'), resample='d') count = len(df.index) top = df[df['percent'] > changepercent] topTen = df[df['percent'] >= 9.9] if 'max5' in df.columns: top_Max = (df[(df.close >= df.hmax) & (df.close >= df.max5)]) # top_low = len(df[df.low < df.min5]) top_min = (df[(df.close <= df.lmin) & (df.close <= df.min5)]) cct.GlobalValues().setkey('top_max', top_Max) cct.GlobalValues().setkey('top_min', top_min) else: top_Max = [] top_low = 0 top_min = [] # topTen = str(len(topTen)) +'('+str(len(top_Ten_Dropcxg))+')' +'(H:'+str(len(top_Max))+')' topTen = str(topTen_all) + '(' + str(len(topTen)) + ')' + \ '(H:' + str(len(top_Max)) + ')' # print "top_Ten_Dropcxg:%s",top_Ten_Dropcxg # crashTen = df[df['percent'] < -9.8] crashTen = str(crashTen_all) + '(L:' + str(len(top_min)) + ')' crash = df[df['percent'] < -changepercent] print(u"AL:%s topT:%s top>%s:%s" % (f_print(4, count), f_print( 3, (topTen), 31), changepercent, f_print(4, len(top), 31))), print( u"crashT:%s crash<-%s:%s" % (f_print(3, (crashTen), 32), changepercent, f_print(4, len(crash), 31))), print(u"-5:%s" % (f_print(4, len(crash[crash.percent < -5]), 32))), # ff = ffu.get_dfcfw_fund_flow(ct.DFCFW_FUND_FLOW_ALL) ffall['time'] = ff['time'] ff = ffall zzb = 0 if len(ff) > 0: zlr = round(float(ff['zlr']), 1) zzb = round(float(ff['zzb']) / 3, 1) zt = str(ff['time']) print(u"流入: %s亿 占比: %s%% %s" % (f_print(4, zlr, 31), f_print(4, zzb, 31), f_print(4, zt))) ff = ffu.get_dfcfw_fund_SHSZ() # hgt = ffu.get_dfcfw_fund_HGT() # szt = ffu.get_dfcfw_fund_HGT(url=ct.DFCFW_FUND_FLOW_SZT) hgt = ffu.get_dfcfw_fund_HGSZ2021('bei') szt = ffu.get_dfcfw_fund_HGSZ2021('nan') log.debug("shzs:%s hgt:%s" % (ff, hgt)) # if len(ff) > 0: # print ("\tSH: %s u:%s vo: %s sz: %s u:%s vo: %s" % ( # f_print(4, ff['scent']), f_print(4, ff['sup']), f_print(5, ff['svol']), f_print(4, ff['zcent']), # f_print(4, ff['zup']), # f_print(5, ff['zvol']))), bigcount = rd.getconfigBigCount(count=None, write=True) if len(ff) > 0: print(u"\tSh: %s Vr:%s Sz: %s Vr:%s " % (f_print(4, ff['scent']), f_print(5, ff['svol'], 31), f_print(4, ff['zcent']), f_print(5, ff['zvol'], 31))), print(u'B:%s-%s V:%s' % (bigcount[0], bigcount[2], f_print(4, bigcount[1]))) else: print(u"\tSh: \t%s Vr: \t%s Sz: \t%s Vr: \t%s ") % (0, 0, 0, 0), print(u'B:%s-%s V:%s' % (bigcount[0], bigcount[2], f_print(4, bigcount[1]))) if len(hgt) > 0: print("\tSgt: %s Gst: %s Hgt: %s Ggt: %s SSVol:%s" % (hgt['ggt'], szt['ggt'], hgt['hgt'], szt['hgt'], f_print(10, ff['allvol'], 31))) else: print("\t%s Sgt: %s Gst: %s \tHgt: \t%s Ggt: " % (0, 0, 0, 0)) if len(rzrq) > 0: if 'shrz' not in rzrq.keys() and 'szrz' not in rzrq.keys(): rzrq['shrz'] = 0 rzrq['szrz'] = 0 shpcent = round( (rzrq['shrz'] / rzrq['sh'] * 100), 1) if rzrq['sh'] > 0 else '?' szpcent = round( (rzrq['szrz'] / rzrq['sz'] * 100), 1) if rzrq['sz'] > 0 else '?' print(u"\tSh: %s rz:%s :%s%% sz: %s rz:%s :%s%% All: %s diff: %s亿" % (f_print(5, rzrq['sh']), f_print(4, rzrq['shrz']), shpcent, f_print(5, rzrq['sz']), f_print(4, rzrq['szrz']), szpcent, f_print(4, rzrq['all'], 31), f_print(5, rzrq['dff'], 31))) # print "bigcount:",bigcount cct.set_console(width, height, title=[ 'B:%s-%s V:%s' % (bigcount[0], bigcount[2], bigcount[1]), 'ZL: %s' % (zlr if len(ff) > 0 else 0), 'To:%s' % len(topTen), 'D:%s' % len(crash), 'Sh: %s ' % ff['scent'] if len(ff) > 0 else '?', 'Vr:%s%% ' % ff['svol'] if len(ff) > 0 else '?', 'MR: %s' % zzb, 'ZL: %s' % (zlr if len(ff) > 0 else '?') ], closeTerminal=True) log.debug("set_console:bigcount[0]%s bigcount[2]:%s" % (bigcount[0], bigcount[2])) return allTop