inserts as dict
This commit is contained in:
parent
b9bb919b96
commit
8389d49e71
42
main.py
42
main.py
@ -63,31 +63,31 @@ def process_gpx_files(tx: Connection, owner: str):
|
||||
if gpx_file.creator != 'FitoTrack':
|
||||
raise ValueError('gpx file not generated by the FitoTrack app')
|
||||
training_id = list(db.execute(
|
||||
"""insert into training (owner, filename, medium, description, moving_time, stopped_time, moving_distance, stopped_distance) values
|
||||
(?, ?, ?, ?, ?, ?, ?, ?) returning id""",
|
||||
(owner,
|
||||
filename,
|
||||
"",
|
||||
gpx_file.description,
|
||||
gpx_file.get_moving_data().moving_time,
|
||||
gpx_file.get_moving_data().stopped_time,
|
||||
gpx_file.get_moving_data().moving_distance,
|
||||
gpx_file.get_moving_data().stopped_distance,)
|
||||
text("""
|
||||
insert into training(owner, filename, type, description, moving_time, stopped_time, moving_distance, stopped_distance) values
|
||||
(:owner, :filename, :type, :description, :moving_time, :stopped_time, :moving_distance, :stopped_distance) returning id
|
||||
"""),
|
||||
dict(owner=owner,
|
||||
filename=filename,
|
||||
type='cycling', # TODO other training types
|
||||
description=gpx_file.description,
|
||||
moving_time=gpx_file.get_moving_data().moving_time,
|
||||
stopped_time=gpx_file.get_moving_data().stopped_time,
|
||||
moving_distance=gpx_file.get_moving_data().moving_distance,
|
||||
stopped_distance=gpx_file.get_moving_data().stopped_distance,),
|
||||
))[0][0]
|
||||
for track in gpx_file.tracks:
|
||||
for segment in track.segments:
|
||||
for point in segment.points:
|
||||
db.execute("""
|
||||
insert into training_data (training_id, t, lat, lon, speed, elevation)
|
||||
values (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(training_id,
|
||||
point.time,
|
||||
point.latitude,
|
||||
point.longitude,
|
||||
point.speed,
|
||||
point.elevation,)
|
||||
)
|
||||
db.execute(text("""
|
||||
insert into training_data(training_id, t, geog, speed, elevation)
|
||||
values (:training_id, :t, :geog, :speed, :elevation)
|
||||
"""),
|
||||
dict(training_id=training_id,
|
||||
t=point.time,
|
||||
geog=f'POINT({point.latitude} {point.longitude})',
|
||||
speed=point.speed,
|
||||
elevation=point.elevation,),)
|
||||
|
||||
|
||||
def main(owner: str):
|
||||
|
Loading…
x
Reference in New Issue
Block a user