def FORMAT_READ_DATA(regObject, MID): if not regObject: raise ParamNullError, "Register object passed is null" if not MID: raise ParamNullError, "Meter Id passed is null" if not isinstance(MID, int): raise ParamInvalidTypeError, "Meter id pass is of wrong type (should be int)" #if not isinstance(regObject, str): # raise ParamInvalidTypeError, "Register object passed is of wrong type: "+str(type(k)) try: r1=int(time.time()) row = str(DEVICE_ID)+","+str(MID)+","+str(r1) for i in range (0,(BLOCK_SIZE-1),2): for j in POSITION_HEADER: if(j == i): kt= (regObject.registers[i+1]<<16) + regObject.registers[i] #Formating & Filtering collected data / making it suitable for CSV format kkt =","+ str(convert(kt)) row = row +kkt row=row[:-1]+"\n" return row except: client = None client = CONNECT_TO_METER() lgr.error('Unexpected Error: FORMAT_READ_DATA', sys.exc_info()) print 'Unexpected Error: FORMAT_READ_DATA', sys.exc_info() pass
def FORMAT_READ_DATA(regObject, MID): if not regObject: raise ParamNullError, "Register object passed is null" if not MID: raise ParamNullError, "Meter Id passed is null" if not isinstance(MID, int): raise ParamInvalidTypeError, "Meter id pass is of wrong type (should be int)" #if not isinstance(regObject, str): # raise ParamInvalidTypeError, "Register object passed is of wrong type: "+str(type(k)) try: r1 = int(time.time()) row = str(DEVICE_ID) + "," + str(MID) + "," + str(r1) for i in range(0, (BLOCK_SIZE - 1), 2): for j in POSITION_HEADER: if (j == i): kt = ( regObject.registers[i + 1] << 16 ) + regObject.registers[ i] #Formating & Filtering collected data / making it suitable for CSV format kkt = "," + str(convert(kt)) row = row + kkt row = row[:-1] + "\n" return row except: client = None client = CONNECT_TO_METER() lgr.error('Unexpected Error: FORMAT_READ_DATA', sys.exc_info()) print 'Unexpected Error: FORMAT_READ_DATA', sys.exc_info() pass
def zmq_producer(context, client): socket = context.socket(zmq.PUB) socket.connect('tcp://127.0.0.1:5000') while True: now_time=int(time.time()) now = datetime.datetime.now() now_day=now.day now_month=now.month global start_time, start_day, count if ((now_time-start_time) > THRESHOLD_TIME) or (now_day!=start_day): count = count + 1 makeFolder(now_day, now_month) delete_older_folders(now) f =open(DATA_BASE_PATH +str(now_day)+"_"+str(now_month)+"/"+str(count-1)+".csv","a") f.write(HEADER) f.close() start_time=now_time start_day=now_day start_month=now_month else: for mId in range (0,len(METER_ID)): try: MID=METER_ID[mId] r1=int(time.time()) row = str(DEVICE_ID)+","+str(MID)+","+str(r1)#Writing time and other variables in row k = READ_METER_DATA(BASE_REGISTER,BLOCK_SIZE, MID, client) #Calling function to read meter for i in range (0,(BLOCK_SIZE-1),2): kt= (k.registers[i+1]<<16) + k.registers[i] #Formating & Filtering collected data / making it suitable for CSV format kkt =","+ str(convert(kt)) row = row +kkt print "Meter: "+str(MID) +"\n"+str(row) row=row[:-1]+"\n" global start_day, start_month makeFolder(start_day,start_month) socket.send(row) #sending meter data (row) to socket for live visualization f =open(DATA_BASE_PATH +str(start_day)+"_"+str(start_month)+"/"+str(count)+".csv","a") f.write(row) #writing meter data (row) in CSV gevent.sleep(0.05) #never remove this delay / you may change amount of delay f.close() except Exception as e: print "Meter: "+str(MID)+" \n" + e.__str__() log_file=open(DATA_BASE_PATH+"Meter_"+str(MID)+"Meterlog.txt","a") log_file.write(str(time.time())+" "+e.__str__()+"\n") log_file.close() client = None client = CONNECT_TO_METER()
def plotting(strabismus=True, tellers=True): global patient_id, exam_id, Termx, Termy, midpointX, midpointY with open('tmp.json', 'rb') as j: input_json = json.loads(j.read()) print(f"Protocol : {input_json['Protocol']}") patient_id = input_json.get("PatientId", 'No Patient Id') exam_id = input_json.get("ExamId", 'No Exam Id') df = convert(input_json) Termx = input_json.get("ScreenWidth", 684) Termy = input_json.get("ScreenHight", 456) midpointX = int(Termx / 2) midpointY = int(Termy / 2) if (df.empty): print( "NO DATA : number of rows (data points) for left/right/both eyes is lower than 8 !" ) return if strabismus: strabismus_to_plot = [{ 'loc': 'up', 'x': 'lx', 'y': 'ly', 'text': 'L Eye - closed' }, { 'loc': 'up', 'x': 'rx', 'y': 'ry', 'text': 'R Eye - opened' }, { 'loc': 'down', 'x': 'lx', 'y': 'ly', 'text': 'L Eye - opened' }, { 'loc': 'down', 'x': 'rx', 'y': 'ry', 'text': 'R Eye - closed' }] start_time_strabismus = time.time() # with removing outliers up_case_draw, down_case_draw = collecting_drawing_data(df) if up_case_draw.empty or down_case_draw.empty: print("Empty Strabismus DataFrame !") else: draw(down_case_draw, up_case_draw, strabismus_to_plot) print( f"Strabismus --- {(time.time() - start_time_strabismus)} seconds ---" ) if tellers: start_time_tellers = time.time() teller_df = get_teller_data(df) if teller_df.empty: print("Empty Tellers DataFrame !") else: get_params(teller_df) print(f"Tellers --- {(time.time() - start_time_tellers)} seconds ---")