Remove duplicate events from the same track
This commit is contained in:
parent
c63fd49245
commit
057e2bcc6c
|
@ -163,8 +163,11 @@ async def process_track(session, track, data_source):
|
|||
with open(target, "w") as fp:
|
||||
json.dump(data, fp, indent=4)
|
||||
|
||||
log.info("Import events into database...")
|
||||
log.info("Clearing old track data...")
|
||||
await clear_track_data(session, track)
|
||||
await session.commit()
|
||||
|
||||
log.info("Import events into database...")
|
||||
await import_overtaking_events(session, track, overtaking_events)
|
||||
|
||||
log.info("Write track statistics and update status...")
|
||||
|
@ -207,7 +210,10 @@ async def clear_track_data(session, track):
|
|||
|
||||
|
||||
async def import_overtaking_events(session, track, overtaking_events):
|
||||
event_models = []
|
||||
# We use a dictionary to prevent per-track hash collisions, ignoring all
|
||||
# but the first event of the same hash
|
||||
event_models = {}
|
||||
|
||||
for m in overtaking_events:
|
||||
hex_hash = hashlib.sha256(
|
||||
struct.pack(
|
||||
|
@ -215,8 +221,7 @@ async def import_overtaking_events(session, track, overtaking_events):
|
|||
)
|
||||
).hexdigest()
|
||||
|
||||
event_models.append(
|
||||
OvertakingEvent(
|
||||
event_models[hex_hash] = OvertakingEvent(
|
||||
track_id=track.id,
|
||||
hex_hash=hex_hash,
|
||||
way_id=m.get("OSM_way_id"),
|
||||
|
@ -235,6 +240,5 @@ async def import_overtaking_events(session, track, overtaking_events):
|
|||
course=m["course"],
|
||||
speed=m["speed"],
|
||||
)
|
||||
)
|
||||
|
||||
session.add_all(event_models)
|
||||
session.add_all(event_models.values())
|
||||
|
|
Loading…
Reference in a new issue