Exemple #1
0
    def onExit(self, termination = False, msg = None):
        if msg is not None:
            print msg
            writeFile(PROGRAM_LOG_PATH, '\n\n%s, %s'%(get_time_stamp(), msg))
        self.main_ai_conn.close()
        for i in range(NUMBER_OF_CAMERAS): self.main_vi_conn[i].close()
        self.main_schema_conn.close()
        self.main_msgB_conn.close()
        self.ai_conn.close()
        self.ao_conn.close()
        for i in range(NUMBER_OF_CAMERAS): self.vi_conn[i].close()
        self.schema_conn.close()
        self.msgB_conn.close()
        if termination:
            self.ai_p.terminate()
            self.ao_p.terminate()
            for i in range(NUMBER_OF_CAMERAS): self.vi_p[i].terminate()
            self.schema_p.terminate()
            self.msgB_p.terminate()

        ### checking log files and generating movie files
        ui = raw_input("The next process will go through all the log files in the output folder and try to generate movie files(mp4) deleting the temporary image folders.\nProceed? (Y/N)")
        if ui.strip().upper() == 'Y':
            uvcInst = uvc.VideoConverter()
            uvcInst.run()

            ### taging wave sound files
            print "-----------------------\n"
            ui = raw_input("The next process will go through all the wave-sound-files in the output folder and try to tag with proper category names.\nProceed? (Y/N)")
            if ui.strip().upper() == 'Y':
                ustInst = ust.WaveFileRecognizer(OUTPUT_PATH)
                ustInst.run()

            ### checking MR(Movements Record) files and generating PNG files to show it graphically
            print "-----------------------\n"
            ui = raw_input("The next process will go through all the MR(Movements Record) files in the output folder and try to generate PNG picture files drawing the movements.\nProceed? (Y/N)")
            if ui.strip().upper() == 'Y':
                umdInst = umd.M_drawer(OUTPUT_PATH)
                umdInst.run()

                ### Make folder for each type of files and move
                print "-----------------------\n"
                ui = raw_input("Make folder for each type of result files and movie files accordingly.\nProceed? (Y/N)")
                if ui.strip().upper() == 'Y':
                    umf.run()
Exemple #2
0
def schema_run(schema_conn):
# Running a schema which AA runs on thought a session
    writeFile(PROGRAM_LOG_PATH, "%s, ***** Staring of the program.\n\n"%get_time_stamp())
    chk_resource_usage(PROGRAM_LOG_PATH) # check the resource (cpu, memory) usage
    last_chk_resource_time = time()

    flag_session_changed_to_off = False
    flag_session_changed_to_on = False
    while True:
        if time()-last_chk_resource_time > 60 * 30: # every a half an hour
            chk_resource_usage(PROGRAM_LOG_PATH) # check the resource (cpu, memory) usage
            last_chk_resource_time = time()

        # If the session time is over, archive all the data
        # If the session time is resumed, update the log-file and csv-result-file.
        if chk_session_time(SESSION_START_HOUR, SESSION_END_HOUR) == False:
            if flag_session_changed_to_off == False: # 1st run after finishing the session-time
                if AAS.feeding_snd_play_time != -1: # if it's middle of a trial
                    AAS.terminate_trial() # terminate it.

                if flag_session_changed_to_on == True:
                # The session was on before
                # If this is True here, this means it's the very 1st time after staring the program.
                # Therefore, there will be nothing to archive.
                    print '*** The session is over.'
                    uvcInst = uvc.VideoConverter()
                    uvcInst.run()
                    #ustInst = ust.WaveFileRecognizer(OUTPUT_PATH)
                    #ustInst.run()
                    umdInst = umd.M_drawer(OUTPUT_PATH)
                    umdInst.run()
                    folder_name = get_time_stamp()[:10]
                    archive_folder_path = os.path.join('archive', folder_name)
                    umf.run(folder_name, archive_folder_path)
                    print '-------------------------------------------------------------'
                    print 'Archiving process is finished at %s.'%get_time_stamp()
                    print '-------------------------------------------------------------'

                flag_session_changed_to_off = True
                flag_session_changed_to_on = False

            if schema_conn.poll(): # check whether there's any message arrive through the pipe
                msg = schema_conn.recv() # receive the message
                if msg == 'q': break
            sleep(1)
            continue
        else:
            if flag_session_changed_to_on == False: # 1st run after starting the session-time
                print '-------------------------------------------------------------'
                print 'Session starts at %s.'%get_time_stamp()
                print '-------------------------------------------------------------'
                flag_session_changed_to_off = False
                flag_session_changed_to_on = True
                AAS.session_initialization() # Initialize the log-file and result-file

        msg = ""
        if AAO.main_msgB_conn.poll(): # any message from message board
            msg = AAO.main_msgB_conn.recv() # receive
        AAS.run(msg)

        ### msg checking for exiting the program
        if schema_conn.poll(): # check whether there's any message arrive through the pipe
            msg = schema_conn.recv() # receive the message
            if msg == 'q': break