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':
|
if gpx_file.creator != 'FitoTrack':
|
||||||
raise ValueError('gpx file not generated by the FitoTrack app')
|
raise ValueError('gpx file not generated by the FitoTrack app')
|
||||||
training_id = list(db.execute(
|
training_id = list(db.execute(
|
||||||
"""insert into training (owner, filename, medium, description, moving_time, stopped_time, moving_distance, stopped_distance) values
|
text("""
|
||||||
(?, ?, ?, ?, ?, ?, ?, ?) returning id""",
|
insert into training(owner, filename, type, description, moving_time, stopped_time, moving_distance, stopped_distance) values
|
||||||
(owner,
|
(:owner, :filename, :type, :description, :moving_time, :stopped_time, :moving_distance, :stopped_distance) returning id
|
||||||
filename,
|
"""),
|
||||||
"",
|
dict(owner=owner,
|
||||||
gpx_file.description,
|
filename=filename,
|
||||||
gpx_file.get_moving_data().moving_time,
|
type='cycling', # TODO other training types
|
||||||
gpx_file.get_moving_data().stopped_time,
|
description=gpx_file.description,
|
||||||
gpx_file.get_moving_data().moving_distance,
|
moving_time=gpx_file.get_moving_data().moving_time,
|
||||||
gpx_file.get_moving_data().stopped_distance,)
|
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]
|
))[0][0]
|
||||||
for track in gpx_file.tracks:
|
for track in gpx_file.tracks:
|
||||||
for segment in track.segments:
|
for segment in track.segments:
|
||||||
for point in segment.points:
|
for point in segment.points:
|
||||||
db.execute("""
|
db.execute(text("""
|
||||||
insert into training_data (training_id, t, lat, lon, speed, elevation)
|
insert into training_data(training_id, t, geog, speed, elevation)
|
||||||
values (?, ?, ?, ?, ?, ?)
|
values (:training_id, :t, :geog, :speed, :elevation)
|
||||||
""",
|
"""),
|
||||||
(training_id,
|
dict(training_id=training_id,
|
||||||
point.time,
|
t=point.time,
|
||||||
point.latitude,
|
geog=f'POINT({point.latitude} {point.longitude})',
|
||||||
point.longitude,
|
speed=point.speed,
|
||||||
point.speed,
|
elevation=point.elevation,),)
|
||||||
point.elevation,)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main(owner: str):
|
def main(owner: str):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user