def analy_deal_type(self, stock_name, start_date, end_date, plt, color):
     delta_days = (end_date - start_date).days
     mysql = MySQL('trans')
     mysql.connect()
     for day in xrange(0, delta_days, 1):
         today = start_date + timedelta(days=day)
         next_day = start_date + timedelta(days=day+1)
         state_where_buy = "DEAL_DATE > '%s' and DEAL_DATE < '%s' and DEAL_TYPE = 1" % (today, next_day)
         buy_data = mysql.query_where(stock_name, state_where_buy)
         cnt_buy_data = len(buy_data)
         state_where_sell = "DEAL_DATE > '%s' and DEAL_DATE < '%s' and DEAL_TYPE = -1" % (today, next_day)
         sell_data = mysql.query_where(stock_name, state_where_sell)
         cnt_sell_data = len(sell_data)
         scale = 5
         if cnt_sell_data is not 0:
             if cnt_buy_data is not 0:
                 buy_total = self.sum_long(buy_data)
             else:
                 buy_total = 0
             sell_total = self.sum_long(sell_data)
             perc = (float(buy_total) / sell_total) * scale
             # perc = (float(cnt_buy_data) / cnt_sell_data) * scale
         else:
             perc = 0
         plt.scatter(today, perc, c=color)
     plt.axhline(y=scale, xmin=0, xmax=1)
     try:
         plt.savefig(".\\results\\"+self.stock_name+".png", dpi=200)
     except Exception:
         print "save png file error!"
     mysql.close_connect()
 def analy_big_trans(self, stock_name, gate_money, start_date, end_date, plt, color):
     delta_days = (end_date - start_date).days
     mysql = MySQL('trans')
     mysql.connect()
     for day in xrange(0, delta_days, 1):
         today = start_date + timedelta(days=day)
         next_day = start_date + timedelta(days=day+1)
         state_where = "DEAL_DATE > '%s' and DEAL_DATE < '%s' and TOTAL_AMOUNT > %d" % (today, next_day, gate_money)
         big_data = mysql.query_where(stock_name, state_where)
         state_where = "DEAL_DATE > '%s' and DEAL_DATE < '%s'" % (today, next_day)
         all_data = mysql.query_where(stock_name, state_where)
         cnt_big_data = len(big_data)
         cnt_all_data = len(all_data)
         if cnt_all_data is not 0:
             perc = (float(cnt_big_data) / cnt_all_data) * 100
         else:
             perc = 0
         plt.scatter(today, perc, c=color)
     mysql.close_connect()
 def analysis_deal_price(self, stock_name, start_date, end_date, plt, color):
     one_day = timedelta(days=1)
     delta_days = (end_date - start_date).days
     mysql = MySQL('trans')
     mysql.connect()
     for day in xrange(0, delta_days, 1):
         query_day = start_date + timedelta(days=day)
         state_where = "DEAL_DATE > '%s' and DEAL_DATE < '%s'" % (query_day, query_day + one_day)
         data = mysql.query_where(stock_name, state_where)
         ret = self.max_data(data)
         # ax.scatter(query_day, ret, c=color)
         plt.plot(query_day, ret, 'o-', c=color)
     mysql.close_connect()
 def analysis_close_price(self, stock_name, start_date, end_date, plt, color):
     one_day = timedelta(days=1)
     delta_days = (end_date - start_date).days
     mysql = MySQL('daily')
     mysql.connect()
     for day in xrange(0, delta_days, 1):
         query_day = start_date + timedelta(days=day)
         state_where = "DATE = '%s'" % query_day
         data = mysql.query_where(stock_name, state_where)
         if len(data) > 0:
             plt.scatter(query_day, data[0][5], c=color)
         else:
             plt.scatter(query_day, 0, c=color)
     mysql.close_connect()