import time, sys import numpy as np import matplotlib.pyplot as plt import pylab as pl import math import os from convertFiles import parseFileNames, textToArray if __name__ == "__main__": # no parameters for this function # parse names of files phoneFile, arduinoFile, saveDirectory = parseFileNames() # convert data in files to arrays phoneTimes, arduinoTimes, phoneDupes = textToArray(phoneFile, arduinoFile) # ARDUINO RUN TIME # find difference between start and end time, convert form millis to days runTimeArduino = ((float(arduinoTimes[len(arduinoTimes) - 1]) - float(arduinoTimes[0]))/(1000*60*60*24)) # convert from millis epoch to seconds epoch, then to readable format runStartArduino = int(arduinoTimes[0])/1000 readableRunStartArduino = time.strftime('%Y-%m-%d %I:%M %p', time.localtime(runStartArduino)) runEndArduino = int(arduinoTimes[len(arduinoTimes)-1])/1000 readableRunEndArduino = time.strftime('%Y-%m-%d %I:%M %p', time.localtime(runEndArduino)) # PHONE RUN TIME
leftRange = -1000 rightRange = 1000 offsetIncrement = 20 # "smallest", "all", and integers are accepted tolerance = 150 normalization = True # uncomment if you want to produce lots of graphs #for i in xrange(100): if (tolerance == "all") or (tolerance == "smallest"): normalization = False startTime = time.time() # parse names of files phoneFile, arduinoFile, saveDirectory = parseFileNames() # convert data in files to arrays phoneTimes, arduinoTimes, phoneDupes = textToArray(phoneFile, arduinoFile) # find the chosen set of deltaTimes (based on parameters) and sum them up offsetValues, sums, numberOfPoints = findSyncWithSums(phoneTimes, arduinoTimes, leftRange, rightRange, offsetIncrement, tolerance, normalization) # print total time endTime = time.time() timeItTook = endTime - startTime print ("finished in", round((timeItTook/60),2), "minutes") # plot the sums over millisecond offset drawSums(offsetValues, sums, numberOfPoints, offsetIncrement, saveDirectory, tolerance, normalization)