Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/storage.py @ 1141:3e0f43edb4d6
Issue loading from different location
| author | Etienne Beauchamp <etienne-2.beauchamp@polymtl.ca> |
|---|---|
| date | Thu, 16 Apr 2020 11:24:35 -0400 |
| parents | c4d9c270f999 |
| children | 8ac52ebff5f7 |
comparison
equal
deleted
inserted
replaced
| 1140:78dddfe7aa0f | 1141:3e0f43edb4d6 |
|---|---|
| 4 | 4 |
| 5 from pathlib import Path | 5 from pathlib import Path |
| 6 import shutil | 6 import shutil |
| 7 from copy import copy | 7 from copy import copy |
| 8 import sqlite3, logging | 8 import sqlite3, logging |
| 9 from os import chdir | |
| 9 | 10 |
| 10 from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt, floor as npfloor, ceil as npceil, linalg, int32, int64 | 11 from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt, floor as npfloor, ceil as npceil, linalg, int32, int64 |
| 11 from pandas import read_csv, merge | 12 from pandas import read_csv, merge |
| 12 | 13 |
| 13 from trafficintelligence import utils, moving, events, indicators | 14 from trafficintelligence import utils, moving, events, indicators |
| 659 | 660 |
| 660 def loadPrototypesFromSqlite(filename, withTrajectories = True): | 661 def loadPrototypesFromSqlite(filename, withTrajectories = True): |
| 661 'Loads prototype ids and matchings (if stored)' | 662 'Loads prototype ids and matchings (if stored)' |
| 662 prototypes = [] | 663 prototypes = [] |
| 663 if Path(filename).is_file(): | 664 if Path(filename).is_file(): |
| 665 filename = str(Path(filename).resolve()) | |
| 666 pwd = Path.cwd() | |
| 667 chdir(Path(filename).parent) | |
| 664 with sqlite3.connect(filename) as connection: | 668 with sqlite3.connect(filename) as connection: |
| 665 cursor = connection.cursor() | 669 cursor = connection.cursor() |
| 666 objects = [] | 670 objects = [] |
| 667 try: | 671 try: |
| 668 cursor.execute('SELECT * FROM prototypes') | 672 cursor.execute('SELECT * FROM prototypes') |
| 683 # objects += loadTrajectoriesFromSqlite(k[0], k[1], [p.getNum() for p in v]) | 687 # objects += loadTrajectoriesFromSqlite(k[0], k[1], [p.getNum() for p in v]) |
| 684 except sqlite3.OperationalError as error: | 688 except sqlite3.OperationalError as error: |
| 685 printDBError(error) | 689 printDBError(error) |
| 686 if len(set([p.getTrajectoryType() for p in prototypes])) > 1: | 690 if len(set([p.getTrajectoryType() for p in prototypes])) > 1: |
| 687 print('Different types of prototypes in database ({}).'.format(set([p.getTrajectoryType() for p in prototypes]))) | 691 print('Different types of prototypes in database ({}).'.format(set([p.getTrajectoryType() for p in prototypes]))) |
| 692 chdir(pwd) | |
| 688 return prototypes | 693 return prototypes |
| 689 | 694 |
| 690 def savePOIsToSqlite(filename, gmm, gmmType, gmmId): | 695 def savePOIsToSqlite(filename, gmm, gmmType, gmmId): |
| 691 '''Saves a Gaussian mixture model (of class sklearn.mixture.GaussianMixture) | 696 '''Saves a Gaussian mixture model (of class sklearn.mixture.GaussianMixture) |
| 692 gmmType is a type of GaussianMixture, learnt either from beginnings or ends of trajectories''' | 697 gmmType is a type of GaussianMixture, learnt either from beginnings or ends of trajectories''' |
