Private
Public Access
1
0

moved CP segment findin/sorting to dataprep

This commit is contained in:
Sander Roosendaal
2017-06-10 21:38:26 -04:00
parent bd7b003280
commit 563c0903cc
3 changed files with 79 additions and 61 deletions

View File

@@ -44,6 +44,7 @@ import sqlalchemy as sa
import sys
from utils import lbstoN
from scipy.interpolate import griddata
import django_rq
queue = django_rq.get_queue('default')
@@ -138,6 +139,71 @@ def filter_df(datadf,fieldname,value,largerthan=True):
return datadf
def getcp(dfgrouped,logarr):
delta = []
cpvalue = []
avgpower = {}
#avgpower[0] = 0
for id,group in dfgrouped:
tt = group['time'].copy()
ww = group['power'].copy()
tmax = tt.max()
newlen = int(tmax/2000.)
print newlen,len(ww)
newt = np.arange(newlen)*tmax/float(newlen)
neww = griddata(tt.values,
ww.values,
newt,method='linear',
rescale=True)
#tt = pd.Series(newt)
#ww = pd.Series(neww)
try:
avgpower[id] = int(ww.mean())
except ValueError:
avgpower[id] = '---'
if not np.isnan(ww.mean()):
length = len(ww)
dt = []
cpw = []
for i in range(length-2):
w_roll = ww.rolling(i+2).mean().dropna()
if len(w_roll):
# now goes with # data points - should be fixed seconds
indexmax = w_roll.idxmax(axis=1)
try:
t_0 = tt.ix[indexmax]
t_1 = tt.ix[indexmax-i]
deltat = 1.0e-3*(t_0-t_1)
wmax = w_roll.ix[indexmax]
if not np.isnan(deltat) and not np.isnan(wmax):
dt.append(deltat)
cpw.append(wmax)
except KeyError:
pass
dt = pd.Series(dt)
cpw = pd.Series(cpw)
cpvalues = griddata(dt.values,
cpw.values,
logarr,method='linear',
rescale=True)
for cpv in cpvalues:
cpvalue.append(cpv)
for d in logarr:
delta.append(d)
delta = pd.Series(delta,name='Delta')
cpvalue = pd.Series(cpvalue,name='CP')
return delta,cpvalue,avgpower
def clean_df_stats(datadf,workstrokesonly=True,ignorehr=True,
ignoreadvanced=False):
# clean data remove zeros and negative values