Skip to content

Commit

Permalink
Reduce number of digits shown to reasonable level
Browse files Browse the repository at this point in the history
  • Loading branch information
ehneilsen committed Sep 26, 2022
1 parent 768a780 commit 406cd73
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions schedview/plot/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ def make_reward_table(self):
index=range(30),
columns=["basis_function", "feasible", "basis_reward", "accum_reward"],
)

self.bokeh_models["reward_table"] = bokeh.models.DataTable(
source=bokeh.models.ColumnDataSource(df),
columns=[bokeh.models.TableColumn(field=c, title=c) for c in df],
Expand All @@ -829,6 +830,13 @@ def update_reward_table_bokeh_model(self):
reward_df = self.scheduler.survey_lists[self.survey_index[0]][
self.survey_index[1]
].make_reward_df(self.conditions)

def to_sigfig(x):
return float("{:.5g}".format(x))

for col in ["basis_reward", "accum_reward"]:
reward_df[col] = reward_df[col].apply(to_sigfig)

self.bokeh_models["reward_table"].source = bokeh.models.ColumnDataSource(
reward_df
)
Expand Down Expand Up @@ -941,6 +949,19 @@ def update_reward_summary_table_bokeh_model(self):
LOGGER.info("Updating reward summary table bokeh model")
if "reward_summary_table" in self.bokeh_models:
scheduler_summary_df = self.make_scheduler_summary_df()

def to_sigfig(x):
try:
value = float(x)
except ValueError:
return x

return float("{:.5g}".format(value))

scheduler_summary_df["reward"] = scheduler_summary_df["reward"].apply(
to_sigfig
)

self.bokeh_models["reward_summary_table"].source.data = dict(
bokeh.models.ColumnDataSource(scheduler_summary_df).data
)
Expand Down

0 comments on commit 406cd73

Please sign in to comment.