-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbreak_point.py
56 lines (48 loc) · 1.59 KB
/
break_point.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pandas as pd
from multiprocessing import Pool
from functools import partial
import time
def fick(costr,key,fdn,snkDic):
flag=[True]*len(fdn)
stt=0
end=0
lix=0
ix=["stt","end"]+fdn
hapin=pd.DataFrame(columns=ix)
nr=costr.shape[0]
for i in range(nr):
index=costr.index[i]
row=costr.iloc[i,:]
if not row.any():
continue
if((index-lix>2000000)):
end=lix
hapin=hapin.append(pd.Series([stt]+[end]+list(flag),index=ix),ignore_index=True)
stt=index
flag=row
else:
fcj=flag&row
if not fcj.any():
if (i<(nr-1)) and (flag&costr.iloc[i+1,:]).any():
#print("%d %d"%(nr, i))
continue
end=lix
hapin=hapin.append(pd.Series([stt]+[end]+list(flag),index=ix),ignore_index=True)
stt=index
flag=row
else:
flag=fcj
lix=index
hapin=hapin.append(pd.Series([stt]+[index]+list(flag),index=ix),ignore_index=True)
hapin=pd.merge(hapin,pd.DataFrame(snkDic[key].loc[list(hapin.stt)]),how="left",left_on="stt",right_index=True)
return hapin
def gick(kch,sht,mc,fdname,sinfo):
input_list= [sht.loc[:,x].unstack() for x in sht]
fixtwo=partial(fick,key=kch,fdn=fdname,snkDic=sinfo)
start_time=time.time()
pool=Pool(processes=mc)
bkil=pool.map(fixtwo,input_list)
pool.close()
pool.join()
print("--- %s: %s seconds ---" %(kch, time.time()-start_time))
return bkil