Demo entry 6762765

21

   

Submitted by 12 on Oct 17, 2018 at 10:41
Language: Python. Code size: 2.8 kB.

class Sequenz(object):
    def __init__(self, v_t,a_1,a_1_lang,delta_v1, t):
        self.v_t = v_t
        self.dauer=len(self.v_t)*0.5
        self.v_mean=self.v_t[np.where(self.v_t>0)].mean()
        #self.v_mean=self.v_t.mean()
        self.a_t=self.get_a_t()
        self.a_pos=self.a_t[np.where(self.a_t>0)[0]].mean()
        self.a_neg=self.a_t[np.where(self.a_t<0)[0]].mean()
        self.a_abs=abs(self.a_t).mean()
        self.B_V_Wechsel=len(self.a_t[np.where(self.a_t==0)[0]])-len(self.v_t[np.where(self.v_t==0)[0]])
        self.Klasse=self.get_Klasse(a_1,a_1_lang,delta_v1, t)
        self.Stop=len(self.Klasse[np.where(self.Klasse==0)[0]])*0.5/self.dauer*100
        self.Beschl=len(self.Klasse[np.where(self.Klasse==1)[0]])*0.5/self.dauer*100
        self.Kons=len(self.Klasse[np.where(self.Klasse==2)[0]])*0.5/self.dauer*100
        self.Verz=len(self.Klasse[np.where(self.Klasse==3)[0]])*0.5/self.dauer*100
        self.Schleich=len(self.Klasse[np.where(self.Klasse==4)[0]])*0.5/self.dauer*100
        #self.Mod=self.get_Reihfolge()
    def check(self):
        cc=[]
        if self.dauer==np.NaN or self.dauer==np.inf:
            cc.append('dauer==nan')
        if self.v_mean==np.NaN or self.v_mean==np.inf:
            cc.append('v_mean==nan')
        return cc
    def get_a_t(self):
        dv=np.zeros(len(self.v_t))
        if self.dauer<1:
            a_t=dv
        else:
            dv[1:-1]=(self.v_t[2:]-self.v_t[:-2])/2
            dv[0]=self.v_t[1]-self.v_t[0]
            dv[-1]=-self.v_t[-1]
            a_t=dv*20/3.6
            a_t[np.where(a_t>10)[0]]=7
        return a_t
    def get_Klasse(self,a_1, a_1_lang, delta_v1, t):
        Klasse=np.zeros(len(self.v_t))                   
        t = int(t)
        for i in range(0,len(self.v_t)): 
            if self.a_t[i] >= a_1:
                Klasse[i] = 1
            elif self.a_t[i] <= -a_1:
                Klasse[i] = 3
            else:
                # i_start anfangpunkt für Beschleunigung 3s-check
                if i >= t-1:
                    i_start = int(i - t + 1)
                    delta_Geschw = sum(self.a_t[i_start:i_start+t])*0.5
                    min_a = np.min(self.a_t[i_start:i_start+t])
                    max_a = np.max(self.a_t[i_start:i_start+t])
                    if min_a > a_1_lang and delta_Geschw > delta_v1:
                        Klasse[i_start:i_start+t] = 1
                    elif max_a < -a_1_lang and delta_Geschw < -delta_v1:
                        Klasse[i_start:i_start+t] = 3
            if Klasse[i]==0:
                if self.v_t[i] > 3:
                    Klasse[i] = 2
                elif self.v_t[i]>0.5:
                    Klasse[i] = 4
        return Klasse

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).