Skip to content

Commit f9ea18b

Browse files
committed
add units to the monitoring frequency
1 parent 593ce97 commit f9ea18b

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

tom_swift/swift.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
SWIFT_TARGET_CLASSIFICATION_CHOICES,
1818
SWIFT_URGENCY_CHOICES,
1919
SWIFT_XRT_MODE_CHOICES)
20+
get_monitoring_unit_choices,)
2021

2122
logger = logging.getLogger(__name__)
2223
logger.setLevel(logging.DEBUG)
@@ -155,8 +156,11 @@ class SwiftObservationForm(BaseObservationForm):
155156
help_text=('If number of visits more than one change next exposure'
156157
'time per visit and monitoring frequency, otherwise leave blank.'),
157158
initial=1)
158-
monitoring_freq = forms.CharField(required=False, label='Frequency of visits')
159-
# TODO: only expose exp_time_per_visit if monitoring freqency is > 1
159+
monitoring_freq = forms.IntegerField(required=False, label='Monitoring Frequency', initial=1)
160+
monitoring_units = forms.ChoiceField(
161+
required=False,
162+
choices=get_monitoring_unit_choices(),
163+
)
160164

161165
#
162166
# Swift Guest Investigator program parameters
@@ -296,7 +300,11 @@ def layout(self):
296300
Div(
297301
'num_of_visits',
298302
'exp_time_per_visit',
299-
'monitoring_freq',
303+
Div(
304+
Div(Field('monitoring_freq'), css_class='col-md-6',),
305+
Div(Field('monitoring_units'), css_class='col-md-6',),
306+
css_class='row',
307+
),
300308
)
301309
),
302310
AccordionGroup('Tiling',
@@ -557,13 +565,14 @@ def _configure_too(self, observation_payload):
557565
#
558566
# Monitoring requests
559567
#
560-
self.swift_api.too.num_of_visits == observation_payload['num_of_visits'] # use assignment expression?
568+
self.swift_api.too.num_of_visits = observation_payload['num_of_visits'] # use assignment expression?
561569
if self.swift_api.too.num_of_visits > 1:
562570
self.swift_api.too.exp_time_per_visit = observation_payload['exp_time_per_visit']
563-
self.swift_api.too.monitoring_freq = observation_payload['monitoring_freq']
564-
# TODO: Units for monitoring_freq (days, hours, minutes, seconds, orbits, others, etc.)
565-
# TODO: make ChoiceField for valid units (above) and (here) construct the formatted text
566-
# for the monitoring_freq field (e.g. "1 orbit", "2 days", "3 hours", etc.)
571+
# construct monitoring_freq from monitoring_freq and monitoring_units e.g '1 hour'
572+
self.swift_api.too.monitoring_freq = f"{observation_payload['monitoring_freq']} {observation_payload['monitoring_units']}"
573+
else:
574+
self.swift_api.too.exp_time_per_visit = None
575+
self.swift_api.too.monitoring_freq = None
567576

568577
#
569578
# Swift Guest Investigator program parameters

tom_swift/swift_api.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ def resolve_target(self, target: Target):
142142
#(9, "Bias"),
143143
]
144144

145-
146-
147145
#
148146
# UVOT Modes
149147
#
@@ -156,3 +154,16 @@ def resolve_target(self, target: Target):
156154
# Any string will validate:
157155
# >>> too.uvot_mode = "I think I want all UV filters for this, whatever the UVOT team recommends."
158156

157+
#
158+
# Monitoring
159+
#
160+
def get_monitoring_unit_choices():
161+
"""Returns a list of tuples for the monitoring frequency unit choices.
162+
163+
Since the TOO() object has propperty describing the valid monitoring frequency units,
164+
use that to create the choices list of tuples (e.g. [('day', 'day'), ('week', 'week'), ...]).
165+
"""
166+
monitoring_unit_choices = []
167+
for unit in TOO().monitoring_units:
168+
monitoring_unit_choices.append((unit, unit))
169+
return monitoring_unit_choices

tom_swift/templates/tom_swift/observation_form.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
// show the monitoring fields
4141
document.getElementById('div_id_exp_time_per_visit').style.display = '';
4242
document.getElementById('div_id_monitoring_freq').style.display = '';
43+
document.getElementById('div_id_monitoring_units').style.display = '';
4344
} else {
4445
// hide the monitoring fields
4546
document.getElementById('div_id_exp_time_per_visit').style.display = 'none';
4647
document.getElementById('div_id_monitoring_freq').style.display = 'none';
48+
document.getElementById('div_id_monitoring_units').style.display = 'none';
4749
}
4850
};
4951

0 commit comments

Comments
 (0)