tvaLib
Classes | Functions | Variables
lib.metadata Namespace Reference

Classes

class  Analysis
 
class  CameraView
 
class  CamType
 Basic TI objects. More...
 
class  Cluster
 
class  HLIOriginDestination
 
class  HLIRoundaboutQuadrant
 HLI extensions. More...
 
class  HLIStopSign
 
class  Site
 
class  SiteAnalysis
 
class  VideoSequence
 

Functions

def connectToDatabase (dbPath)
 Tools. More...
 
def upgradeDatabase (dbPath, tableName, columnNames, columnTypes)
 
def createDatabase (filename=':memory:')
 Basic TI DB handlers. More...
 
def connectDatabase (filename=':memory:')
 
def initializeSites (session, directoryName)
 

Variables

 Base = declarative_base()
 
def session = createDatabase()
 Example. More...
 
def camTypes = session.query(CamType).all()
 Add camera types. More...
 
def sites = session.query(Site).all()
 Add sites. More...
 
def cameras = session.query(CameraView).all()
 Add Cameras. More...
 
def sequences = session.query(VideoSequence).all()
 Add Sequences. More...
 
def site_analyses = session.query(SiteAnalysis).all()
 Add analysis sites. More...
 
def analyses = session.query(Analysis).all()
 

Function Documentation

◆ connectDatabase()

def lib.metadata.connectDatabase (   filename = ':memory:')
Creates a session to query the filename. 

Definition at line 296 of file metadata.py.

296 def connectDatabase(filename=':memory:'): ''' Creates a session to query the filename. '''
297  engine = create_engine('sqlite:///'+filename)
298  Session = sessionmaker(bind=engine)
299  return Session()
300 
301 
def connectDatabase(filename=':memory:')
Definition: metadata.py:296

◆ connectToDatabase()

def lib.metadata.connectToDatabase (   dbPath)

Tools.

Definition at line 24 of file metadata.py.

24 def connectToDatabase(dbPath):
25  import sqlite3
26  conn = sqlite3.connect(dbPath)
27  return conn.cursor()
28 
def connectToDatabase(dbPath)
Tools.
Definition: metadata.py:24

◆ createDatabase()

def lib.metadata.createDatabase (   filename = ':memory:')

Basic TI DB handlers.

Creates a session to query the filename. 

Definition at line 289 of file metadata.py.

289 def createDatabase(filename=':memory:'):
290  ''' Creates a session to query the filename. '''
291  engine = create_engine('sqlite:///'+filename)
292  Base.metadata.create_all(engine)
293  Session = sessionmaker(bind=engine)
294  return Session()
295 
def createDatabase(filename=':memory:')
Basic TI DB handlers.
Definition: metadata.py:289

◆ initializeSites()

def lib.metadata.initializeSites (   session,
  directoryName 
)
Initializes default site objects and Camera Views

eg somedirectory/montreal/ contains intersection1, intersection2, etc.
The site names would be somedirectory/montreal/intersection1, somedirectory/montreal/intersection2, etc.

Definition at line 302 of file metadata.py.

302 def initializeSites(session, directoryName):
303  '''Initializes default site objects and Camera Views
304 
305  eg somedirectory/montreal/ contains intersection1, intersection2, etc.
306  The site names would be somedirectory/montreal/intersection1, somedirectory/montreal/intersection2, etc.'''
307  from os import listdir, path
308  sites = []
309  cameraViews = []
310  names = listdir(directoryName)
311  for name in names:
312  if path.isdir(directoryName+'/'+name):
313  sites.append(Site(directoryName+'/'+name, None))
314  cameraViews.append(CameraView(-1, None, None, sites[-1], None))
315  session.add_all(sites)
316  session.add_all(cameraViews)
317  session.commit()
318 
def initializeSites(session, directoryName)
Definition: metadata.py:302

◆ upgradeDatabase()

def lib.metadata.upgradeDatabase (   dbPath,
  tableName,
  columnNames,
  columnTypes 
)
Upgrade an existing database using these parameters (if the column
    doesn't already exist). AKA database migration, not supported natively
    by SQLAlchemy. This function is not necessary if the upgrade requires a
    new table (supported natively by SQLAlchemy).
    
    Input:
    ======
    dbPath:      path to database
    tableName:   name of table in database to alter
    columnNames: a list of column names, e.g. ['Column1','Column2']
    columnTypes: a list of column types, e.g. ['INTEGER','STRING']

Definition at line 29 of file metadata.py.

29 def upgradeDatabase(dbPath, tableName, columnNames, columnTypes):
30  ''' Upgrade an existing database using these parameters (if the column
31  doesn't already exist). AKA database migration, not supported natively
32  by SQLAlchemy. This function is not necessary if the upgrade requires a
33  new table (supported natively by SQLAlchemy).
34 
35  Input:
36  ======
37  dbPath: path to database
38  tableName: name of table in database to alter
39  columnNames: a list of column names, e.g. ['Column1','Column2']
40  columnTypes: a list of column types, e.g. ['INTEGER','STRING']
41  '''
42 
43  c = connectToDatabase(dbPath)
44  for column_name,column_type in zip(columnNames,columnTypes):
45  try: c.execute('ALTER TABLE '+tableName+' ADD COLUMN '+column_name+' '+column_type)
46  except: pass
47  c.close()
48 
def upgradeDatabase(dbPath, tableName, columnNames, columnTypes)
Definition: metadata.py:29
def connectToDatabase(dbPath)
Tools.
Definition: metadata.py:24

Variable Documentation

◆ analyses

def lib.metadata.analyses = session.query(Analysis).all()

Definition at line 435 of file metadata.py.

◆ Base

lib.metadata.Base = declarative_base()

Definition at line 18 of file metadata.py.

◆ cameras

def lib.metadata.cameras = session.query(CameraView).all()

Add Cameras.

Definition at line 413 of file metadata.py.

◆ camTypes

def lib.metadata.camTypes = session.query(CamType).all()

Add camera types.

Definition at line 395 of file metadata.py.

◆ sequences

def lib.metadata.sequences = session.query(VideoSequence).all()

Add Sequences.

Definition at line 419 of file metadata.py.

◆ session

def lib.metadata.session = createDatabase()

Example.

SQLAlchemy Engine

Definition at line 390 of file metadata.py.

◆ site_analyses

def lib.metadata.site_analyses = session.query(SiteAnalysis).all()

Add analysis sites.

Definition at line 430 of file metadata.py.

◆ sites

def lib.metadata.sites = session.query(Site).all()

Add sites.

Definition at line 407 of file metadata.py.