Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: take into account the midnight-spaning case when deciding if … #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ class exposureCalc:
def __init__(self, sunrise, sunset):
self.sunrise=sunrise
self.sunset=sunset
self.span_midnight=self.sunset < self.sunrise
def get_exposure(self, time):
if(time >=self.sunrise and time <=self.sunset):

if not self.span_midnight and (time >=self.sunrise and time <=self.sunset):
return 'auto'
return 'night'
elif self.span_midnight and (time >= self.sunrise or time <= self.sunset):
return 'auto'
else:
return 'night'

#One hour either side of sunrise/set
def take_shot(self, time):
if(time >=self.sunrise and time <=self.sunset):
if not self.span_midnight and (time >=self.sunrise and time <=self.sunset):
return True
elif self.span_midnight and (time >= self.sunrise or time <= self.sunset):
return True
return False
else:
return False
12 changes: 12 additions & 0 deletions test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ def test_exposureCalc_outsideLowerBounds(self):
exposureCalc1=exposureCalc(700,1700)
self.assertEqual(exposureCalc1.get_exposure(600), "night")

def test_exposureCalc_spanMidNight_middleBounds_beforeMidnight(self):
exposureCalc1=exposureCalc(1700, 700)
self.assertEqual(exposureCalc1.get_exposure(1900), 'auto')

def test_exposureCalc_spanMidNight_middleBounds_afterMidnight(self):
exposureCalc1=exposureCalc(1700, 700)
self.assertEqual(exposureCalc1.get_exposure(500), 'auto')

def test_exposureCalc_spanMidNight_outsideBounds(self):
exposureCalc1=exposureCalc(1700, 700)
self.assertEqual(exposureCalc1.get_exposure(1000), 'night')

def test_take_shot(self):
exp=exposureCalc(700,1700)
self.assertEqual(exp.take_shot(1700), True)
Expand Down