def getFilteredAll(): try: start = sys.argv[1] except IndexError: start = '' try: end = sys.argv[2] except IndexError: end = '' try: msgid = sys.argv[3] except IndexError: msgid = 32 sensors = qs.GetSensorDF() for s in range(len(sensors)): targetTable = sensors.name[s] df = qs.GetRawAccelData(siteid = targetTable, fromTime = start, toTime = end, msgid = msgid) numElements = len(df.index) qs.PrintOut("Number of %s Raw elements: %s" % (targetTable, numElements)) if numElements > 0: df_filtered = fs.applyFilters(df, orthof=True, rangef=True, outlierf=True) numFiltered = len(df_filtered.index) if numFiltered > 0: qs.PrintOut("Number of %s filtered elements: %s" % (targetTable, numFiltered)) #print df_filtered else: qs.PrintOut("No valid filtered data for %s" % (targetTable))
orthof=True, rangef=True, outlierf=False) df_filtered = fs.applyFilters(df, orthof=False, rangef=False, outlierf=True) numFiltered = len(df_filtered.index) drawcountx = df_resampled.x.count() drawcounty = df_resampled.y.count() drawcountz = df_resampled.z.count() dfinalcountx = df_filtered.x.count() dfinalcounty = df_filtered.y.count() dfinalcountz = df_filtered.z.count() if numFiltered > 0: qs.PrintOut("Data Count Summary for %s" % (targetTable)) qs.PrintOut("Raw Data (resampled without pad)") qs.PrintOut("Xraw: %s" % (drawcountx)) qs.PrintOut("Yraw: %s" % (drawcounty)) qs.PrintOut("Zraw: %s" % (drawcountz)) qs.PrintOut("Filtered Data") qs.PrintOut("Xf: %s" % (dfinalcountx)) qs.PrintOut("Yf: %s" % (dfinalcounty)) qs.PrintOut("Zf: %s" % (dfinalcountz)) #print df_filtered else: print "No valid filtered data for %s" % (targetTable)
def getFilteredData(isCmd = True, inSite = "", inNode = 1, inStart = "", inEnd = "", inMsgid = 32): if isCmd == True: try: #site selection site = sys.argv[1] except IndexError: print "No site has been selected. Script unable to run!" return try: #node selection node = sys.argv[2] if node == 'nil': node = -1 except IndexError: node = -1 try: #start date start = sys.argv[3] if start == 'nil': start = '' except IndexError: start = '' try: #end date end = sys.argv[4] if end == 'nil': end = '' except IndexError: end = '' try: #switch between accel 1 and 2 msgid = sys.argv[5] if msgid == 'nil': msgid = 32 except IndexError: msgid = 32 else: site = inSite node = inNode start = inStart end = inEnd msgid = inMsgid #print "variables: %s %s %s %s %s" % (site,node,start,end,msgid) df = qs.GetRawAccelData(siteid = site, fromTime = start, toTime = end, msgid = msgid, targetnode = node) numElements = len(df.index) qs.PrintOut("Number of %s Raw elements: %s" % (site, numElements)) if numElements > 0: df_filtered = fs.applyFilters(df, orthof=True, rangef=True, outlierf=False) numFiltered = len(df_filtered.index) if numFiltered > 0: qs.PrintOut("Number of %s filtered elements: %s" % (site, numFiltered)) return df_filtered else: qs.PrintOut("No valid filtered data for %s" % (site)) return pd.DataFrame() #return empty dataframe return pd.DataFrame()
def GenLsbAlerts(): sites = qs.GetSensorList() alertTxt = "" alertTxt2 = "" print "Getting lsb alerts" for site in sites: for nid in range(1, site.nos + 1): df = ofd.getFilteredData( isCmd=False, inSite=site.name, inNode=nid, inStart=(dt.now() - td(7)).strftime("%y/%m/%d %H:%M:%S")) isDFempty = df.empty if isDFempty == True: qs.PrintOut('No Data Available... for %s %s' % (site.name, nid)) continue df = df.set_index(['ts']) df2 = df.copy() dfa = [] try: df3 = df2.resample('30Min').fillna(method='pad') except pd.core.groupby.DataError: #print "No data to resample %s %s" % (site.name, nid) continue dfv = df3 - df3.shift(12) if len(dfa) == 0: dfa = dfv.copy() else: dfa = dfa.append(dfv) window = 48 dfarm = pd.rolling_mean(dfa, window) dfarm = dfarm[dfarm.index > dt.now() - td(1)] if (((abs(dfarm.x) > 0.25) | (abs(dfarm.y) > 0.25) | (abs(dfarm.z) > 1.0)).any()): ins = "%s,%s" % (site.name, nid) alertTxt += ins alertTxt2 += ins print ins + '\t', if ((abs(dfarm.x) > 0.25).any()): print 'x', alertTxt += ',1' alertTxt2 += ',' + repr(max(abs(dfarm.x))) else: alertTxt += ',0' alertTxt2 += ',0' if ((abs(dfarm.y) > 0.25).any()): print 'y', alertTxt += ',1' alertTxt2 += ',' + repr(max(abs(dfarm.y))) else: alertTxt += ',0' alertTxt2 += ',0' if ((abs(dfarm.z) > 1.0).any()): print 'z', alertTxt += ',1' alertTxt2 += ',' + repr(max(abs(dfarm.z))) else: alertTxt += ',0' alertTxt2 += ',0' print '' alertTxt += '\n' alertTxt2 += '\n' f = open('lsbalerts.csv', 'w') f.write(alertTxt) f.close() f = open('lsbalerts2.csv', 'w') f.write(alertTxt2) f.close()