Skip to content

Commit

Permalink
debugging, non-integer values are problematic
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffckerr committed Sep 15, 2023
1 parent abd62dc commit 057b4a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
33 changes: 17 additions & 16 deletions binomialbias/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def get_ui():
for key in ui_keys:
try:
raw = input[key]()
v = bbm.to_num(raw)
v = bbm.to_num(raw, die=False)
u[key] = v
except:
print(f'Encountered error with input: {key} = "{raw}", continuing...')
Expand All @@ -244,21 +244,22 @@ def reconcile_inputs():
for k in ui_keys:
gv = g[k]
uv = bbm.to_num(u[k])
if k in slider_keys:
uv = round(uv)
match = sc.approx(gv, uv)
if not match: # Avoid floating point errors
print(f'Mismatch for {k}: {gv}{uv}')
g[k] = uv # Always set the current key to the current value
if k in ['nt', 'ntt']:
g.nt = uv
g.ntt = uv
reconcile_fracs('ne', 'na')
if k == 'ntt':
check_sliders()
else:
reconcile_fracs(k)
break
if not np.isnan(uv):
if k in slider_keys:
uv = round(uv)
match = sc.approx(gv, uv)
if not match: # Avoid floating point errors
print(f'Mismatch for {k}: {gv}{uv}')
g[k] = uv # Always set the current key to the current value
if k in ['nt', 'ntt']:
g.nt = uv
g.ntt = uv
reconcile_fracs('ne', 'na')
if k == 'ntt':
check_sliders()
else:
reconcile_fracs(k)
break

# The isolation here avoids a potential infinite loop
with sh.reactive.isolate():
Expand Down
13 changes: 9 additions & 4 deletions binomialbias/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ def to_str(x, sf=3):
return string


def to_num(x):
def to_num(x, die=False):
""" Convert a string to a number, handling either ints or floats """
try:
if sc.isnumber(x):
x = to_str(x)
num = float(x) if '.' in x else int(x) # Handle int or float
except:
num = np.nan
except Exception as E:
if die:
raise E
else:
num = np.nan
return num


Expand Down Expand Up @@ -352,7 +355,9 @@ def plot(self, dist_color='cornflowerblue', cdf_color='darkblue', ci_color='k',
if gap or i == 1:
ax.text(ira, dy+pmf[ira],'$n_a$', **textkw)

ax.set_aspect(d.n/vmax*0.3)
print('TEMP HI I AM', d.n, vmax, type(d.n), type(vmax), d.n/vmax*0.3)

# ax.set_aspect(d.n/vmax*0.3)

# Add frame labels
if letters:
Expand Down

0 comments on commit 057b4a2

Please sign in to comment.