Skip to content

Commit

Permalink
Add ability to get cal_targets from linked cal_target table (#17)
Browse files Browse the repository at this point in the history
* add ability to get cal_targets from linked cal_target table

* add check for source, update error message
  • Loading branch information
mmccrackan authored Feb 11, 2025
1 parent 1a8fa60 commit 2809886
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/scheduler_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def get_preset_config(preset_name, default={}):
},
'queries': {
'sort': '-from',
'fields': 'program,from,to,config,status'
'expand': 'cal_targets'
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/scheduler_server/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,29 @@ def rest_handler(t0, t1, policy_config={}):
config = yaml.safe_load(best_plan['config'])
if isinstance(config, str):
config = {"schedule": config}

# add cal targets from linked table
cal_keys = ['boresight', 'elevation', 'focus', 'allow_partial', 'az_speed', 'az_accel']
# don't overwrite any cal targets passed in the config
if 'cal_targets' not in config:
config['cal_targets'] = []
# ignore if no linked cal targets
if 'cal_targets.source' in best_plan:
for i, source in enumerate(best_plan['cal_targets.source']):
if source is None:
logger.warn("No source name, skipping")
continue
cal_target = {}
cal_target['source'] = source
for cal_key in cal_keys:
if best_plan['cal_targets.' + cal_key][i] is not None:
cal_target[cal_key] = best_plan['cal_targets.' + cal_key][i]
config['cal_targets'].append(cal_target)
logger.info(f"Best plan cal targets: {config['cal_targets']}")
except Exception as e:
logger.error(f"Failed to load yaml config with error: {e}")
logger.error(f"config: {best_plan['config']}")
raise ValueError("Failed to parse yaml config")
raise ValueError(f"Failed to parse yaml config: {e}")

script_base = os.environ['SCHED_BASE']
module_path = op.join(script_base, program) + (".py" if not program.endswith(".py") else "")
Expand Down

0 comments on commit 2809886

Please sign in to comment.