diff --git a/cloud_codeorganization.pptx b/cloud_codeorganization.pptx deleted file mode 100644 index 76febc6..0000000 Binary files a/cloud_codeorganization.pptx and /dev/null differ diff --git a/current_GUIcode.py b/current_GUIcode.py deleted file mode 100644 index d924327..0000000 --- a/current_GUIcode.py +++ /dev/null @@ -1,744 +0,0 @@ - # 1. Name of the test is always Malaria - # 2. Close button to be checked as abort button - # 3. Exceptions for network connection, camera. - - - - - #Things to be worked on: - # 1. On window closed by clicking x at top right corner, the application should terminate - - # 2. On abort button Clicked, the C++ API should be killed - - # 1. Progressbar speed increased with iterations - - # (SOLVED) 5. Setting user defined resolutions for image capture in pylon programs - - # (SOLVED) 9. Auto focus code for variance calculation - - # (SOLVED)2. Stopping/killing threads on abort - - # (SOLVED)8. Adjust time for sending data through FTP that should be by stopping or killing threads while they are sleeping .... (Same as 2) - - # (SOLVED)3. Focusing window pulse - - # (SOLVED)4. sending data for analysis in progress bar - - # (SOLVED)6. On abort, stop progress bar. - - # (SOLVED)7. Run focussing only on start up.. Ask jayesh about it.. - - # (SOLVED)1.Command line executions in os.system for basler camera acquisition -global ip1 -global ip2 -global ip3 -global batches -global numframes -batches=2 -numframes=5000 -ip1="54.191.132.121" -ip2="54.191.13.206" -ip3="52.38.126.238" -#!/usr/bin/python -import numpy -#import cv2 -#from pyfirmata import Arduino, util -from gi.repository import Gtk, GObject -import time -from time import sleep -import os -import threading -import sys -import thread -from time import sleep -global count -global x -from threading import Thread -from locale import gettext as _ -import subprocess -import ftplib -from ftplib import FTP -#import gpio -import datetime -#global Thread1 -#global Thread2 -global Acquire -Acquire = False -global ExitVLCThread -ExitVLCThread = False -global Kill -Kill=False -global SendCellDataThread -SendCellDataThread = False -import Queue -global error1 -global error2 -global error3 -global test -global f -global filename -global compress -global st -error1=0 -error2=0 -error3=0 -q=Queue.Queue(1) - -#Create a directory to acquire images. -#os.mkdir('/home/odroid/BloodAnalyser/AcquiredData/PatientInformation') -if os.path.isdir("/home/odroid/BloodAnalyser/AcquiredData/"): - os.system("rm -r /home/odroid/BloodAnalyser/AcquiredData/") -os.mkdir('/home/odroid/BloodAnalyser/AcquiredData/') -os.mkdir('/home/odroid/BloodAnalyser/AcquiredData/PatientInformation') - - -class patientID(Gtk.Window): - def __init__(self): - self.builder = Gtk.Builder() - global name - global age - #Get objects from patient ID Glade file - self.builder.add_from_file('./patientID.glade') - self.window = self.builder.get_object('entrywindow') - self.nextbutton = self.builder.get_object('button1') - self.okbutton=self.builder.get_object('okbutton') - self.name = self.builder.get_object('name') - self.age = self.builder.get_object('age') - self.entryname=self.builder.get_object('entryname') - self.entryage=self.builder.get_object('entryage') - self.entrypatientID=self.builder.get_object('entrypatientID') - #self.check_editable = Gtk.CheckButton("entryname") - - #self.entryname = Gtk.Entry() - - self.patientID = self.builder.get_object('patientID') - self.builder.connect_signals(self) - #self.entryname = Gtk.Entry() - #self.entryage = Gtk.Entry() - #self.entrypatientID = Gtk.Entry() - - #print(self.entryname.get_text()) - print('rashmi') - - self.window.show() - def on_okbutton_clicked(self,button): - global name - global age - global patientID - global st - ts=time.time() - #blood=BloodAnalyser() - st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H_%M_%S') - name=self.entryname.get_text() - age=self.entryage.get_text() - patientID=self.entrypatientID.get_text() - self.window.hide() - #filename=folder.append(st) - #filename=filename.append(".txt") - global test - test="malaria" - global filename - filename=folder+st+".txt" - - #return - - -class splashScreen(Gtk.Window): - def __init__(self): - - self.builder = Gtk.Builder() - self.builder.add_from_file('./splash.glade') - self.builder.connect_signals(self) - self.window = self.builder.get_object('applicationwindow1') - self.image1=self.builder.get_object("image1") - self.window.show() - #self.done=True - #GObject.timeout_add(5000,) - - self.window.show -class AutoFocus(Gtk.Window): - def __init__(self): - self.builder = Gtk.Builder() - self.builder.add_from_file('./AutoFocus.glade') - self.builder.connect_signals(self) - self.window = self.builder.get_object('AutoFocus_window') - self.image1=self.builder.get_object("image1") - self.autofocus_pulse=self.builder.get_object("autofocus_pulse") - - self.autofocus_start=False - #threading.Thread(target=self.UpdateImages).start() - - def pulse_invoke(self): - #self.window.show() - - try: - os.system('v4l2-ctl -c exposure_absolute=1') - os.system('mplayer tv:// driver=v4l2:device=/dev/video0') - - - blood_analyser.vlc_invoke() - #return - except: - error2=True - return error2 - - def variance(self): - try: - os.chdir('/home/odroid/BloodAnalyser/AutoFocus') - #os.system("make clean") - #os.system("source /opt/pylon4/bin/pylon-setup-env.sh /opt/pylon4") - #os.system("make") - #os.system("chmod 777 autofocus") - #os.system("ls") - - #itime=time.time() - board=Arduino('/dev/ttyACM0') - - #cap = cv2.VideoCapture(0) - n=1 - mylistForward=[] - while(n < 50): - board.digital[5].write(1) - board.digital[6].write(1) - # Capture frame-by-frame - os.system("mplayer tv:// -tv driver=v4l2:device=/dev/video0:fps=20 --frames=2 -vo png") - - # Our operations on the frame come here - - frame=cv2.imread('/home/odroid/BloodAnalyser/AutoFocus/00000002.png') - #image_file = '/home/rbccps/BloodAnalyser/AutoFocus/focus%d.png'%n - self.window.show() - - self.image1.set_from_file('/home/odroid/BloodAnalyser/AutoFocus/00000002.png') - a=numpy.var(frame) - print(a) - mylistForward.append(a) - sleep(0.1) - n=n+1 - maxMeasure=max(mylistForward) - maxMeasure = maxMeasure - 40 - cMeas=0 - n=0 - print '**************Motor Moving Backwards*******************' - while(n<50): - print("While loop entered") - if cMeas > maxMeasure: - board.digital[5].write(0) - break - board.digital[5].write(1) - board.digital[6].write(0) - - os.system("mplayer tv:// -tv driver=v4l2:device=/dev/video0:fps=20 --frames=2 -vo png") - self.image1.set_from_file('/home/odroid/BloodAnalyser/AutoFocus/00000002.png') - frame1=cv2.imread('/home/odroid/BloodAnalyser/AutoFocus/00000002.png') - cMeas=numpy.var(frame1) - print(cMeas) - n=n+1 - sleep(0.1) - board.digital[5].write(0) - - - #cv2.destroyAllWindows() - - #n=cap.release() - self.window.hide() - print(n) - # When everything done, release the capture - print("Capture released") - maxMeasure= max(mylistForward) - blood_analyser.vlc_invoke() - - #cv2.destroyAllWindows() - - except: - global error1 - print("HARDWARE MISSING") - error1=1 - return error1 - - - - def on_timeout(self, user_data): - - if self.activity_mode: - self.autofocus_pulse.pulse() - else: - new_value = self.autofocus_pulse.get_fraction() + 0.01 - - if new_value > 1: - new_value = 0 - - self.progressbar.set_fraction(new_value) - - # As this is a timeout function, return True so that it - # continues to get called - return True - - -class quit_window(Gtk.Window): - def __init__(self): - self.builder = Gtk.Builder() - os.chdir('/home/odroid/BloodAnalyser') - self.builder.add_from_file('./quit_window.glade') - self.builder.connect_signals(self) - self.window = self.builder.get_object('quit_window') - self.finishbutton = self.builder.get_object('finishbutton') - self.another_testbutton = self.builder.get_object('another_testbutton') - - - - def show_screen(self): - self.window.show() - - - def on_finishbutton_activate(self, widget): - os.system('rm ./celldata.zip') - os.system('rm -r ./AcquiredData') - os.system('mkdir ./AcquiredData') - Gtk.main_quit() - - - def on_another_testbutton_activate(self,widget): - #os.system('rm ./celldata.zip') - #os.system('rm -r ./AcquiredData') - #os.system('mkdir ./AcquiredData') - print "ANother test selected" - self.progressbar.set_fraction(0.0) - self.timeout_id = GObject.timeout_add(False, self.on_timeout,None) - - blood_analyser.start.set_label("START TEST") - blood_analyser = BloodAnalyser() - #splScr = splashScreen() - patient_ID=patientID() - Gtk.main() - - - - - -class BloodAnalyser(Gtk.Window): - - def __init__(self): - global count - count=0 - global x - x=0 - self.builder = Gtk.Builder() - self.builder.add_from_file('./bloodAnalyser.glade') - self.builder.connect_signals(self) - self.window = self.builder.get_object('window1') - self.window.show() - - - self.infectious_disease = self.builder.get_object("infectious_disease") - self.hamatological_disorder =self.builder.get_object("hematological") - self.completebloodcount = self.builder.get_object("completebloodcount") - self.malaria = self.builder.get_object("malaria") - self.dengue = self.builder.get_object("dengue") - self.tuberculosis = self.builder.get_object("tuberculosis") - self.spherocytosis = self.builder.get_object("spherocytosis") - self.sicklecellanemia=self.builder.get_object("sicklecellanemia") - self.hereditaryelliptocytosis=self.builder.get_object("hereditaryelliptocytosis") - self.start = self.builder.get_object("start") - self.progressbar = self.builder.get_object("progressbar") - self.image1=self.builder.get_object("image1") - self.image2=self.builder.get_object("image2") - - self.malaria.set_sensitive(True) - self.dengue.set_sensitive(True) - self.tuberculosis.set_sensitive(True) - self.spherocytosis.set_sensitive(False) - self.sicklecellanemia.set_sensitive(False) - self.hereditaryelliptocytosis.set_sensitive(False) - - - def on_infectiousdisease_toggled(self, button): - if button.get_active(): - print "infectious" - self.malaria.set_sensitive(True) - self.dengue.set_sensitive(True) - self.tuberculosis.set_sensitive(True) - self.spherocytosis.set_sensitive(False) - self.sicklecellanemia.set_sensitive(False) - self.hereditaryelliptocytosis.set_sensitive(False) - - - #print "infectious" - - def on_hematological_toggled(self, button): - if button.get_active(): - print "hematology" - self.spherocytosis.set_sensitive(True) - self.sicklecellanemia.set_sensitive(True) - self.hereditaryelliptocytosis.set_sensitive(True) - self.malaria.set_sensitive(False) - self.dengue.set_sensitive(False) - self.tuberculosis.set_sensitive(False) - - - def on_completebloodcount_toggled(self, button): - global test - test="Complete Blood Count" - print "blood count" - self.spherocytosis.set_sensitive(False) - self.sicklecellanemia.set_sensitive(False) - self.hereditaryelliptocytosis.set_sensitive(False) - self.malaria.set_sensitive(False) - self.dengue.set_sensitive(False) - self.tuberculosis.set_sensitive(False) - self.hereditaryelliptocytosis.set_sensitive(False) - - def on_malaria_toggled(self, widget): - - if malaria.get_active(): - global test - test="Malaria" - print "on" - #else: - # print "off" - def on_hereditaryelliptocytosis_toggled(self, widget): - if hereditaryelliptocytosis.get_active(): - print "hereditaryelliptocytosis" - global test - test="hereditaryelliptocytosis" - - def on_timeout_thread_end(self, user_data): - global error1 - global error2 - global error3 - global filename - # Error handling if the Motor pulse giving Arduino board is missing - if error1==1: - dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "Error!") - dialog.format_secondary_text("Required hardware missing!.. Cannot run application") - response = dialog.run() - - self.progressbar.set_fraction(0.0) - self.timeout_id = GObject.timeout_add(False, self.on_timeout,None) - if response == Gtk.ResponseType.OK: - self.window.close() - dialog.destroy() - self.window.hide() - Gtk.main_quit() - # Error handling if the camera is not operating properly - elif error2==1: - dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "Error!") - dialog.format_secondary_text("Camera interface not found!.. Cannot run application") - response = dialog.run() - - self.progressbar.set_fraction(0.0) - self.timeout_id = GObject.timeout_add(False, self.on_timeout,None) - if response == Gtk.ResponseType.OK: - self.window.close() - dialog.destroy() - self.window.hide() - Gtk.main_quit() - - elif error3==1: - dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "Sending Data Error!") - dialog.format_secondary_text("Cannot send data.") - response = dialog.run() - - self.progressbar.set_fraction(0.0) - self.timeout_id = GObject.timeout_add(False, self.on_timeout,None) - if response == Gtk.ResponseType.OK: - self.window.close() - dialog.destroy() - self.window.hide() - Gtk.main_quit() - sys.exit() - - else: - if self.Thread1.is_alive(): - test_ended = False - - else: - test_ended = True - text="Finished Sending Data !" - - # text="Data Sent for Analysis" - self.progressbar.set_text(text) - self.activity=False - #print("send_data status=%s",SendCellDataThread) - self.progressbar.set_fraction(0.0) - self.timeout_id = GObject.timeout_add(1, self.on_timeout,None) - - - - #self.progressbar.set_fraction(0.0) - GObject.source_remove(self.timeout_id) - dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, "Test Complete !") - dialog.format_secondary_text("Do you want to run another test?") - response = dialog.run() - if response == Gtk.ResponseType.YES: - dialog.destroy() - self.window.hide() - Gtk.main_quit() - - - - dialog.destroy() - if response == Gtk.ResponseType.NO: - dialog.destroy() - #os.system('rm ./celldata.zip') - - dialog.destroy() - self.window.hide() - Gtk.main_quit() - sys.exit() - - - return False - return True - - - #print("Button", "was turned", state) - def on_start_clicked(self, widget): - global count - global ExitVLCThread - global Acquire - global Kill - global SendCellDataThread - global test - global st - global name - global age - global patientID - global filename - folder=("/home/odroid/BloodAnalyser/AcquiredData/") - #filename=folder.append(st) - #filename=filename.append(".txt") - filename=folder+'PatientInformation'+".txt" - f = open(filename,"w") #opens file with name of "test.txt" - - - #f.write("Name:\t") - f.write(name) - f.write("\n") - print(f) - - #f.write("Age:\t") - f.write(age) - f.write("\n") - - #f.write("PatientID:\t") - f.write(patientID) - f.write("\n") - - #f.write("Test Selected:\t") - f.write(test) - f.write("\n") - f.close() - #os.system('7z a /home/odroid/BloodAnalyser/AcquiredData/celldata.7z /home/odroid/BloodAnalyser/AcquiredData/PatientInformation') - #self.activity= False - #self.ftp_invoke() - - count=count+1 - print(count) - if (count ==1): - - print("Hello World!") - dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, "Reminder! Suitable Cartridge had to be loaded before starting the test.") - dialog.format_secondary_text("Do you want to continue?") - response = dialog.run() - if response == Gtk.ResponseType.YES: - dialog.destroy() - self.start.set_label("ABORT TEST") - print("WARN dialog closed by clicking OK button") - - Acquire = True - print (Acquire) - #Kill = True - #print(Kill) - #global Thread1 - #global Thread2 - - - auto_focus=AutoFocus() - - #auto_focus.window.show() - #blood_analyser = BloodAnalyser() - - self.timeout_id_thread_end = GObject.timeout_add(500, self.on_timeout_thread_end, None) - - self.Thread1=threading.Thread(target=auto_focus.pulse_invoke) - #self.Thread1.start() - - #self.Thread1=threading.Thread(target=self.vlc_invoke) - self.Thread1.daemon=True - self.Thread1.start() - - - - elif response == Gtk.ResponseType.NO: - dialog.destroy() - print("WARN dialog closed by clicking CANCEL button") - count=0 - - else: - print(count) - dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.WARNING,Gtk.ButtonsType.YES_NO, "Test in progress!.. Do you still want to abort test?") - dialog.format_secondary_text("Click Yes to continue") - response = dialog.run() - if response == Gtk.ResponseType.YES: - - dialog.destroy() - self.window.hide() - Gtk.main_quit() - os.system('exit()') - print("Thread2=") - print(SendCellDataThread) - os.system("killall vlc") - - self.start.set_label("START TEST") - text2 = " " - count = 0 - self.progressbar.set_text(text2) - - self.progressbar.set_show_text(text2) - - self.progressbar.set_fraction(0.0) - self.activity= False -# self.timeout_id = GObject.timeout_add(0, self.on_timeout,None) - - - self.start.set_label("START TEST") - #os.system('rm ./celldata.zip') - os.system('rm -r ./AcquiredData') - os.system('mkdir ./AcquiredData') - print("WARN dialog closed by clicking OK button") - elif response == Gtk.ResponseType.NO: - count = 0 - dialog.destroy() - - def on_timeout(self, user_data): - if self.activity: - - new_value = self.progressbar.get_fraction() + 0.01 - - if new_value > 1: - new_value = 0 - - self.progressbar.set_fraction(new_value) - - return True - - - - - - def vlc_invoke(self): - #gobject.threads_init() - #os.system("v4l2-ctl -c exposure_absolute=1") - print ("Vlc invoked") - #similar to time.sleep() - #sleep(10) - n = 0 - global error2 - start_time=time.time() - - while (True): - - sleep(0.5) - print Acquire - if Acquire: - #print ('while acquire') - self.activity= 1 - - self.timeout_id = GObject.timeout_add(400, self.on_timeout,None) - - os.chdir('/home/odroid/BloodAnalyser/AcquiredData') - - - itime=time.time() - i=1 - - print("Time taken to capture =") - print(time.time()-itime) - - - - os.chdir('/home/odroid/BloodAnalyser/AcquiredData') - while(i" - print "Example: python server_script_threads.py 3" - sys.exit() - -instance_id = int(sys.argv[1]) -num_instances = int(sys.argv[2]) -print 'Starting instance id: %d, num_batches:%d'%(instance_id, num_instances) - - -class servercheck(): - - i=0 - path=("/home/ubuntu/") - print(path) - path_to_watch =os.path.join("/home/ubuntu/") - before = dict ([(f, None) for f in os.listdir (path_to_watch)]) - dir=os.chdir(os.path.join("/home/ubuntu/")) - it=time.time() - - while 1: - print "Checking for zip file..." - time.sleep (1) - after = dict ([(f, None) for f in os.listdir (path_to_watch)]) - added = [f for f in after if not f in before] - removed = [f for f in before if not f in after] - #print(removed) - if removed: - print "removed: ", ", ".join (removed) - - if added: - - added_file=", ".join (added) - print "added: ", ", ".join (added) - i=i+1 - if i<4: - file_name=("celldata.7z") - added_file=", ".join (added) - if added_file == file_name: - - time.sleep(130) - print "Removing celldata folder" - os.system("rm -rf celldata") - - print "Unzipping celldata.7z" - os.system("7z x celldata.7z") - - print "Removing zip file - celldata.7z" - os.system("rm celldata.7z") - - if os.path.isdir("./images"): - os.system("cp -r celldata/* images/") - else: - os.mkdir("./images/") - os.system("cp -r celldata/* images/") - - global ProcessThreads - ProcessThreads = [] - print os.getcwd() + '/celldata' - numImages = len(os.listdir(os.getcwd() + '/celldata')) - print "Number of images in the folder: %d"%numImages - numThreads = 5 - numImagesPerThread = numImages/numThreads - print "Starting %d threads- Total images: %d, Images per thread:%d"%(numThreads, numImages, numImagesPerThread) - - image_num_min = 2 # Starting from image 2 as image 1 is always black! - 39,5 28% - image_num_max = 0 - - for i in range (1, numThreads+1): - - image_num_max = image_num_min + numImagesPerThread - if image_num_max > 10000: - image_num_max=10000 - t = threading.Thread(target=process,args=(i, image_num_min, image_num_max)) - t.start() - ProcessThreads.append(t) - print 'Started thread %d for images %d to %d'%(i, image_num_min, image_num_max) - image_num_min = image_num_max + 1 - - for t in ProcessThreads: - t.join() - - totalCount = 0 - - for i in range (1, numThreads+1): - result_file = 'count' + str(i) + '.txt' - f = open(result_file, 'r') - count_str = f.readline() - count = int(count_str.split("=")[1]) - totalCount = totalCount + count - print "Thread:%d, Count:%d, Total Count:%d"%(i, count, totalCount) - os.system("rm -f " + result_file) - - print totalCount - - print totalCount - - writefile(totalCount) - #checkcountfiles() - - before=after - - def process(threadId, frame_no_min, frame_no_max): - result_file = 'count' + str(threadId) + '.txt' - cmd = 'sudo ./run_malariaExecutableArgs.sh /usr/local/MATLAB/MATLAB_Compiler_Runtime/v83/ %d %d %s'%(frame_no_min, frame_no_max, result_file) - print "ThreadId: %d, cmd =%s"%(threadId, cmd) - os.system(cmd) - return - - - def writefile(count): - #testsite_array = [] - #with open('PatientInformation.txt','r') as my_file: - # testsite_array = my_file.readlines() - #count=numpy.sum(testsite_array) - file_name = 'Instance' + str(instance_id) + '.txt' - f = open(file_name,'w') - f.write('%d'%count) - f.flush() - f.close() - cmd = 'sudo scp -i "jayesh1.pem" ' + file_name + ' ubuntu@ec2-54-200-214-228.us-west-2.compute.amazonaws.com:' - print cmd - os.system(cmd) - def checkcountfiles(): - path = '/home/ubuntu/' - files = [] - countFiles=1 - iteration=0 - totalCount=0 - cellcount=0 - textf1='Instance'+str(countFiles)+'.txt' - textf2='Instance'+str(countFiles+1)+'.txt' - textf3='Instance'+str(countFiles+2)+'.txt' - while True: - print "Checking for count files from Instances" - time.sleep(1) - if os.path.isfile(textf1) and os.path.isfile(textf2) and os.path.isfile(textf3): - - #print i - iteration=iteration+1 - print countFiles - textf='Instance'+str(iteration)+'.txt' - - f = open(textf,'r') - count_str = f.readline() - cellcount = int(count_str) - print 'The count of instance %d =%d'%(iteration,cellcount) - totalCount = totalCount + cellcount - - if iteration == num_instances: - print 'condition met' - print 'total count =%d'%totalCount - file_name="totalCount.txt" - f = open(file_name,'w') - f.write('%d'%totalCount) - f.flush() - f.close() - return - else: - print "Count files have not arrived" - 85% -