DB config
This commit is contained in:
parent
368b556a51
commit
fd583cbc5b
@ -46,49 +46,51 @@ def updateLast(db, cursor):
|
|||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
|
|
||||||
ins_id = row[0]
|
if row[0]:
|
||||||
|
ins_id = row[0]
|
||||||
|
|
||||||
## hole alle Fahrten nach letzter Ladung
|
## hole alle Fahrten nach letzter Ladung
|
||||||
sql = '''
|
sql = '''
|
||||||
SELECT d_total_distance, d_total_ascent, d_avg_speed FROM bike_drives WHERE d_date >= ?;
|
SELECT d_total_distance, d_total_ascent, d_avg_speed FROM bike_drives WHERE d_date >= ?;
|
||||||
'''
|
'''
|
||||||
cursor.execute(sql, (row[1],))
|
cursor.execute(sql, (row[1],))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
total_range = 0
|
total_range = 0
|
||||||
total_ascent = 0
|
total_ascent = 0
|
||||||
avg_speed = 0
|
avg_speed = 0
|
||||||
fahrten = 0
|
fahrten = 0
|
||||||
|
|
||||||
print("Anzahl:", len(rows))
|
print("Anzahl:", len(rows))
|
||||||
if len(rows) < 1:
|
if len(rows) < 1:
|
||||||
cursor.close()
|
print("Keine neuen Daten vorhanden, beende jetzt.")
|
||||||
if db:
|
cursor.close()
|
||||||
db.close()
|
if db:
|
||||||
print("The SQLite connection is closed")
|
db.close()
|
||||||
exit(0)
|
print("The SQLite connection is closed")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
fahrten += 1
|
fahrten += 1
|
||||||
total_range += row[0]
|
total_range += row[0]
|
||||||
total_ascent += row[1]
|
total_ascent += row[1]
|
||||||
avg_speed += row[2]
|
avg_speed += row[2]
|
||||||
|
|
||||||
avg_speed = round(avg_speed / fahrten, 1)
|
avg_speed = round(avg_speed / fahrten, 1)
|
||||||
|
|
||||||
data = (total_range, total_ascent, avg_speed, watt, fahrten, ins_id)
|
data = (total_range, total_ascent, avg_speed, watt, fahrten, ins_id)
|
||||||
sql = '''
|
sql = '''
|
||||||
UPDATE bike_loading SET
|
UPDATE bike_loading SET
|
||||||
l_total_range = ?,
|
l_total_range = ?,
|
||||||
l_total_ascent = ?,
|
l_total_ascent = ?,
|
||||||
l_avg_speed = ?,
|
l_avg_speed = ?,
|
||||||
l_loaded_wh = ?,
|
l_loaded_wh = ?,
|
||||||
l_fahrten = ?
|
l_fahrten = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
'''
|
'''
|
||||||
cursor.execute(sql, data)
|
cursor.execute(sql, data)
|
||||||
db.commit()
|
db.commit()
|
||||||
print("Data updated successfully into bike_loading table")
|
print("Data updated successfully into bike_loading table")
|
||||||
|
|
||||||
|
|
||||||
def insertNew(db, cursor):
|
def insertNew(db, cursor):
|
||||||
|
@ -29,6 +29,7 @@ def main():
|
|||||||
if type_names[0] == "IN_MOVED_TO":
|
if type_names[0] == "IN_MOVED_TO":
|
||||||
if filename.endswith(ext):
|
if filename.endswith(ext):
|
||||||
processFIT(filename)
|
processFIT(filename)
|
||||||
|
deleteFiles(filename)
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -126,10 +127,13 @@ def writeDB():
|
|||||||
print("The SQLite connection is closed")
|
print("The SQLite connection is closed")
|
||||||
|
|
||||||
|
|
||||||
#row.extend(["Date", "Total Distance", "Total Ascent", "Max Alt.", "AVG Speed", "AVG HR", "Calories"])
|
def deleteFiles(filename):
|
||||||
#row.extend([fitData["date"], fitData["total_distance"], fitData["total_ascent"], fitData["max_altitude"], fitData["avg_speed"],
|
try:
|
||||||
# fitData["avg_heart_rate"], fitData["total_calories"] ])
|
file = filename.remove(ext)
|
||||||
|
os.unlink(path+file+".*")
|
||||||
|
print("lösche", file)
|
||||||
|
except Exception as e:
|
||||||
|
print('Failed to delete %s. Reason: %s' % (path+filename, e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user