DEV Community

Tidy Cents
Tidy Cents

Posted on

Menu engineering in Python: compute the two cutoffs instead of guessing them

Menu engineering puts every dish in one of four boxes: star (popular, profitable), plowhorse (popular, thin margin), puzzle (profitable, rarely ordered) and dog. Most templates hand you the boxes and leave the two cutoff lines blank. The lines are the whole method:

  • Popularity line = 70% of an equal share of the mix. Five dishes, equal share 20%, line at 14%.
  • Margin line = average contribution margin per portion sold, weighted by units, not a plain average of the dishes.
from decimal import Decimal as D

def menu_matrix(items):
    """items: list of (name, price, plate_cost, units). Returns thresholds and quadrant per dish."""
    units = sum(u for *_, u in items)
    cm = {n: D(p) - D(c) for n, p, c, _ in items}
    avg_cm = sum(cm[n] * u for n, *_, u in items) / units       # weighted by what sold
    pop_line = D("0.7") / len(items)                              # 70% of an equal share
    out = {}
    for n, p, c, u in items:
        popular = D(u) / units >= pop_line
        profitable = cm[n] >= avg_cm
        out[n] = {(True, True): "star", (True, False): "plowhorse",
                  (False, True): "puzzle", (False, False): "dog"}[(popular, profitable)]
    return avg_cm, pop_line, out


menu = [("Tomato Soup", "6.50", "2.10", 42), ("Grilled Salmon", "24.00", "9.80", 18),
        ("Burger", "15.00", "5.40", 34), ("Mushroom Risotto", "18.00", "6.30", 14),
        ("Caesar Salad", "11.00", "3.20", 32)]
avg, line, q = menu_matrix(menu)
print(f"margin line {avg:.2f}  popularity line {line:.0%}")
for k, v in q.items(): print(f"{k:17} {v}")
Enter fullscreen mode Exit fullscreen mode

Output:

margin line 8.43  popularity line 14%
Tomato Soup       plowhorse
Grilled Salmon    puzzle
Burger            star
Mushroom Risotto  puzzle
Caesar Salad      plowhorse
Enter fullscreen mode Exit fullscreen mode

The top seller (soup, 30% of portions) is a plowhorse: it needs margin, not promotion. Use Decimal for money and keep >= on both comparisons so a dish exactly on a line classifies as high. A dish that sold zero still belongs in the list; deleting it changes the popularity line.

Browser version, no sign-up: Menu Engineering Matrix.

Top comments (0)