# -*- coding: utf-8 -*-
"""
Created on Tue Jun  6 09:28:17 2017

@author: Administrator
"""

import pandas as pd
import ToolModule as tm
#import datetime
import FilterDataModule as fd

def getData(code=None,startDate=None,endDate=None,ft=None):
    data_list = []
    code_list = []
    turnover_rate_list = []
    if code is None:
        allCode = fd.all_share_codes
    else:
        allCode = code
    #allCode = [x for x in allCode if (int(x) > 300999 or int(x) < 300000)]
    #print(len(allCode))
    for code in allCode:
        data = fd.getHisDataByCode(code,startDate,endDate)
        if isinstance(data,pd.DataFrame) and not data.empty and (ft is None or ft(data)):
            data = data[data.turnover > 0]
            turnover_rate_list.extend(list(data.turnover/data.turnover.min()))
            code_list.extend([code]*len(data))
            data_list.append(data)
            #print('==================')
            #print(data)
    #print(len(data_list))    
    frame = pd.concat(data_list)#,ignore_index=True)
    frame['code'] = code_list
    frame['turnover_rate'] = turnover_rate_list
    return frame

#data = getData('300024','2017-07-04')
data = getData(None,'2017-07-05','2017-07-04')
print(data)
@@ -1033,17 +1033,23 @@
    frame
-%5B
+.loc%5B:,
 'code'%5D 
@@ -1069,17 +1069,23 @@
    frame
-%5B
+.loc%5B:,
 'turnove
@@ -1176,61 +1176,322 @@
 ')%0Ad
-ata = getData(None,'2017-07-05','2017-07-04')%0Aprint(data
+ef FT(data):%0A    if len(data) == 3:%0A        return True%0A    else:%0A        return False%0Adata = getData(None,'2017-07-05','2017-07-03',ft=FT)%0Adata2 = data.groupby('code').apply(lambda x:x.p_change)%0A%0Ak1 = data2%5B(data2%5B'2017-07-04'%5D %3E 0) & (data2%5B'2017-07-03'%5D%3E8)%5D%0Ak2 = data2%5Bdata2%5B'2017-07-03'%5D%3E8%5D%0A%0Aprint(len(k1)/len(k2)
 )

change set moth