Skip to content

Commit

Permalink
Add calculate delta between slots and now (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh867 authored Apr 20, 2021
1 parent b452d33 commit bd9248c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions openoceancamera/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,17 @@ def next_future_timeslot(self):

def time_to_nearest_schedule(self):
possible_slots = []

# Get the future slots
for slot in self.schedule_data:
if slot["start"] >= datetime.now():
possible_slots.append(slot)

# Sorts the slots in case they may not be
possible_slots = sorted(possible_slots, key=lambda x: x["start"])

print(f"The time now is: {datetime.now()}")
print(f"The future slots are: {possible_slots}")

# Take the difference between the most recent slot's start time and time now
delta = possible_slots[0]["start"] - datetime.now()
print(f"The time difference is: {delta}")
# Returns an integer value for the time difference in seconds
return int(delta.total_seconds())

def time_to_slot(self, slot):
delta = slot["start"] - datetime.now()
return int(delta.total_seconds())
2 changes: 1 addition & 1 deletion openoceancamera/camera/camera_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def camera_thread():
slot_index = camera_schedule.should_start()
if slot_index == -1 and next_slot is not None:
# if the camera needs to shutdown, do wittypi stuff to shutdown the camera and set restart time and stop this loop
mins_to_next_slot = int(camera_schedule.time_to_nearest_schedule() / 60)
mins_to_next_slot = int(camera_schedule.time_to_slot(next_slot) / 60)
if mins_to_next_slot > 10:
shutdown_time = datetime.now() + timedelta(minutes=2)
shutdown_time = shutdown_time.strftime("%d %H:%M")
Expand Down

0 comments on commit bd9248c

Please sign in to comment.