The "advanced" option gives the user the most control over the budget values processed
by OptiPass by letting them specify the number of budget levels (in the basic budget
there are always 10 budget levels).
This box has three widgets: a slider to specify the
maximum amount, another slider to specify the increment between budgets, and
an input box to specify the number of budgets. Adjusting the value of any of these
widgets automatically updates the other two. For example, if the maximum is set to $1M
and the number of budgets is 10, the increment is $100K. If the user changes the number
of budgets to 20, the increment drops to $50K. Or if they change the maximum to $2M, the
increment increases to $200K.
Source code in src/tidegates/budgets.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233 | def __init__(self):
super(AdvancedBudgetBox, self).__init__(margin=(15,0,15,5))
self.cap = 0
self.max_slider = pn.widgets.FloatSlider(
name='Maximum Budget',
start=0,
end=1,
step=self.MAX_STEP,
value=0,
width=self.SLIDER_WIDTH,
format=NumeralTickFormatter(format='$0,0'),
stylesheets=[slider_style_sheet],
)
self.inc_slider = pn.widgets.FloatSlider(
name='Budget Interval',
start=0,
end=1,
step=self.INC_STEP,
value=0,
width=self.SLIDER_WIDTH//2,
format=NumeralTickFormatter(format='$0,0'),
stylesheets=[slider_style_sheet],
)
self.count_input = pn.widgets.IntInput(
name='Number of Budgets',
value=10,
step=1,
start=self.COUNT_MIN,
end=self.COUNT_MAX,
width=75,
)
self.append(pn.Row(self.max_slider, pn.pane.HTML('<b>Limit: N/A<b>')))
self.append(pn.Row(self.inc_slider, self.count_input))
self.max_slider.param.watch(self.max_updated, ['value'])
self.inc_slider.param.watch(self.inc_updated, ['value'])
self.count_input.param.watch(self.count_updated, ['value'])
|
count_updated(e)
Callback function invoked when the user changes the number of budget
levels. Computes a new budget increment.
src/tidegates/budgets.py
| def count_updated(self, e):
"""
Callback function invoked when the user changes the number of budget
levels. Computes a new budget increment.
"""
self.inc_slider.value = self.max_slider.value // self.count_input.value
|
inc_updated(e)
Callback function invoked when the user changes the budget increment.
Computes a new number of budgets.
src/tidegates/budgets.py
264
265
266
267
268
269
270
271 | def inc_updated(self, e):
"""
Callback function invoked when the user changes the budget increment.
Computes a new number of budgets.
"""
c = max(self.COUNT_MIN, self.max_slider.value // self.inc_slider.value)
c = min(self.COUNT_MAX, c)
self.count_input.value = c
|
max_updated(e)
Callback function invoked when the user moves the maximum budget
slider. Computes a new budget increment.
src/tidegates/budgets.py
| def max_updated(self, e):
"""
Callback function invoked when the user moves the maximum budget
slider. Computes a new budget increment.
"""
self.inc_slider.value = self.max_slider.value // self.count_input.value
|
set_budget_max(n)
Called when the user selects or deselects a region. Save the new
maximum, and update the value of the increment based on the new maximum.
| Parameters: |
-
n
–
the total cost of all barriers in the selected regions.
|
src/tidegates/budgets.py
242
243
244
245
246
247
248
249
250
251
252
253
254
255 | def set_budget_max(self, n):
"""
Called when the user selects or deselects a region. Save the new
maximum, and update the value of the increment based on the new maximum.
Arguments:
n: the total cost of all barriers in the selected regions.
"""
self.max_slider.end = max(1, n)
self.max_slider.start = self.MAX_STEP
self.inc_slider.end = max(1, n // 2)
self.inc_slider.start = max(self.INC_STEP, n / self.COUNT_MAX)
lim = 'N/A' if n == 0 else f'${n/1000000:.2f}M'
self[0][1] = pn.pane.HTML(f'<b>Limit: {lim}</b>')
|
values()
In this widget the maximum budget and budget increment are determined
by the values in the corresponding widgets.
src/tidegates/budgets.py
| def values(self):
"""
In this widget the maximum budget and budget increment are determined
by the values in the corresponding widgets.
"""
return self.max_slider.value, self.inc_slider.value
|