Пример #1
0
    def getAllEventsTable(self):
        """
        Returns pandas table containing all found events for all found event types'
            * Primary mouse' meta data
            * Events' start time
            * Events' end time
            * Events' duration
        Returns:
            DataFrame
        """
        with mute_prints():
            all_event_names = getAllEvents(connection=self.conn)

        event_table =  pd.concat([self.getSingleEventTable(event_name)
                                    for event_name in all_event_names]
                                , axis=0)
        return event_table.sort_values("time").reset_index(drop=True)
def process( file ):

    print(file)

    mem = virtual_memory()
    availableMemoryGB = mem.total / 1000000000
    print( "Total memory on computer: (GB)", availableMemoryGB )

    if availableMemoryGB < 10:
        print( "Not enough memory to use cache load of events.")
        disableEventTimeLineCache()


    chronoFullFile = Chronometer("File " + file )

    connection = sqlite3.connect( file )

    # update missing fields
    try:
        connection = sqlite3.connect( file )
        c = connection.cursor()
        query = "ALTER TABLE EVENT ADD METADATA TEXT";
        c.execute( query )
        connection.commit()

    except:
        print( "METADATA field already exists" , file )

    BuildDataBaseIndex.buildDataBaseIndex( connection, force=False )

    # build sensor data
    animalPool = AnimalPool( )
    animalPool.loadAnimals( connection )
    #animalPool.buildSensorData(file)

    currentT = minT

    try:

        flushEvents( connection )

        while currentT < maxT:

            currentMinT = currentT
            currentMaxT = currentT+ windowT
            if ( currentMaxT > maxT ):
                currentMaxT = maxT

            chronoTimeWindowFile = Chronometer("File "+ file+ " currentMinT: "+ str(currentMinT)+ " currentMaxT: " + str(currentMaxT) );
            processTimeWindow( connection, file, currentMinT, currentMaxT )
            chronoTimeWindowFile.printTimeInS()

            currentT += windowT



        print("Full file process time: ")
        chronoFullFile.printTimeInS()


        TEST_WINDOWING_COMPUTATION = False

        if ( TEST_WINDOWING_COMPUTATION ):

            print("*************")
            print("************* TEST START SECTION")
            print("************* Test if results are the same with or without the windowing.")

            # display and record to a file all events found, checking with rolling idA from None to 4. Save nbEvent and total len

            eventTimeLineList = []

            eventList = getAllEvents( connection )
            file = open("outEvent"+str(windowT)+".txt","w")
            file.write( "Event name\nnb event\ntotal duration" )

            for eventName in eventList:
                for animal in range( 0,5 ):
                        idA = animal
                        if idA == 0:
                            idA = None
                        timeLine = EventTimeLineCached( connection, file, eventName, idA,  minFrame=minT, maxFrame=maxT )
                        eventTimeLineList.append( timeLine )
                        file.write( timeLine.eventNameWithId+"\t"+str(len(timeLine.eventList))+"\t"+str(timeLine.getTotalLength())+"\n" )

            file.close()

            #plotMultipleTimeLine( eventTimeLineList )

            print("************* END TEST")

        flushEventTimeLineCache()

    except:

        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        error = ''.join('!! ' + line for line in lines)

        t = TaskLogger( connection )
        t.addLog( error )
        flushEventTimeLineCache()

        print( error, file=sys.stderr )

        raise FileProcessException()
                txt += str( len( event[idAnimalA, idAnimalB].getEventList() ) ) + "\t"

            print( txt )


    print( "*** DONE ***")


if __name__ == '__main__':

    print("Code launched.")


    files = askopenfilename( title="Choose a set of file to process", multiple=1 )

    eventList = getAllEvents(file=files[0] )

    for i in range( 0 , len( eventList) ):
        print( "[" + str( i ) + "] :" + eventList[i] )

    while( True ):

        userInput = input ("Event to read (full name or number ) (enter to quit): ")

        if userInput=="":
            print("Exit :)")
            quit()

        if ( userInput.isdigit() ):
            eventName = eventList[ int( userInput )]
        else: