Skip to content

Commit

Permalink
Default to rereading the fields file (#488)
Browse files Browse the repository at this point in the history
* Now has an option in the config to specify if the file should be re-read or not.
  • Loading branch information
wtgee authored Apr 12, 2018
1 parent e084d0c commit 2d8120d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions conf_files/pocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ db:
scheduler:
type: dispatch
fields_file: simple.yaml
check_file: False
mount:
brand: ioptron
model: 30
Expand Down
3 changes: 2 additions & 1 deletion pocs/observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def get_observation(self, *args, **kwargs):

# If observation list is empty or a reread is requested
if (self.scheduler.has_valid_observations is False or
kwargs.get('reread_fields_file', False)):
kwargs.get('reread_fields_file', False) or
self.config['scheduler'].get('check_file', False)):
self.scheduler.read_field_list()

# This will set the `current_observation`
Expand Down
2 changes: 2 additions & 0 deletions pocs/scheduler/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def get_observation(self, time=None, show_all=False, reread_fields_file=False):
defaults to time called
show_all (bool, optional): Return all valid observations along with
merit value, defaults to False to only get top value
reread_fields_file (bool, optional): If the fields file should be reread
before scheduling occurs, defaults to False.
Returns:
tuple or list: A tuple (or list of tuples) with name and score of ranked observations
Expand Down
5 changes: 2 additions & 3 deletions pocs/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ def add_observation(self, field_config):
Args:
field_config (dict): Configuration items for `Observation`
"""
assert field_config['name'] not in self._observations.keys(), \
self.logger.error("Cannot add duplicate field name")

if 'exp_time' in field_config:
field_config['exp_time'] = float(field_config['exp_time']) * u.second

Expand All @@ -233,6 +230,8 @@ def add_observation(self, field_config):
self.logger.warning("Skipping invalid field config: {}".format(field_config))
self.logger.warning(e)
else:
if field.name in self._observations:
self.logger.debug("Overriding existing entry for {}".format(field.name))
self._observations[field.name] = obs

def remove_observation(self, field_name):
Expand Down
3 changes: 2 additions & 1 deletion pocs/state/states/default/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def on_enter(event_data):
pocs.logger.warning("Error in scheduling: {}".format(e))
else:

if observation != existing_observation:
if ((observation and existing_observation) and
(observation.name != existing_observation.name)):
pocs.say("Got it! I'm going to check out: {}".format(observation.name))

pocs.logger.debug("Setting Observation coords: {}".format(observation.field))
Expand Down
15 changes: 10 additions & 5 deletions pocs/tests/test_base_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,18 @@ def test_scheduler_add_duplicate_field(scheduler):
scheduler.add_observation({
'name': 'Duplicate Field',
'position': '12h30m01s +08d08m08s',
'priority': 100
})

with pytest.raises(AssertionError):
scheduler.add_observation({
'name': 'Duplicate Field',
'position': '12h30m01s +08d08m08s',
})
assert scheduler.observations['Duplicate Field'].priority == 100

scheduler.add_observation({
'name': 'Duplicate Field',
'position': '12h30m01s +08d08m08s',
'priority': 500
})

assert scheduler.observations['Duplicate Field'].priority == 500


def test_scheduler_add_duplicate_field_different_name(scheduler):
Expand Down

0 comments on commit 2d8120d

Please sign in to comment.