comparison trafficintelligence/storage.py @ 1033:8ffb3ae9f3d2

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 20 Jun 2018 00:07:03 -0400
parents aafbc0bab925
children 933588568bec
comparison
equal deleted inserted replaced
1032:d0e339359d8a 1033:8ffb3ae9f3d2
561 ######################### 561 #########################
562 # saving and loading for scene interpretation: POIs and Prototypes 562 # saving and loading for scene interpretation: POIs and Prototypes
563 ######################### 563 #########################
564 564
565 def savePrototypesToSqlite(filename, prototypes): 565 def savePrototypesToSqlite(filename, prototypes):
566 '''save the prototypes (a prototype is defined by a filename, a number (id) and type''' 566 '''save the prototypes (a prototype is defined by a filename, a number (id) and type)'''
567 with sqlite3.connect(filename) as connection: 567 with sqlite3.connect(filename) as connection:
568 cursor = connection.cursor() 568 cursor = connection.cursor()
569 try: 569 try:
570 cursor.execute('CREATE TABLE IF NOT EXISTS prototypes (prototype_filename VARCHAR, prototype_id INTEGER, trajectory_type VARCHAR CHECK (trajectory_type IN (\"feature\", \"object\")), nmatchings INTEGER, PRIMARY KEY (prototype_filename, prototype_id, trajectory_type))') 570 cursor.execute('CREATE TABLE IF NOT EXISTS prototypes (prototype_filename VARCHAR, prototype_id INTEGER, trajectory_type VARCHAR CHECK (trajectory_type IN (\"feature\", \"object\")), nmatchings INTEGER, PRIMARY KEY (prototype_filename, prototype_id, trajectory_type))')
571 for p in prototypes: 571 for p in prototypes:
572 cursor.execute('INSERT INTO prototypes VALUES(?,?,?,?)', (p.getFilename(), p.getNum(), p.getTrajectoryType(), p.getNMatchings())) 572 cursor.execute('INSERT INTO prototypes VALUES(?,?,?,?)', (p.getFilename(), p.getNum(), p.getTrajectoryType(), p.getNMatchings()))
573 except sqlite3.OperationalError as error:
574 printDBError(error)
575 connection.commit()
576
577 def setPrototypeMatchingsInSqlite(filename, prototypes):
578 '''updates the prototype matchings'''
579 with sqlite3.connect(filename) as connection:
580 cursor = connection.cursor()
581 try:
582 for p in prototypes:
583 if p.getNMatchings() is None:
584 nMatchings = 'NULL'
585 else:
586 nMatchings = p.getNMatchings()
587 cursor.execute('UPDATE prototypes SET nmatchings = {} WHERE prototype_filename = \"{}\" AND prototype_id = {} AND trajectory_type = \"{}\"'.format(nMatchings, p.getFilename(), p.getNum(), p.getTrajectoryType()))
573 except sqlite3.OperationalError as error: 588 except sqlite3.OperationalError as error:
574 printDBError(error) 589 printDBError(error)
575 connection.commit() 590 connection.commit()
576 591
577 def savePrototypeAssignmentsToSqlite(filename, objects, objectType, labels, prototypes): 592 def savePrototypeAssignmentsToSqlite(filename, objects, objectType, labels, prototypes):