DB config
This commit is contained in:
parent
368b556a51
commit
fd583cbc5b
@ -46,50 +46,52 @@ 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
|
|
||||||
sql = '''
|
## hole alle Fahrten nach letzter Ladung
|
||||||
SELECT d_total_distance, d_total_ascent, d_avg_speed FROM bike_drives WHERE d_date >= ?;
|
sql = '''
|
||||||
'''
|
SELECT d_total_distance, d_total_ascent, d_avg_speed FROM bike_drives WHERE d_date >= ?;
|
||||||
cursor.execute(sql, (row[1],))
|
'''
|
||||||
rows = cursor.fetchall()
|
cursor.execute(sql, (row[1],))
|
||||||
|
rows = cursor.fetchall()
|
||||||
total_range = 0
|
|
||||||
total_ascent = 0
|
total_range = 0
|
||||||
avg_speed = 0
|
total_ascent = 0
|
||||||
fahrten = 0
|
avg_speed = 0
|
||||||
|
fahrten = 0
|
||||||
print("Anzahl:", len(rows))
|
|
||||||
if len(rows) < 1:
|
print("Anzahl:", len(rows))
|
||||||
cursor.close()
|
if len(rows) < 1:
|
||||||
if db:
|
print("Keine neuen Daten vorhanden, beende jetzt.")
|
||||||
db.close()
|
cursor.close()
|
||||||
print("The SQLite connection is closed")
|
if db:
|
||||||
exit(0)
|
db.close()
|
||||||
|
print("The SQLite connection is closed")
|
||||||
for row in rows:
|
exit(0)
|
||||||
fahrten += 1
|
|
||||||
total_range += row[0]
|
for row in rows:
|
||||||
total_ascent += row[1]
|
fahrten += 1
|
||||||
avg_speed += row[2]
|
total_range += row[0]
|
||||||
|
total_ascent += row[1]
|
||||||
|
avg_speed += row[2]
|
||||||
|
|
||||||
|
avg_speed = round(avg_speed / fahrten, 1)
|
||||||
|
|
||||||
|
data = (total_range, total_ascent, avg_speed, watt, fahrten, ins_id)
|
||||||
|
sql = '''
|
||||||
|
UPDATE bike_loading SET
|
||||||
|
l_total_range = ?,
|
||||||
|
l_total_ascent = ?,
|
||||||
|
l_avg_speed = ?,
|
||||||
|
l_loaded_wh = ?,
|
||||||
|
l_fahrten = ?
|
||||||
|
WHERE id = ?
|
||||||
|
'''
|
||||||
|
cursor.execute(sql, data)
|
||||||
|
db.commit()
|
||||||
|
print("Data updated successfully into bike_loading table")
|
||||||
|
|
||||||
avg_speed = round(avg_speed / fahrten, 1)
|
|
||||||
|
|
||||||
data = (total_range, total_ascent, avg_speed, watt, fahrten, ins_id)
|
|
||||||
sql = '''
|
|
||||||
UPDATE bike_loading SET
|
|
||||||
l_total_range = ?,
|
|
||||||
l_total_ascent = ?,
|
|
||||||
l_avg_speed = ?,
|
|
||||||
l_loaded_wh = ?,
|
|
||||||
l_fahrten = ?
|
|
||||||
WHERE id = ?
|
|
||||||
'''
|
|
||||||
cursor.execute(sql, data)
|
|
||||||
db.commit()
|
|
||||||
print("Data updated successfully into bike_loading table")
|
|
||||||
|
|
||||||
|
|
||||||
def insertNew(db, cursor):
|
def insertNew(db, cursor):
|
||||||
global loading
|
global loading
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -124,13 +125,16 @@ def writeDB():
|
|||||||
if db:
|
if db:
|
||||||
db.close()
|
db.close()
|
||||||
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"])
|
|
||||||
#row.extend([fitData["date"], fitData["total_distance"], fitData["total_ascent"], fitData["max_altitude"], fitData["avg_speed"],
|
|
||||||
# fitData["avg_heart_rate"], fitData["total_calories"] ])
|
|
||||||
|
|
||||||
|
|
||||||
|
def deleteFiles(filename):
|
||||||
|
try:
|
||||||
|
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__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user