# Initialize connection ser = initConnection(arduino_port) else: counter -= 1 # Run data recording time_start, times_array, data_array = recordData(ser) # Put files that are to be written into a file in queue so the saving thread can pick them up q.put((time_start, times_array, data_array, night_folder)) # Close conection if this is the last recording run if counter == 0: closeConnection(ser) # Wait a bit before analyzing time.sleep(5) print 'Running the night statistics...' # Run the night statistics analysis analyze(night_folder) print 'Statistics done!' # Wait a bit before recalculating the new start time time.sleep(5*60)
counter = int(duration / data_block_time) + 1 # Initialize connection ser = initConnection(arduino_port) else: counter -= 1 # Run data recording time_start, times_array, data_array = recordData(ser) # Put files that are to be written into a file in queue so the saving thread can pick them up q.put((time_start, times_array, data_array, night_folder)) # Close conection if this is the last recording run if counter == 0: closeConnection(ser) # Wait a bit before analyzing time.sleep(5) print 'Running the night statistics...' # Run the night statistics analysis analyze(night_folder) print 'Statistics done!' # Wait a bit before recalculating the new start time time.sleep(5 * 60)
counter = 0 while True: if counter <= 0: start_time = work_day_duration(44.869509, 13.853925, 23)[0] if start_time == True: rising = work_day_duration(44.869509, 13.853925, 23)[2] counter = ( (rising - datetime.datetime.now()).total_seconds()) / data_block_time else: if analyze: print "Analyzing..." logging.info("Analyzing...") nightAnalyzer.analyze() analyze = False sleep_done = False while not sleep_done: sleep_time = int( (start_time - datetime.datetime.now()).total_seconds()) + 60 if sleep_time < 3600: sleep_done = True print 'Waiting ' + str( int((start_time - datetime.datetime.now() ).total_seconds())) + ' seconds.' logging.info('Waiting ' + str( int((start_time - datetime.datetime.now()).total_seconds())) + ' seconds.')
# used to determin whether the analizing script should be called analyze = False counter = 0 while True: if counter == 0: start_time = work_day_duration(44.869509, 13.853925, 23)[0] if start_time == True: rising = ephem.localtime(ephem.Observer().next_rising(ephem.Sun())) counter = ((rising - datetime.datetime.utcnow()).total_seconds()) / 10.24 else: if analyze: print "Analyzing..." logging.info("Analyzing...") nightAnalyzer.analyze() analyze = False print 'Waiting ' + str(int((start_time - datetime.datetime.now()).total_seconds())) + ' seconds.' logging.info('Waiting ' + str(int((start_time - datetime.datetime.now()).total_seconds())) + ' seconds.') time.sleep(int((start_time - datetime.datetime.now()).total_seconds())) else: counter -= 1 analyze = True # Run data recording time_start, times_array, data_array = recordData(ser) # Put files that are to be written into a file in queue so the saving thread can pick them up #writeData(str(time_start) + '.csv', times_array, data_array) q.put((time_start, times_array, data_array))