Mercurial Hosting > traffic-intelligence
comparison python/storage.py @ 752:14963a9c3b09 dev
debug finished
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 28 Oct 2015 23:37:25 -0400 |
parents | 79405a938407 |
children | 3d48e34db846 |
comparison
equal
deleted
inserted
replaced
751:79405a938407 | 752:14963a9c3b09 |
---|---|
755 so that all times correspond to the number of the simulation step (and can be stored as integers) | 755 so that all times correspond to the number of the simulation step (and can be stored as integers) |
756 | 756 |
757 Objects positions will be considered only after warmUpLastInstant | 757 Objects positions will be considered only after warmUpLastInstant |
758 (if the object has no such position, it won't be loaded) | 758 (if the object has no such position, it won't be loaded) |
759 | 759 |
760 Assumed to be sorted over time''' | 760 Assumed to be sorted over time |
761 Warning: if reading from SQLite a limited number of objects, objectNumbers will be the maximum object id''' | |
761 objects = {} # dictionary of objects index by their id | 762 objects = {} # dictionary of objects index by their id |
762 | 763 |
763 if usePandas: | 764 if usePandas: |
764 from pandas import read_csv | 765 from pandas import read_csv |
765 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, low_memory = lowMemory) | 766 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, low_memory = lowMemory) |
774 tmp = data[data['NO'] == objNum] | 775 tmp = data[data['NO'] == objNum] |
775 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last'])) | 776 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last'])) |
776 # positions should be rounded to nDecimals decimals only | 777 # positions should be rounded to nDecimals decimals only |
777 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = npround(tmp['POS'].tolist(), nDecimals), Y = npround(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist()) | 778 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = npround(tmp['POS'].tolist(), nDecimals), Y = npround(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist()) |
778 if objectNumbers is not None and objectNumbers > 0 and len(objects) >= objectNumbers: | 779 if objectNumbers is not None and objectNumbers > 0 and len(objects) >= objectNumbers: |
779 break | 780 objects.values() |
780 else: | 781 else: |
781 if filename.endswith(".fzp"): | 782 if filename.endswith(".fzp"): |
782 inputfile = openCheck(filename, quitting = True) | 783 inputfile = openCheck(filename, quitting = True) |
783 line = readline(inputfile, '*$') | 784 line = readline(inputfile, '*$') |
784 while len(line) > 0:#for line in inputfile: | 785 while len(line) > 0:#for line in inputfile: |
802 cursor = connection.cursor() | 803 cursor = connection.cursor() |
803 queryStatement = 'SELECT t, trajectory_id, link_id, lane_id, s_coordinate, y_coordinate FROM curvilinear_positions' | 804 queryStatement = 'SELECT t, trajectory_id, link_id, lane_id, s_coordinate, y_coordinate FROM curvilinear_positions' |
804 if objectNumbers is not None: | 805 if objectNumbers is not None: |
805 queryStatement += ' WHERE trajectory_id '+getObjectCriteria(objectNumbers) | 806 queryStatement += ' WHERE trajectory_id '+getObjectCriteria(objectNumbers) |
806 queryStatement += ' ORDER BY trajectory_id, t' | 807 queryStatement += ' ORDER BY trajectory_id, t' |
807 for row in cursor: | 808 try: |
808 objNum = row[1] | 809 cursor.execute(queryStatement) |
809 instant = row[0]*simulationStepsPerTimeUnit | 810 for row in cursor: |
810 s = row[4] | 811 objNum = row[1] |
811 y = row[5] | 812 instant = row[0]*simulationStepsPerTimeUnit |
812 lane = '{}_{}'.format(row[2], row[3]) | 813 s = row[4] |
813 if objNum not in objects: | 814 y = row[5] |
814 if warmUpLastInstant is None or instant >= warmUpLastInstant: | 815 lane = '{}_{}'.format(row[2], row[3]) |
815 if objectNumbers is None or len(objects) < objectNumbers: | 816 if objNum not in objects: |
816 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) | 817 if warmUpLastInstant is None or instant >= warmUpLastInstant: |
817 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() | 818 if objectNumbers is None or len(objects) < objectNumbers: |
818 if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: | 819 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) |
819 objects[objNum].timeInterval.last = instant | 820 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() |
820 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) | 821 if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: |
822 objects[objNum].timeInterval.last = instant | |
823 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) | |
824 except sqlite3.OperationalError as error: | |
825 printDBError(error) | |
821 else: | 826 else: |
822 print("File type of "+filename+" not supported (only .sqlite and .fzp files)") | 827 print("File type of "+filename+" not supported (only .sqlite and .fzp files)") |
823 return objects.values() | 828 return objects.values() |
824 | 829 |
825 def selectPDLanes(data, lanes = None): | 830 def selectPDLanes(data, lanes = None): |