Skip to content

Commit

Permalink
improve output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
cwpearson committed Jan 21, 2024
1 parent f44b502 commit 3087586
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 11 additions & 0 deletions beavertails/beavertails.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
width: 1fr;
border: white;
}
.output-recipe {
height:1;

&.name {
width: 2fr;
}
&.value {
width: 1fr;
}
}


.item-input {
width: 2fr; /*otherwise, grow to fill screen width*/
Expand Down
13 changes: 10 additions & 3 deletions beavertails/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,16 @@ def solve(needs: Rates, settings: Settings):
prob2, var_names2 = construct_phase2(needs, settings, value(prob1.objective))
status2, log2 = mypulp.solve(prob2)

vars = {
var_names2[var]: value(var) for var in prob2.variables() if "_int" in str(var)
}
# only return integer recipe values
vars = {}
for var in prob2.variables():
if "_int" in str(var):
name = var_names2[var]
try:
val = int(value(var))
except:
val = value(var)
vars[name] = val
result = {
"beavers": value(prob1.objective),
"tiles": value(prob2.objective),
Expand Down
10 changes: 8 additions & 2 deletions beavertails/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ def compose(self) -> ComposeResult:
yield Label("tiles", id="tiles-name", classes="tiles-name")
yield Label(id="tiles-value", classes="tiles-value")
with VerticalScroll(id="item-list"):
yield Label(classes="output-recipe")
with Horizontal(classes="output-recipe"):
yield Label(classes="output-recipe name")
yield Label(classes="output-recipe value")

def add_item(self, name, value):
new_entry = Label(f"{name}: {value}")
new_entry = Horizontal(
Label(f"{name}", classes="output-recipe name"),
Label(f"{value}", classes="output-recipe value"),
classes="output-recipe",
)
self.query_one("#item-list").mount(new_entry)

def remove_items(self):
Expand Down

0 comments on commit 3087586

Please sign in to comment.