def alert_generation(disp_vel,colname,num_nodes,T_disp, T_velL2, T_velL3, k_ac_ax, num_nodes_to_check,end,proc_file_path,CSVFormat): # displacement and velocity at start and end of interval disp_vel = disp_vel.loc[(disp_vel.ts == start) | (disp_vel.ts == end)] LastGoodData= GetLastGoodDataFromDb(colname) #NEED TO GROUPBY ID THEN PROCESS NODE ALERT nodal_disp_vel = disp_vel.groupby('id') alert_out = nodal_disp_vel.apply(alert.node_alert2, colname=colname, num_nodes=num_nodes, T_disp=T_disp, T_velL2=T_velL2, T_velL3=T_velL3, k_ac_ax=k_ac_ax, lastgooddata=LastGoodData) #processing column-level alerts alert_out=alert.column_alert(alert_out, num_nodes_to_check, k_ac_ax) #trending_col=alert.trending_col(alert_out,colname) #adding 'ts' alert_out['ts']=end #setting ts and node_ID as indices alert_out=alert_out.set_index(['ts','id']) #checks if file exist, append latest alert; else, write new file if PrintProc: try: if os.path.exists(proc_file_path+colname+"/"+colname+" "+"alert"+CSVFormat) and os.stat(proc_file_path+colname+"/"+colname+" "+"alert"+CSVFormat).st_size != 0: alert_monthly=pd.read_csv(proc_file_path+colname+"/"+colname+" "+"alert"+CSVFormat,names=alert_headers,parse_dates='ts',index_col='ts') alert_monthly=alert_monthly[(alert_monthly.index>=end-timedelta(days=alert_file_length))] alert_monthly=alert_monthly.reset_index() alert_monthly=alert_monthly.set_index(['ts','id']) alert_monthly=alert_monthly.append(alert_out) alert_monthly=alert_monthly[alertgen_headers] alert_monthly.to_csv(proc_file_path+colname+"/"+colname+" "+"alert"+CSVFormat, sep=',', header=False,mode='w') else: if not os.path.exists(proc_file_path+colname+"/"): os.makedirs(proc_file_path+colname+"/") alert_out.to_csv(proc_file_path+colname+"/"+colname+" "+"alert"+CSVFormat, sep=',', header=False,mode='w') except: print "Error in Printing Proc" return alert_out
def alert_generation(colname,xz,xy,vel_xz,vel_xy,num_nodes, T_disp, T_velA1, T_velA2, k_ac_ax, num_nodes_to_check,end,CSVFormat): ##DESCRIPTION: ##returns node level alerts ##INPUT: ##colname; string; name of site ##xz; dataframe; horizontal linear displacements along the planes defined by xa-za ##xy; dataframe; horizontal linear displacements along the planes defined by xa-ya ##xz_vel; dataframe; velocity along the planes defined by xa-za ##xy_vel; dataframe; velocity along the planes defined by xa-ya ##num_nodes; float; number of nodes ##T_disp; float; threshold values for displacement ##T_velA1; float; threshold velocities correspoding to alert level A1 ##T_velA2; float; threshold velocities correspoding to alert level A2 ##k_ac_ax; float; minimum value of (minimum velocity / maximum velocity) required to consider movement as valid ##num_nodes_to_check; integer; number of adjacent nodes to check for validating current node alert ##end; ##CSVFormat; file type ##OUTPUT: ##alert_out #processing node-level alerts alert_out=alert.node_alert(colname,xz,xy,vel_xz,vel_xy,num_nodes, T_disp, T_velA1, T_velA2, k_ac_ax) #processing column-level alerts alert_out=alert.column_alert(alert_out, num_nodes_to_check, k_ac_ax) #trending_col=alert.trending_col(alert_out,colname) #adding 'ts' alert_out['ts']=end #setting ts and node_ID as indices alert_out=alert_out.set_index(['ts','id']) return alert_out
def alert_generation(colname,xz,xy,vel_xz,vel_xy,num_nodes, T_disp, T_velL2, T_velL3, k_ac_ax, num_nodes_to_check,end,proc_file_path,CSVFormat): ##DESCRIPTION: ##returns node level alerts ##INPUT: ##colname; string; name of site ##xz; dataframe; horizontal linear displacements along the planes defined by xa-za ##xy; dataframe; horizontal linear displacements along the planes defined by xa-ya ##xz_vel; dataframe; velocity along the planes defined by xa-za ##xy_vel; dataframe; velocity along the planes defined by xa-ya ##num_nodes; float; number of nodes ##T_disp; float; threshold values for displacement ##T_velL2; float; threshold velocities correspoding to alert level L2 ##T_velL3; float; threshold velocities correspoding to alert level L3 ##k_ac_ax; float; minimum value of (minimum velocity / maximum velocity) required to consider movement as valid ##num_nodes_to_check; integer; number of adjacent nodes to check for validating current node alert ##end; ##proc_file_path; file path ##CSVFormat; file type ##OUTPUT: ##alert_out #processing node-level alerts alert_out=alert.node_alert(colname,xz,xy,vel_xz,vel_xy,num_nodes, T_disp, T_velL2, T_velL3, k_ac_ax) #processing column-level alerts alert_out=alert.column_alert(alert_out, num_nodes_to_check, k_ac_ax) #trending_col=alert.trending_col(alert_out,colname) #adding 'ts' alert_out['ts']=end #setting ts and node_ID as indices alert_out=alert_out.set_index(['ts','id']) #checks if file exist, append latest alert; else, write new file if PrintProc: try: if os.path.exists(proc_file_path+colname+"/"+colname+" "+"alert"+"NoSmoothing"+CSVFormat) and os.stat(proc_file_path+colname+"/"+colname+" "+"alert"+"NoSmoothing"+CSVFormat).st_size != 0: alert_monthly=pd.read_csv(proc_file_path+colname+"/"+colname+" "+"alert"+"NoSmoothing"+CSVFormat,names=alert_headers,parse_dates='ts',index_col='ts') alert_monthly=alert_monthly[(alert_monthly.index>=end-timedelta(days=alert_file_length))] alert_monthly=alert_monthly.reset_index() alert_monthly=alert_monthly.set_index(['ts','id']) alert_monthly=alert_monthly.append(alert_out) alert_monthly=alert_monthly[alertgen_headers] alert_monthly.to_csv(proc_file_path+colname+"/"+colname+" "+"alert"+"NoSmoothing"+CSVFormat, sep=',', header=False,mode='w') else: if not os.path.exists(proc_file_path+colname+"/"): os.makedirs(proc_file_path+colname+"/") alert_out.to_csv(proc_file_path+colname+"/"+colname+" "+"alert"+"NoSmoothing"+CSVFormat, sep=',', header=False,mode='w') except: print "Error in Printing Proc" return alert_out
def alert_generation(colname, xz, xy, vel_xz, vel_xy, num_nodes, T_disp, T_velL2, T_velL3, k_ac_ax, num_nodes_to_check, end, proc_file_path, CSVFormat): ##DESCRIPTION: ##returns node level alerts ##INPUT: ##colname; string; name of site ##xz; dataframe; horizontal linear displacements along the planes defined by xa-za ##xy; dataframe; horizontal linear displacements along the planes defined by xa-ya ##xz_vel; dataframe; velocity along the planes defined by xa-za ##xy_vel; dataframe; velocity along the planes defined by xa-ya ##num_nodes; float; number of nodes ##T_disp; float; threshold values for displacement ##T_velL2; float; threshold velocities correspoding to alert level L2 ##T_velL3; float; threshold velocities correspoding to alert level L3 ##k_ac_ax; float; minimum value of (minimum velocity / maximum velocity) required to consider movement as valid ##num_nodes_to_check; integer; number of adjacent nodes to check for validating current node alert ##end; ##proc_file_path; file path ##CSVFormat; file type ##OUTPUT: ##alert_out #processing node-level alerts alert_out = alert.node_alert(colname, xz, xy, vel_xz, vel_xy, num_nodes, T_disp, T_velL2, T_velL3, k_ac_ax) #processing column-level alerts alert_out = alert.column_alert(alert_out, num_nodes_to_check, k_ac_ax) #trending_col=alert.trending_col(alert_out,colname) #adding 'ts' alert_out['ts'] = end #setting ts and node_ID as indices alert_out = alert_out.set_index(['ts', 'id']) #checks if file exist, append latest alert; else, write new file if PrintProc: try: if os.path.exists(proc_file_path + colname + "/" + colname + " " + "alert" + CSVFormat) and os.stat( proc_file_path + colname + "/" + colname + " " + "alert" + CSVFormat).st_size != 0: alert_monthly = pd.read_csv(proc_file_path + colname + "/" + colname + " " + "alert" + CSVFormat, names=alert_headers, parse_dates='ts', index_col='ts') alert_monthly = alert_monthly[( alert_monthly.index >= end - timedelta(days=alert_file_length))] alert_monthly = alert_monthly.reset_index() alert_monthly = alert_monthly.set_index(['ts', 'id']) alert_monthly = alert_monthly.append(alert_out) alert_monthly = alert_monthly[alertgen_headers] alert_monthly.to_csv(proc_file_path + colname + "/" + colname + " " + "alert" + CSVFormat, sep=',', header=False, mode='w') else: if not os.path.exists(proc_file_path + colname + "/"): os.makedirs(proc_file_path + colname + "/") alert_out.to_csv(proc_file_path + colname + "/" + colname + " " + "alert" + CSVFormat, sep=',', header=False, mode='w') except: print "\n" return alert_out