Mercurial Hosting > traffic-intelligence
diff python/metadata.py @ 828:14e4ad7c7420
work on merging data for synchronized views
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 28 Jun 2016 17:18:45 -0400 |
parents | 6e4357e9116d |
children | 2a5856961933 |
line wrap: on
line diff
--- a/python/metadata.py Tue Jun 28 15:55:56 2016 -0400 +++ b/python/metadata.py Tue Jun 28 17:18:45 2016 -0400 @@ -4,11 +4,14 @@ from os import path from math import floor +from numpy import zeros + from sqlalchemy import orm, create_engine, Column, Integer, Float, DateTime, String, ForeignKey, Boolean, Interval from sqlalchemy.orm import relationship, backref, sessionmaker from sqlalchemy.ext.declarative import declarative_base from utils import datetimeFormat, removeExtension +from moving import TimeInterval Base = declarative_base() @@ -35,6 +38,15 @@ def getFilename(self): return self.name + @staticmethod + def getSite(session, siteId): + 'Returns the site(s) matching the index or the name' + if str.isdigit(siteId): + return session.query(Site).filter(Site.idx == int(siteId)).all() + else: + return session.query(Site).filter(Site.description.like('%'+siteId+'%')).all() + + class EnvironementalFactors(Base): '''Represents any environmental factors that may affect the results, in particular * changing weather conditions @@ -120,7 +132,6 @@ @orm.reconstructor def initOnLoad(self): - from numpy import zeros if self.intrinsicCameraMatrix00 is not None: self.intrinsicCameraMatrix = zeros((3,3)) self.intrinsicCameraMatrix[0,0] = self.intrinsicCameraMatrix00 @@ -231,7 +242,10 @@ '''startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39 duration is a timedelta object''' self.name = name - self.startTime = datetime.strptime(startTime, datetimeFormat) + if isinstance(startTime, str): + self.startTime = datetime.strptime(startTime, datetimeFormat) + else: + self.startTime = startTime self.duration = duration self.site = site self.cameraView = cameraView @@ -244,9 +258,16 @@ else: return self.name + def getTimeInterval(self): + return TimeInterval(self.startTime, self.startTime+self.duration) + def containsInstant(self, instant): 'instant is a datetime' return self.startTime <= instant and self.startTime+self.duration + + def intersection(self, startTime, endTime): + 'returns the moving.TimeInterval intersection with [startTime, endTime]' + return TimeInterval.intersection(self.getTimeInterval(), TimeInterval(startTime, endTime)) def getFrameNum(self, instant): 'Warning, there is no check of correct time units'