def getSavedIbmValues(self, IBMDictionary, songWord): ibmWordBeginTime = IBMDictionary[songWord][1] ibmWordBeginTimestamp = Timestamp( self.formatSubtitle(ibmWordBeginTime)) ibmWordEndTime = IBMDictionary[songWord][2] ibmWordEndTimestamp = Timestamp(self.formatSubtitle(ibmWordEndTime)) return ibmWordBeginTimestamp, ibmWordEndTimestamp
def extractTimestamp(self, timestamp): # 00: 00:40, 125 --> 00: 00:44, 170 timestamp = timestamp.replace(" ", "") timestamp = timestamp.replace(",", ".") times = timestamp.split("-->") beginTime = times[0] endTime = times[1].rstrip() beginTS = Timestamp(beginTime) endTS = Timestamp(endTime) return beginTS, endTS
def saveListAsSnippet(self, timeStampedSubtitle, movieName, songWord, parentSnippet): """ save word as VideoSnippet, then save to a dictionary """ songWordVideoSnippet = None print("timestamped subtitle is ", timeStampedSubtitle) for aiWordList in timeStampedSubtitle: word = Cleanser.Cleanser.cleaning_word( aiWordList[0]) # get rid of apostrophes and other annoyances path = os.path.join(self.movieLocation, self.speaker, "wordAudio", word + str(self.wordid) + ".mp3") beginSec, beginMs = self.splitUnformatTime( aiWordList[1]) # format: ["several":, 1.0, 1.51] endSec, endMs = self.splitUnformatTime(aiWordList[2]) beginTS = "00:00:" + beginSec + "." + beginMs endTS = "00:00:" + endSec + "." + endMs beginTSObject = Timestamp(beginTS) endTSObject = Timestamp(endTS) videoSnippet = VideoSnippet(beginTSObject, endTSObject, word, path, movieName, parentSnippet.path, parentSnippet.beginTime, parentSnippet.endTime) """ save the file path of the video snippet containing word to reuse words in future songs """ aiWordList.append(parentSnippet.path) if songWord == word: songWordVideoSnippet = videoSnippet continue # dont add to IBM saved dictionary if word in self.IBM_Dictionary: wordIsDuplicate = videoSnippet.isIdentical( self.duplicateIBM_Dictionary[word] ) # if so, then we have already rejected this IBM word else: wordIsDuplicate = False if not wordIsDuplicate: if word in self.IBM_Dictionary: self.duplicateIBM_Dictionary[word].append( videoSnippet ) # will removing videosnippet from one list delete from other dictionary? self.IBM_Dictionary[word].append(videoSnippet) else: self.duplicateIBM_Dictionary[word] = [videoSnippet] self.IBM_Dictionary[word] = [videoSnippet] FileCourier.writeDictionaryListOfObjects( self.IBM_Filename, self.IBM_Dictionary) self.wordid += 1 else: print("DOOP ALERT!. Word %s is a duplicate" % word) # NOT WORKING!!! return songWordVideoSnippet
def __init__(self, agent_id, total_agents, domain, constraints, cost_functions): # Solution CPA and Bound self._CPA_SOLUTION = None self._B = sys.maxsize # Agent information self._id = agent_id self._constraints = constraints self._domain = domain self._cost_functions = cost_functions self._total_agents = total_agents # self._timestamp = [0] * (total_agents + 1) self._timestamp = Timestamp(self._total_agents + 1) # Instance variables self._received_cpa = None self._current_cpa = None self._next_assignment = 0 # index of value in domain self._current_assignment = 0 self._estimate_value = 0 # scalar value of this agents estimate self._queue = [] # A python list can be used a queue self._converged = False # Only for first Agent if self._id == 1: cpa = self._generate_cpa() # start events self._queue.append(Message('CPA_MSG', self._timestamp, 0, self._id, cpa))
def get_timer_interval_limit(session_id,begin,end): """ use page instead of select all data at once avoid data too large to crash """ global last_timestamp global last_sn query = (" SELECT log_tv_sec,log_tv_usec,log_content " " FROM `{0}` " " WHERE session_id = {1} AND log_type = get_log_type_id('timer_enter') " " LIMIT {2},{3}".format(table_name,session_id,begin,end) ) print("query {0},{1}".format(begin,end)) cursor.execute(query) rows = cursor.fetchall() for sec,usec,sn in rows: timestamp = Timestamp(int(sec),int(usec)) sn = int(sn,16) if sn - last_sn == 1: interval = timestamp - last_timestamp # if it's great than 100ms,tell me if interval > 100000: print(interval / 1000.0,end="") s = "{0},".format(interval / 1000.0) f.write(s) pass last_sn = sn last_timestamp = timestamp return
def readDictionaryObjects(file): " get VideoSnippets from serialized pruned movie dictionary " if len(file) == 0: return {} snippetDictionary = eval(file) for key in snippetDictionary: serializedMovieEntry = snippetDictionary[key] # get list of arguments to VideoSnippet beginTime = Timestamp(serializedMovieEntry[0]) endTime = Timestamp(serializedMovieEntry[1]) word = serializedMovieEntry[2] path = serializedMovieEntry[3] movieName = serializedMovieEntry[4] parentFilePath = serializedMovieEntry[5] parentBeginTime = Timestamp(serializedMovieEntry[6]) parentEndTime = Timestamp(serializedMovieEntry[7]) snippetDictionary[key] = VideoSnippet(beginTime, endTime, word, path, movieName, parentFilePath, parentBeginTime, parentEndTime) return snippetDictionary
def set_header(self, payment_status_bulk_payload, credentials): hash_string = credentials.api_key + payment_status_bulk_payload.request_id + credentials.api_token txn_hash = EncryptionConfig.sha512(hash_string) time_stamp = Timestamp() headers = {'Content-Type': 'application/json', 'MERCHANT_ID':credentials.merchant_id, 'API_KEY':credentials.api_key, 'REQUEST_ID':payment_status_bulk_payload.request_id, 'REQUEST_TS':time_stamp.dateTimeObj(dateTimeObj=datetime.now()), 'API_DETAILS_HASH': txn_hash} return headers
def addSilence(self, silenceDuration, lyricItr): """ calculate duration of the pause between lyrics and trim the right amount of silence""" silenceTS = Timestamp() silenceEnd = silenceTS.convertTotalMsToString(silenceDuration) silenceVideoName = os.path.join(self.movieLocation, "silence", "silence" + str(lyricItr) + ".mp4") silenceVidInput = self.speaker.lower() + "swag" + ".mp4" os.system( "/usr/local/opt/ffmpeg/bin/ffmpeg -i /Users/edwardcox/Desktop/TomCruiseSing/silence/" + silenceVidInput + "\ -ss 00:00:00.0" + " -to " + silenceEnd + " -y " + silenceVideoName) # removed -c copy to re-encode return silenceVideoName
def getWordFromSRT(self, subtitle_path, dirName, isSong=False): """ map words to Snippets (contain timestamps of sentences the word is contained in) """ # read file line by line arrowCounter = 0 # number of snippets subtitle_file = open(subtitle_path, "r", errors='ignore') lines = subtitle_file.readlines() song_snippet_word_array = [ ] # store the words for multiple lines belonging to 1 subtitle subtitle_file.close() prevEndTimestamp = prevprevEndTimestamp = prevBeginTimestamp = None # combine lyrics with the previous timestamp (not the next one) for l in range( len(lines)): # iterate through the lines of the SRT file line = lines[l] line = Cleanser.Cleanser.cleanhtml(line) # remove html tags if "-->" in line or l == len( lines) - 1: # if last lines add last snippet to list if arrowCounter == 1: prevBeginTimestamp = Timestamp("00:00:00.0") arrowCounter += 1 if l == len(lines) - 1: song_snippet_word_array += line.rstrip().split() self.saveSubtitleWords(song_snippet_word_array, dirName, prevBeginTimestamp, prevEndTimestamp, isSong) if isSong: if prevEndTimestamp is not None: # len(song_snippet_word_array) > 0: # Cleanser.Cleanser.hasLetters(song_snippet_word_array) clean_word_array = Cleanser.Cleanser.clean_sentence( song_snippet_word_array) # song SRT subtitle length to be used in VideoAssembler for stretching/shrinking clips if prevprevEndTimestamp is not None: self.songSnippetList.append( SongSnippet(prevprevEndTimestamp, prevEndTimestamp, clean_word_array) ) # include the pause between lyrics in a snippet else: self.songSnippetList.append( SongSnippet(prevBeginTimestamp, prevEndTimestamp, clean_word_array)) prevprevEndTimestamp = prevEndTimestamp song_snippet_word_array = [] if l != len(lines) - 1: prevBeginTimestamp, prevEndTimestamp = self.extractTimestamp( line) continue word_array = line.rstrip().split() # remove \n at end of sentence song_snippet_word_array += word_array self.saveSubtitleWords(word_array, dirName, prevBeginTimestamp, prevEndTimestamp, isSong)
def assembleVideoClips(self, humanApprovedDictionary, songSnippetList): """ IBMDictionary contains movieEntry. key is word, value is a Snippet songDictionary contains Snippet. key is word, value is object with start, end times """ id = 0 lyricItr = 0 prevLyricTimestamp = Timestamp("00:00:00.0") sentenceFileList = [] totalsilence = 0 # silence between lyrics snippetidx = 0 combinedClips = 0 self.trimAllSongWord( humanApprovedDictionary) # cut all the word videos for songSnippet in songSnippetList: if totalsilence == 0: longSilenceStartTime = prevLyricTimestamp snippetidx += 1 songLine = songSnippet.subtitle lyricEndTime = songSnippet.endTime wordList = [] """ the length of silence is measured as the gap between the last subtitle end time and the current start time """ prevLyricTimestamp = lyricEndTime lyricItr += 1 # track the first word found in IBMDictionary for silence timestamp duration calculation if len(songLine) > 0: # takes care of empty song lines """ trim all song words belonging to a song line""" wordList = self.getSongWordLocations(wordList, songLine) if len( wordList ) > 0: # words added to wordList. If couldn't find any words in line, replace with silence clip combinedClips += 1 sentenceFilePath = self.combineVideoClipsIntoSentence( wordList, songSnippet, totalsilence, longSilenceStartTime, songSnippet.beginTime, lyricItr, id) sentenceFileList.append(sentenceFilePath) totalsilence = 0 else: # songline contains words, but we couldn't find any from our speaker totalsilence += songSnippet.endTime.totalms - songSnippet.beginTime.totalms id += 1 else: # songline doesnt contain words totalsilence += songSnippet.endTime.totalms - songSnippet.beginTime.totalms # Delete combineClip.mp4 afterward parodyPath = os.path.join("finalVideo", self.speaker + "_" + self.songTitle + ".mp4") self.combineVideoClips(sentenceFileList, parodyPath)
def ReadTimestamps(): mTimestamp = Timestamp() UsersTimestamps = mFirebaseData.child(Constants.Timestamps).get() print("Deleting relevant timestamps..") if (UsersTimestamps is not None): if (UsersTimestamps.each() is not None): for timestamp in UsersTimestamps.each(): userId = timestamp.key() mTimestamp.setUserId(userId) print(userId) details = mFirebaseData.child( Constants.Timestamps).child(userId).get() details = timestamp.val() details = dict(details) mTimestamp.setTimestamp( details.get(Constants.Timestamp_Timestamp)) mTimestamp.setBeachName( details.get(Constants.Timestamp_BeachName)) mTimestamp.setBeachId(details.get(Constants.Timestamp_BeachID)) mTimestamp.setBeachListenerId( details.get(Constants.Timestamp_BeachListenerId)) mTimestamp.setBeachCountry( details.get(Constants.Timestamp_Country)) mTimestamp.print() date = datetime.datetime.utcfromtimestamp( int(mTimestamp.Timestamp)) dayOfMonth = date.day month = date.month currentDayOfMonth = datetime.datetime.utcnow().day currentMonth = datetime.datetime.utcnow().month print("received date: month: " + str(month) + " day " + str(dayOfMonth)) print("current date: month: " + str(currentMonth) + " day " + str(currentDayOfMonth)) checkInHour = datetime.datetime.utcfromtimestamp( int(mTimestamp.Timestamp)).hour checkInMinutes = int( datetime.datetime.fromtimestamp(int( mTimestamp.Timestamp)).minute) print("check in minutes: " + str(checkInMinutes)) print("check in hour: " + str(checkInHour)) currentHour = datetime.datetime.utcnow().hour currentMinute = datetime.datetime.utcnow().minute print("current hour : " + str(currentHour)) print("current minute: " + str(currentMinute)) if ((checkInHour + Constants.Timestamp_Max_Hour) < currentHour or (currentMonth > month) or (currentDayOfMonth > dayOfMonth)): print("deleting timestamp...") mFirebaseData.child(Constants.Timestamps).child( mTimestamp.UserID).remove() mFirebaseData.child(Constants.Beaches).child( mTimestamp.BeachID).child(Constants.Peoplelist).child( mTimestamp.UserID).remove() mFirebaseData.child(Constants.Users).child( mTimestamp.UserID).child( Constants.CurrentBeach).remove() CurrentDevices = mFirebaseData.child( Constants.BeachesListener).child( mTimestamp.BeachListenerID).child( Constants.CurrentDevices).get() CurrentDevices = int(CurrentDevices.val()) CurrentDevices = CurrentDevices - 1 mFirebaseData.child(Constants.BeachesListener).child( mTimestamp.BeachListenerID).child( Constants.CurrentDevices).set(CurrentDevices) else: print("Not deleteing from timestamps")
lastFilter = window.filterActive.get() elem = searchNextPatient(window, window.filterActive.get()) break if window.previous.get(): changed = True lastFilter = window.filterActive.get() elem = searchPreviousPatient(window, window.filterActive.get()) break lastNotification = window.notificationActive.get() lastContinue = window.continueActive.get() sensorTime = dataset.iloc[window.currentIndex]["Timestamp"] actualTime = Timestamp(sensorTime) if window.currentIndex != 0 or window.currentIndex != dim_ciclo: sensorTimePrecedente = dataset.iloc[window.currentIndex - 1]["Timestamp"] sensorTimePrev = Timestamp(sensorTimePrecedente) timeDiff = sensorTimePrev.secondsConverter( ) - actualTime.secondsConverter() if timeDiff > 5000: timeDiff = 1000 window.root.after( int(800 * window.velocity),
def timestamp(**kwds): from Timestamp import Timestamp return Timestamp(**kwds)
from Timestamp import Timestamp, generateTimestamps t1 = Timestamp().createBasedOnKey("2015101523") print("t1: " + str(t1)) t2 = Timestamp().createBasedOnKey("2013010101") print("t2: " + str(t2)) t3 = Timestamp().createBasedOnKey("2013010101") print("t3: " + str(t3)) print("t2 == t3: " + str(t2 == t3)) print("t1 == t3: " + str(t1 == t3)) timestamps = generateTimestamps(2013) print(str(len(timestamps)))
#!/usr/bin/python import sys ## change this path to where Timestamp.py load_path = 'C:\\users\\vladimir\\programming\\nasa_wlog\\py_nasa_log\\' if __name__ == '__main__': if not load_path in sys.path: sys.path.append(load_path) from Timestamp import Timestamp txt = '01/Jul/1995:00:00:01 -0400' tm1 = Timestamp() if tm1.toTimestamp(txt): print 'month: ' + tm1.getMonth() + "\n", print 'day: ' + tm1.getDay() + "\n", print 'year: ' + tm1.getYear() + "\n", print 'hour: ' + tm1.getHour() + "\n", print 'mins: ' + tm1.getMins() + "\n", print 'secs: ' + tm1.getSecs() + "\n", print 'string representation: ' + tm1.toString() else: print 'no timestamp created' + "\n",
# /usr/bin/python3 from DbConnect import cursor import time from Timestamp import Timestamp log_file_name = "TimerInterval.txt" f = open(log_file_name,"w+") table_name = "log20140929" last_timestamp = Timestamp() last_sn = -1 def get_count(session_id): query = (" SELECT count(*) " " FROM `{0}` " " WHERE session_id = {1} AND log_type = get_log_type_id('timer_enter') " .format(table_name,session_id) ) print("query data count(it will take a long time)...") cursor.execute(query) count = cursor.fetchone() print("count:",count) return int(count[0]) def get_timer_interval_limit(session_id,begin,end): """ use page instead of select all data at once avoid data too large to crash """
#!/usr/bin/python import sys ## change this path to where Timestamp.py load_path = 'C:\\users\\vladimir\\programming\\nasa_wlog\\py_nasa_log\\' if __name__ == '__main__': if not load_path in sys.path: sys.path.append(load_path) from Timestamp import Timestamp txt = '01/Jul/1995:00:00:01 -0400' tm2 = Timestamp() if tm2 != None: tm2.setDay('01') tm2.setMonth('Jul') tm2.setYear('1995') tm2.setHour('00') tm2.setMins('00') tm2.setSecs('01') print 'string representation: ' + tm2.toString() else: print 'no timestamp created' + "\n",
True, "\t") print("Done...") print("Generate timestamps...") timestamps = generateTimestampsForDays(2013, 1, 1, 1) print("Done...") generateDataGridHourData( WORK_DIRECTORY, DATA_DIRECTORY + "weather/wu/", timestamps, OUTPUT_DIRECTORY + "york_hour_grid_2013.csv") for month in range(1, 13): for day in range(1, DAYS_OF_MONTH[month - 1] + 1): dayTimestamp = Timestamp().createBasedOnOther(2013, month, day, 1) dayTimestampKey = dayTimestamp.key[0:8] timestamps = generateTimestampsForDays(2013, month, day, day) generateDataGridHourData( WORK_DIRECTORY, DATA_DIRECTORY + "weather/wu/", timestamps, OUTPUT_DIRECTORY + "data_" + dayTimestampKey + ".csv")
tomorrow = (datetime.now() + timedelta(days=1)) tomorrowString = tomorrow.strftime('%Y%m%d') tomorrowYear = int(tomorrow.strftime('%Y')) tomorrowMonth = int(tomorrow.strftime('%m')) tomorrowDay = int(tomorrow.strftime('%d')) print("\tToday's day stamp: " + todayString) print("\tTomorrow's day stamp: " + tomorrowString) print("\tCurrent year, month, day, hour: " + str(currentYear) + "," + str(currentMonth) + "," + str(currentDay) + "," + str(currentHour)) print("\tTomorrow year, month, day: " + str(tomorrowYear) + "," + str(tomorrowMonth) + "," + str(tomorrowDay)) timestamps = [] historyTimestamps = [] forecastTimestamps = [] for hour in range(0, currentHour + 1): timestamp = Timestamp().createBasedOnOther(currentYear, currentMonth, currentDay, hour) historyTimestamps.append(timestamp) for hour in range(0, 24): timestamp = Timestamp().createBasedOnOther(currentYear, currentMonth, currentDay, hour) timestamps.append(timestamp) if timestamp not in historyTimestamps: forecastTimestamps.append(timestamp) for hour in range(0, 24): timestamp = Timestamp().createBasedOnOther(tomorrowYear, tomorrowMonth, tomorrowDay, hour) timestamps.append(timestamp) forecastTimestamps.append(timestamp) # print("History " + str(len(historyTimestamps))) # for t in historyTimestamps: