Skip to content

Commit

Permalink
[delta_q] handle large CDFs in the UI display
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuhn committed Dec 7, 2024
1 parent a223b2d commit 2f761c9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 7 deletions.
8 changes: 8 additions & 0 deletions delta_q/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@ You may want to copy the latest example from `models.txt`, taking the whole set
## Known Shortcomings

- functional but ugly

## misc

### converting from latencies.json of the Haskell simulation

```sh
jq -r '[.[]|.[1]]|sort|length as $l|[foreach .[] as $i (0;.+1;if .%100==0 or .==$l then "("+($i|tostring)+", "+(./$l|tostring)+")" else null end)|select(.)]|join(",")' latencies.json
```
24 changes: 24 additions & 0 deletions delta_q/comparison_hs.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion delta_q/src/bin/editor-web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn edit_expression(props: &EditExpressionProps) -> HtmlResult {
<pre>{ &*result }</pre>
</div>
} else {
<span class={classes!("dq_show")} onclick={cloned!(editing; move |_| editing.set(true))}>{ value.to_string() }</span>
<span class={classes!("dq_show")} onclick={cloned!(editing; move |_| editing.set(true))}>{ format!("{:#}", *value) }</span>
}
})
}
Expand Down
6 changes: 5 additions & 1 deletion delta_q/src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ impl Default for CDF {
impl fmt::Display for CDF {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "CDF")?;
write!(f, "{}", self.steps)?;
if f.alternate() {
write!(f, "{:#}", self.steps)?;
} else {
write!(f, "{}", self.steps)?;
}
Ok(())
}
}
Expand Down
6 changes: 5 additions & 1 deletion delta_q/src/delta_q.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ impl DeltaQ {
}
}
DeltaQExpr::Outcome(outcome) => {
write!(f, "{}", outcome)
if f.alternate() {
write!(f, "{:#}", outcome)
} else {
write!(f, "{}", outcome)
}
}
DeltaQExpr::Seq(first, load, second) => {
if parens {
Expand Down
13 changes: 10 additions & 3 deletions delta_q/src/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ impl Outcome {
}
impl Display for Outcome {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.cdf)?;
for (metric, load) in self.load.iter() {
write!(f, " WITH {metric}{load}")?;
if f.alternate() {
write!(f, "{:#}", self.cdf)?;
for (metric, load) in self.load.iter() {
write!(f, " WITH {metric}{load:#}")?;
}
} else {
write!(f, "{}", self.cdf)?;
for (metric, load) in self.load.iter() {
write!(f, " WITH {metric}{load}")?;
}
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion delta_q/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn cdf_component(props: &CdfProps) -> Html {

html! {
<div class={classes!("cdf", "anchor")} onclick={cloned!(popup; move |_| if !*popup { popup.set(true) })}>
{ format!("{}", props.outcome) }
{ format!("{:#}", props.outcome) }
if *popup {
<div class={classes!("popup")}>
<button onclick={cloned!(popup; move |_| popup.set(false))}>{ "abort" }</button>
Expand Down
9 changes: 9 additions & 0 deletions delta_q/src/step_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,26 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut scratch = String::new();

let mut written = 1;
write!(f, "[")?;
for (i, (x, y)) in self.data().iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
written += 2;
}
write!(&mut scratch, "{:.5}", x)?;
write!(f, "({}, ", trim(&scratch))?;
written += 3 + scratch.len();
scratch.clear();
y.pretty_print(&mut scratch)?;
write!(f, "{})", trim(&scratch))?;
written += 1 + scratch.len();
scratch.clear();

if f.alternate() && written > 80 {
write!(f, " ...")?;
break;
}
}
write!(f, "]")?;
Ok(())
Expand Down

0 comments on commit 2f761c9

Please sign in to comment.