Case study — Shiftova
Forecasting restaurant sales: how I built it, then tested whether it's actually good
I built the sales forecast inside Shiftova, my scheduling app for restaurants. It learns from one restaurant's own sales history to predict how busy each day will be. This is how I built it, how I tested whether it's actually good, and what I learned, including what didn't work.
Short on time? Read the 1-minute version →
The short version, in plain English
- A restaurant needs to know how busy each day will be, so it schedules the right number of people. Too few and service suffers. Too many and money is wasted.
- I built a forecast that learns from the restaurant's own sales history, then tested it honestly: on real past days, using only what was known at the time.
- It beats the franchisor's own method (the franchise's head office), mostly on holidays. Against simple averages the edge is small, and most of what's left is random day-to-day variation that nobody could predict.
- The most useful discovery: sales jump the day before a mid-week public holiday and sag for two days after it. The forecast now accounts for that.
Throughout, “error” or “miss” means how far off the forecast was, as a percentage of what actually sold.
~41%
lower error on holidays than the franchisor's own formula
17.5%
typical miss on a single day, roughly the best this data allows: even a forecaster that secretly knew each weekday's true average would miss by 17.7%
26% → 22%
average miss on the days right next to a holiday, after the adjustment I found
0
forecasts changed on days that aren't next to a holiday (tested, not assumed)
At a glance
- My role
- Sole engineer and analyst: framing the problem, building the forecast, testing it, and launching it.
- Data
- About three years of daily sales (1,000+ days) from a live restaurant, anonymized here.
- Methods
- Forecasting that ignores freak days (robust regression), replaying history day by day to test it (backtesting), comparing against simple methods and against random variation, and checking whether a pattern is real or just luck (statistical testing).
- Stack and status
- Built in TypeScript with a PostgreSQL database (Supabase), automated tests, and no outside AI services. Live and in daily use at a real restaurant.
Skills used
The problem: a forecast that decides how many people work
A restaurant schedules its staff a week ahead. Forecast sales too high and it overstaffs and loses money. Forecast too low and service suffers. The obvious approach is to average the last few same-weekdays (the last few Tuesdays, say), which is also what the franchisor's own tool does. On a small restaurant's real data it breaks in three specific ways:
- One bad day drags the average. A single mistyped number among ordinary days can pull a simple weekday average up by nearly 10x.
- A real turnaround gets averaged away. Years of decline followed by a genuine recent recovery looks like “nothing is happening” when every day counts equally.
- A real repeating pattern gets missed, or lands on the wrong weekday. A holiday, or a date like Halloween, is either ignored or gets blended into whichever day of the week it happened to fall on that year.
How it works: two parts working together
The data is daily sales entered by the restaurant: roughly three years, over 1,000 days. Real data has the problems you'd expect: typos, missing days, closures, one-off catering orders and holidays. The forecast has to cope with all of them without anyone cleaning the data by hand.
It has two parts. Part one learns the usual pattern from all the history: which weekdays are busy, how holidays behave, how the seasons change, and the long-run direction of the business. Part two looks only at the last 90 days and adjusts for how the business is running lately. Both parts use a method that automatically gives less weight to freak days (called robust regression), so one typo can't skew the result.
Two simpler designs failed first. In one, giving recent days extra weight distorted the seasonal picture and pointed it the wrong way months ahead. In the other, leaving out the long-run direction pushed that drift into the seasons instead, distorting them. Splitting the forecast into two independent parts fixed both.
Daily sales history
The most recent ~3 years of the restaurant's sales.
Part 1: the usual pattern
Weekdays, holidays, time of year and the long-run direction, learned from all the history. It also spots real repeating patterns on its own, but only if they showed up in 2+ years, clearly, the same way each time.
Part 2: the recent adjustment
How the last 90 days compare with the usual pattern. A hard cutoff, not a slow fade, so a real turnaround actually shows up.
Forecast = usual pattern + recent adjustment
Never below $0. A known one-off, like a big catering order, can be added by hand.
Final forecast for that date
Labelled low, medium or high confidence, based only on how much history exists. It reflects how much data there is, not a statistical margin of error.
What it spots on its own
The forecast can spot repeating patterns by itself, like a holiday that always sells unusually well or badly. But I made the bar deliberately high: a pattern has to show up in at least 2 years, be clearly unusual every single time, and always point the same way. One weak or contradictory year and it's rejected. That's on purpose, because once the forecast adopts a pattern it keeps applying it, so it needs strong evidence.
On the restaurant's multi-year history, it did find one recurring special day and one standout public holiday. It correctly refused to single out most other holidays, and found no reliable month-by-month pattern once the mix of weekdays was accounted for.
| Before the fix | After | True value |
|---|---|---|
| $4,600 (holiday treated like any other) | $2,026 (given its own adjustment) | ~$0 (the store is closed) |
Roughly a 56% smaller miss for that one date. Every other holiday's forecast moved by under 2%, correctly unaffected, since none of them met the bar for their own adjustment. The fix is a fixed dollar amount, so it still under-corrects if that holiday ever lands on the busiest day of the week: a real improvement, not a complete fix.
How I tested it
A forecast is only as credible as its test. Every number below comes from a replay of history (called backtesting): for each day, the forecast sees only the sales from before that day, makes its prediction, and is then compared with what really sold. Nothing from the future can leak in. I ran it twice:
- Against the franchisor's own formula. I worked out how the franchisor's scheduling spreadsheet predicts sales and checked it against the restaurant's real sales. Underneath, it simply averages the same weekday over the last 4 weeks (with a manual override that was never used in any week I checked). 173 weeks, 1,211 days scored.
- Against simple averages, and against random variation. A tougher second round over the most recent year, asking not just “is it better?” but “is it as good as this data allows?” (Random day-to-day variation is what analysts call “noise”.)
Results
Against the franchisor's formula
Average daily miss in dollars, once the forecast had 2+ years of history behind it
The forecast wins by roughly 5.7% overall, and by roughly 41% on holidays. The honest picture: on an ordinary day, a 4-week average is already a reasonable guess, so the two land close together. The real advantage is where averaging simply can't work: the franchisor's formula has no way to know a date is a holiday or a special day. An average can't know a date is different. This can.
Against simple averages, and against random variation
Over the last year, on a typical day the forecast misses by about 14%. The average miss is about 17.5%, and roughly one day in ten is off by more than 38%. Weekly totals are off by about 7%. Whether that's good depends on what you compare it with:
How far off the forecast was, as a percentage of what actually sold, with each day predicted using only earlier sales. *Hindsight floor: a forecaster that cheats by already knowing each weekday's true average for the year, a rough measure of the best this data allows.
Two things stand out, and I think both are worth saying plainly:
- The edge over a plain average is modest. About 8% smaller miss than the 4-week average, about 3% smaller than a 13-week average, and over the most recent six months a tie with the 13-week one. Its value isn't ordinary days. It's holidays, repeating dates and the seasons, handled automatically without anyone maintaining a list.
- Most of the remaining miss is just randomness. The same weekday at this restaurant swings 17% to 33% above or below its own average from one week to the next. Even a forecaster that cheated by knowing each weekday's true average would still miss by 17.7%, no better than my forecast's 17.5%. That leftover is day-to-day randomness that sales history can't reveal: a large order, a promotion, a quiet night. (Entering sales every day instead of weekly made no difference either: 17.5% vs 17.6%.)
Where the misses are
I assumed the big misses would be large orders: days that sold far more than expected. They weren't.
Each square is one day. Slumps are days that sold far less than forecast; spikes sold far more.
That reframed the search. The question wasn't “how do I catch big orders?” (the app already lets a manager add a known one-off order by hand) but “what makes days slow?” So I listed the worst slumps. Many sat right next to a public holiday.
Key finding: the days around a holiday
I knew from experience that the day after a public holiday is usually slow. But “usually slow” isn't something you can build on, so I tested it against two years of data. It held up, and it was more specific than I expected.
How far actual sales were from the forecast, on average (positive = sold more than forecast), across about 20 holidays per column over two years. The last grey column is a comparison group: 130 ordinary days, 8 to 14 days after a holiday. The drops on days 1 and 2 are too large to be a coincidence (roughly 3.5 standard errors from zero, a standard yardstick for “could this be luck?”). The day-6 bump isn't.
- The slump lasts exactly two days. About 18% below forecast the day after, about 13% below two days after. By the third day, nothing.
- The day before can run high. About 23% above forecast on average.
- It isn't “the holiday season”. The first ten days of January as a whole were only a few percent low, so one very slow day I'd flagged in early January was just a slow day.
The average hid the answer
My first attempt lumped every holiday together and barely helped. Then I split them by kind: a Monday long weekend versus a holiday that falls on any other day.
Compared with the same weekday in the four weeks on either side. The n = shows how many holidays each bar is based on (Monday ones · other ones). Positive = sold more than a normal day.
A holiday in the middle of the week breaks the ordering rhythm. A Monday long weekend mostly doesn't. Lumped together, the average blended a big effect and a nonexistent one into a blur. Once split, the evidence for the day before was about twice as strong.
Building it so it can't hurt
I added it as a final adjustment that touches only those days, instead of building it into the main forecast, for three reasons:
- The effect is proportional (a busy Friday loses more dollars than a quiet Tuesday), but the main forecast adjusts in fixed dollar amounts.
- My existing pattern-spotter requires every single occurrence to be unusual. That suits a one-day event like Halloween but can never fire for an effect made of twenty individually modest days.
- As a final step, it cannot change any other day.
It only switches on when the evidence is solid: at least eight past examples and a clearly real effect, and it deliberately under-corrects when it has few examples to learn from. With only a year or so of history it does nothing and waits. Each effect is measured against the same weekday in the four weeks on either side, which automatically accounts for the season and the direction the business was heading at the time.
All days365 days
Days next to a holiday33 days
Replaying the last year using only past data. Of the 11 forecasts the adjustment changed, 9 moved closer to what actually sold. The adjustment is built into the forecast and ships with the next app release.
The overall gain is small because only about one day in eleven is affected. But those are the days where staffing goes wrong: too few people on the busy day before a mid-week holiday, too many on the slow days after. And the safety check held: zero forecasts changed on days that aren't next to a holiday, which I tested rather than assumed.
What didn't work
Negative results are part of the evidence. These are the ideas I tested that didn't pan out:
- Telling the forecast to ignore one-off days. If a manager could flag a big catering day so it stopped skewing later forecasts, would accuracy improve? No: 17.6%, 17.5% and 17.8%, against 17.5% without it. The forecast already gives freak days little weight.
- Paydays. Nothing detectable on the 1st or the 15th.
- A month-end bump that looked real. The last days of each month ran about 9% above forecast, and it looked convincing. Tested honestly, using only earlier data, it improved nothing. I'd checked a dozen calendar patterns at once, so one looking real by pure chance is exactly what you'd expect.
- Weather. No measurable effect on this restaurant's sales.
Lessons learned
- 1. Judge a forecast against simple alternatives and against pure randomness, not against perfection. A 17.5% miss sounds mediocre until you learn that even a forecaster that secretly knew each weekday's true average would miss by 17.7%.
- 2. Ask the person who knows the business, then test what they say. “The day after a holiday is usually slow” became the most useful finding of the project, but only after it was checked against two years of data and refined: it lasts two days, it isn't the holiday season, and it depends on the kind of holiday.
- 3. Averages can hide what's really going on. Lumping Monday long weekends in with mid-week holidays blurred a strong effect into a weak one. Split the data by a reason you can name before concluding an effect is small.
- 4. A pattern that looks real is only a hypothesis. The month-end bump looked convincing on the data I used to find it and vanished on data it hadn't seen. The holiday effect held up across years and across holidays, which is why it shipped and the other didn't.
- 5. Build a safety check you can prove. “Zero other forecasts changed” was verified by an automated test, not hoped for.
- 6. Check your own claims against what the code really does. The forecast labels each prediction low, medium or high confidence, and it's tempting to read that as a statistical margin of error. It isn't: it only reflects how many days of history exist. While writing this up, I found that the note in the code describing that label had drifted from what the code actually did, citing a threshold from a file that no longer exists, with a number that didn't match. The code was right; the note wasn't. I fixed it on the spot, and it's a habit I try to apply everywhere.
Limitations and next steps
- One restaurant. The holiday adjustment rests on about a dozen mid-week holidays: moderate evidence, not proof, which is why it waits for enough history and plays it safe when it's unsure.
- Not yet compared with ready-made forecasting tools. I've compared it with simple averages and the franchisor's formula, but not yet with popular off-the-shelf methods (Prophet, exponential smoothing, gradient boosting). That's next.
- Most of the remaining daily miss is randomness that sales history can't explain. Closing it would take information the history doesn't contain, such as known large orders or a promotion calendar.
- A holiday's own adjustment is a fixed dollar amount, so it can under- or over-correct when the holiday lands on a different weekday than usual. (The newer around-holiday adjustment is proportional, which avoids this.)
- Special days are only recognized on fixed calendar dates. A pattern tied to a moving date, or to something other than the calendar, can't be captured.
- A manager's one-off adjustment (a known large order) never enters the history the forecast learns from. It's added after the forecast runs, so it can't leak into next year's numbers.
Next: a comparison with ready-made forecasting tools, a public, reproducible version of the evaluation using made-up data, and more restaurants to test the holiday effect on.
Hiring, or building something similar?
I'm a full-stack developer with a computer science degree and over a decade of analytics-heavy product work, and I'm open to full-stack, backend and data roles as well as project work.