def ins_top_meigaras(self, datestr, meigaras=[], ex_meigaras=[], choose_strictly=True):
        strsql = "select code from trade.dow "
        
        wherelist = ["date = \'%s\'" % datestr]
        if choose_strictly:
            if float(self.volsize_limit) > 0:
                wherelist.append("volsize>=\'%s\'" % self.volsize_limit) 
            if self.use_dow == 1:
                if self.trade_mode == "BUY":
                    wherelist.append("dow_sign=\'1'")
                if self.trade_mode == "SELL":
                    wherelist.append("dow_sign=\'-1'")
            if float(self.price_moving_rate_limit) > 0:
                wherelist.append("mv_range_avg<=\'%s\'" % self.price_moving_rate_limit)
        if len(meigaras) > 0:
            wherelist.append(kf.where_code_in(meigaras))
        if len(ex_meigaras) > 0:
            wherelist.append(kf.where_code_in(ex_meigaras, True))
        
        strwhere = f.list2sqlwhere(wherelist)
        strsql = strsql + strwhere + ";" 
        if strwhere != "":       
            meigaras = sql.exec_selsql(strsql, 0)
        else:
            meigaras = []        
        
        
        strsql = "select pf.code, pf.fieldid, tp.geneid, tp.points, \
tp.holding_days, tp.trade_mode from trade.%s as pf " % (self.pf_table)
        strsql = strsql + "inner join trade.%s as tp on pf.fieldid = tp.fieldid " % self.tp_table
        
        wherelist = ["date = \'%s\'" % datestr]
        if int(self.min_cnt) > 0:
            wherelist.append("tp.fieldcnt>=\'%s\'" % self.min_cnt)
        if float(self.min_points) > 0:
            wherelist.append("tp.points>=\'%s\'" % self.min_points)
        wherelist.append("tp.trade_mode=\'%s\'" % self.trade_mode)
                    
        strwhere = f.list2sqlwhere(wherelist)
        
        where_code_in = kf.where_code_in(meigaras)
        if strwhere == "":
            strwhere = " where "
        else:
            if where_code_in != "":
                strwhere = strwhere + " and "
        strsql = strsql + strwhere + kf.where_code_in(meigaras)
        strsql = strsql + " order by tp.points desc"
        strsql = strsql + " limit %s;" % self.top_fieldid_num
        
        data = sql.exec_selsql(strsql)
        
        for row in data:
            row.insert(0, self.prgname)
        
        if len(data) > 0:
            tbl.arr2table(data, "learned_memory")
 def ins_top_meigaras(self, datestr, meigaras=[], ex_meigaras=[]):
     strsql = "truncate table trade.learned_memory2;"
     sql.exec_updsql(strsql)
     
     strsql = "select pf.code, pf.fieldid, tp.geneid, tp.score, \
     tp.holding_days/tp.n_plays, pf.volume from trade.%s as pf " % (self.pf_table)
     strsql = strsql + "inner join trade.%s as tp on pf.fieldid = tp.fieldid " % self.tp_table
     
     wherelist = ["date = \'%s\'" % datestr]
     if int(self.min_cnt) > 0:
         wherelist.append("tp.fieldcnt>=\'%s\'" % self.min_cnt)
     if float(self.min_score) > 0:
         wherelist.append("tp.score>=\'%s\'" % self.min_score)
     wherelist.append("tp.holding_days>0")
     wherelist.append("n_win/(n_lose+n_win)>=0.5")
                 
     strwhere = f.list2sqlwhere(wherelist)
     
     where_code_in = kf.where_code_in(meigaras)
     if strwhere == "":
         strwhere = " where "
     else:
         if where_code_in != "":
             strwhere = strwhere + " and "
     strsql = strsql + strwhere + kf.where_code_in(meigaras)
     strsql = strsql + " order by tp.score desc"
     strsql = strsql + " limit %s;" % self.top_fieldid_num
     
     data = sql.exec_selsql(strsql)
     
     for row in data:
         row.insert(0, self.prgname)
     
     if len(data) > 0:
         tbl.arr2table(data, "learned_memory2")