# -*- coding: utf-8 -*- import datetime, time, heapq, cx_Oracle #2rd sheet def get_5mins_3A_LOG(): conn = cx_Oracle.connect('huawei_cem/[email protected]:1521/BLADE2') curs = conn.cursor() sql_sentence = r'SELECT * FROM FCAR.LOG WHERE TIMESTAMP >= SYSDATE - (5/1440) ORDER BY TIMESTAMP' rr = curs.execute (sql_sentence) for r in rr: yield [r[3], r[2], r[0], r[4], r[1]] curs.close() conn.close() # ORDER BY TIMESTAMP DESC ''' def get_5mins_3A_iterator(sheetname, timestamp_index): conn = cx_Oracle.connect('huawei_cem/[email protected]:1521/BLADE2') curs = conn.cursor() sql_sentence = r'SELECT * FROM {} ORDER BY TIMESTAMP DESC'.format(sheetname) rr = curs.execute (sql_sentence) row_b = rr.fetchone() now = row_b[timestamp_index] t = timestamp_index yield row_b[t], row_b[t - 1], row_b[t - 3], row_b[t + 1], row_b[t - 2] for row in rr: if(now - row[timestamp_index] > datetime.timedelta(minutes=5)): break yield row[t], row[t - 1], row[t - 3], row[t + 1], row[t - 2] curs.close() conn.close() ''' def get_5mins_3A_file(iter_LOG): time_ = datetime.datetime.now() ftime = time_.strftime("%Y%m%d%H%M%S") txt_outcome = ftime + ".txt" with open(txt_outcome, "a") as f: for x in iter_LOG: x[0] = str(int(time.mktime(x[0].timetuple()))) if x[1] == 'Interim-Update' or x[1] == 'Start': f.write('|'+x[0]+'|0'+'|'*4+x[1]+'|'*4+x[2]+'|'+x[3]+'|'*2+x[4]+'|'*15) elif x[1] == 'Stop': f.write('|'*3+x[0]+'|500||'+x[1] +'|'*4+x[2]+'|'+x[3]+'|'*2+x[4]+'|'*15) f.write('\n') if __name__ == '__main__': #for x in get_5mins_3A_LOG(): #print(x) iter_LOG = get_5mins_3A_LOG() get_5mins_3A_file(iter_LOG)
3A
猜你喜欢
转载自www.cnblogs.com/kHrystal/p/10159752.html
今日推荐
周排行