Mercurial > hg > nsaunier > traffic-intelligence
comparison python/storage.py @ 628:977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 16 Feb 2015 11:58:51 +0100 |
| parents | dc2d0a0d7fe1 |
| children | 3058e00887bc |
comparison
equal
deleted
inserted
replaced
| 627:82e9f78a4714 | 628:977407c9f815 |
|---|---|
| 516 cursor.execute('select INT.id, INT.object_id1, INT.object_id2, INT.first_frame_number, INT.last_frame_number, IND.indicator_type, IND.frame_number, IND.value from interactions INT, indicators IND where INT.id = IND.interaction_id ORDER BY INT.id, IND.indicator_type') | 516 cursor.execute('select INT.id, INT.object_id1, INT.object_id2, INT.first_frame_number, INT.last_frame_number, IND.indicator_type, IND.frame_number, IND.value from interactions INT, indicators IND where INT.id = IND.interaction_id ORDER BY INT.id, IND.indicator_type') |
| 517 interactionNum = -1 | 517 interactionNum = -1 |
| 518 indicatorTypeNum = -1 | 518 indicatorTypeNum = -1 |
| 519 tmpIndicators = {} | 519 tmpIndicators = {} |
| 520 for row in cursor: | 520 for row in cursor: |
| 521 if row[0] != interactionNum: # save interaction and create new interaction | 521 if row[0] != interactionNum: |
| 522 if interactionNum >= 0: | |
| 523 interactions.append(events.Interaction(interactionNum, moving.TimeInterval(row[3],row[4]), roadUserNumbers[0], roadUserNumbers[1])) | |
| 524 interactions[-1].indicators = tmpIndicators | |
| 525 tmpIndicators = {} | |
| 526 interactionNum = row[0] | 522 interactionNum = row[0] |
| 527 roadUserNumbers = row[1:3] | 523 interactions.append(events.Interaction(interactionNum, moving.TimeInterval(row[3],row[4]), row[1], row[2])) |
| 524 interactions[-1].indicators = {} | |
| 528 if indicatorTypeNum != row[5]: | 525 if indicatorTypeNum != row[5]: |
| 529 if indicatorTypeNum >= 0: | 526 indicatorName = events.Interaction.indicatorNames[indicatorTypeNum] |
| 530 indicatorName = events.Interaction.indicatorNames[indicatorTypeNum] | 527 indicatorValues = {row[6]:row[7]} |
| 531 tmpIndicators[indicatorName] = indicators.SeverityIndicator(indicatorName, indicatorValues) | 528 interactions[-1].indicators[indicatorName] = indicators.SeverityIndicator(indicatorName, indicatorValues) |
| 532 indicatorTypeNum = row[5] | 529 indicatorTypeNum = row[5] |
| 533 indicatorValues = {row[6]:row[7]} | |
| 534 else: | 530 else: |
| 535 indicatorValues[row[6]] = row[7] | 531 indicatorValues[row[6]] = row[7] |
| 536 if interactionNum >= 0: | |
| 537 if indicatorTypeNum >= 0: | |
| 538 indicatorName = events.Interaction.indicatorNames[indicatorTypeNum] | |
| 539 tmpIndicators[indicatorName] = indicators.SeverityIndicator(indicatorName, indicatorValues) | |
| 540 interactions.append(events.Interaction(interactionNum, moving.TimeInterval(row[3],row[4]), roadUserNumbers[0], roadUserNumbers[1])) | |
| 541 interactions[-1].indicators = tmpIndicators | |
| 542 except sqlite3.OperationalError as error: | 532 except sqlite3.OperationalError as error: |
| 543 printDBError(error) | 533 printDBError(error) |
| 544 return [] | 534 return [] |
| 545 connection.close() | 535 connection.close() |
| 546 return interactions | 536 return interactions |
