Mercurial > hg > nsaunier > traffic-intelligence
comparison python/storage.py @ 751:79405a938407 dev
corrected bug
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 28 Oct 2015 23:22:57 -0400 |
| parents | 6049e9b6902c |
| children | 14963a9c3b09 |
comparison
equal
deleted
inserted
replaced
| 750:6049e9b6902c | 751:79405a938407 |
|---|---|
| 775 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last'])) | 775 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last'])) |
| 776 # positions should be rounded to nDecimals decimals only | 776 # 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()) | 777 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: | 778 if objectNumbers is not None and objectNumbers > 0 and len(objects) >= objectNumbers: |
| 779 break | 779 break |
| 780 return objects.values() | |
| 781 else: | 780 else: |
| 782 if filename.endswith(".fzp"): | 781 if filename.endswith(".fzp"): |
| 783 inputfile = openCheck(filename, quitting = True) | 782 inputfile = openCheck(filename, quitting = True) |
| 784 line = readline(inputfile, '*$') | 783 line = readline(inputfile, '*$') |
| 785 while len(line) > 0:#for line in inputfile: | 784 while len(line) > 0:#for line in inputfile: |
| 796 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() | 795 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() |
| 797 if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: | 796 if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: |
| 798 objects[objNum].timeInterval.last = instant | 797 objects[objNum].timeInterval.last = instant |
| 799 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) | 798 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) |
| 800 line = readline(inputfile, '*$') | 799 line = readline(inputfile, '*$') |
| 801 return objects.values() | |
| 802 elif filename.endswith(".sqlite"): | 800 elif filename.endswith(".sqlite"): |
| 803 connection = sqlite3.connect(filename) | 801 connection = sqlite3.connect(filename) |
| 804 cursor = connection.cursor() | 802 cursor = connection.cursor() |
| 805 queryStatement = 'SELECT t, trajectory_id, link_id, lane_id, s_coordinate, y_coordinate FROM curvilinear_positions' | 803 queryStatement = 'SELECT t, trajectory_id, link_id, lane_id, s_coordinate, y_coordinate FROM curvilinear_positions' |
| 806 if objectNumbers is not None: | 804 if objectNumbers is not None: |
| 807 queryStatement += ' WHERE trajectory_id '+getObjectCriteria(objectNumbers) | 805 queryStatement += ' WHERE trajectory_id '+getObjectCriteria(objectNumbers) |
| 808 queryStatement += ' ORDER BY trajectory_id, t' | 806 queryStatement += ' ORDER BY trajectory_id, t' |
| 809 #objects = loadTrajectoriesFromTable(connection, "curvilinear_positions", "vissim_curvilinear", objectNumbers) | |
| 810 for row in cursor: | 807 for row in cursor: |
| 811 objNum = row[1] | 808 objNum = row[1] |
| 812 instant = row[0]*simulationStepsPerTimeUnit | 809 instant = row[0]*simulationStepsPerTimeUnit |
| 813 s = row[4] | 810 s = row[4] |
| 814 y = row[5] | 811 y = row[5] |
| 821 if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: | 818 if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: |
| 822 objects[objNum].timeInterval.last = instant | 819 objects[objNum].timeInterval.last = instant |
| 823 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) | 820 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) |
| 824 else: | 821 else: |
| 825 print("File type of "+filename+" not supported (only .sqlite and .fzp files)") | 822 print("File type of "+filename+" not supported (only .sqlite and .fzp files)") |
| 826 | 823 return objects.values() |
| 827 | 824 |
| 828 def selectPDLanes(data, lanes = None): | 825 def selectPDLanes(data, lanes = None): |
| 829 '''Selects the subset of data for the right lanes | 826 '''Selects the subset of data for the right lanes |
| 830 | 827 |
| 831 Lane format is a string 'x_y' where x is link index and y is lane index''' | 828 Lane format is a string 'x_y' where x is link index and y is lane index''' |
