Mercurial Hosting > traffic-intelligence
comparison python/utils.py @ 395:6fba1ab040f1
minor modification to framestotime
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 26 Jul 2013 17:52:23 -0400 |
parents | 03dbecd3a887 |
children | b36b00dd27c3 |
comparison
equal
deleted
inserted
replaced
394:6567fee37c16 | 395:6fba1ab040f1 |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 ''' Generic utilities.''' | 2 ''' Generic utilities.''' |
3 | 3 |
4 #from numpy import * | 4 #from numpy import * |
5 #from pylab import * | 5 #from pylab import * |
6 from datetime import time | |
6 | 7 |
7 __metaclass__ = type | 8 __metaclass__ = type |
8 | 9 |
9 commentChar = '#' | 10 commentChar = '#' |
10 | 11 |
142 ######################### | 143 ######################### |
143 | 144 |
144 def argMaxDict(d): | 145 def argMaxDict(d): |
145 return max(d.iterkeys(), key=(lambda key: d[key])) | 146 return max(d.iterkeys(), key=(lambda key: d[key])) |
146 | 147 |
147 def framesToTime(nFrames, frameRate, initialTime = (0.,0.,0.)): | 148 def framesToTime(nFrames, frameRate, initialTime = time()): |
148 'returns hour, minutes and seconds' | 149 '''returns a datetime.time for the time in hour, minutes and seconds |
150 initialTime is a datetime.time''' | |
149 from math import floor | 151 from math import floor |
150 from datetime import time | 152 from datetime import time |
151 seconds = int(floor(float(nFrames)/float(frameRate))+initialTime[0]*3600+initialTime[1]*60+initialTime[2]) | 153 seconds = int(floor(float(nFrames)/float(frameRate))+initialTime.hour*3600+initialTime.minute*60+initialTime.second) |
152 h = int(floor(seconds/3600.)) | 154 h = int(floor(seconds/3600.)) |
153 seconds = seconds - h*3600 | 155 seconds = seconds - h*3600 |
154 m = int(floor(seconds/60)) | 156 m = int(floor(seconds/60)) |
155 seconds = seconds - m*60 | 157 seconds = seconds - m*60 |
156 return time(h, m, seconds) | 158 return time(h, m, seconds) |