From 7d6a2e0a789639b3d4d3c45daef41617849a0656 Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Sat, 30 Apr 2022 01:38:39 -0400 Subject: [PATCH] Calculate all Cycles... --- period/cycles.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/period/cycles.py b/period/cycles.py index 596ce39..6db2ce0 100644 --- a/period/cycles.py +++ b/period/cycles.py @@ -151,16 +151,15 @@ def cycle_math(): for num, cycle in enumerate(all_cycles): # http://127.0.0.1:5000/cycle_math # cycle length = next start - this start - if num > 0: - this_start = pendulum.parse(cycle['start_time']) - next_start = pendulum.parse(all_cycles[num-1]['start_time']) - cycle_length = (next_start - this_start).days - db.execute( - 'UPDATE cycle SET cycle_length = ?' - ' WHERE id = ?', - (cycle_length, cycle['id']) - ) - db.commit() + this_start = pendulum.parse(cycle['start_time']) + next_start = pendulum.parse(all_cycles[num-1]['start_time']) + cycle_length = (next_start - this_start).days + db.execute( + 'UPDATE cycle SET cycle_length = ?' + ' WHERE id = ?', + (cycle_length, cycle['id']) + ) + db.commit() return redirect(url_for('cycles.index')) \ No newline at end of file