Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I added a few tests with a minimal setup (testing with real db, but not involving Flask). I noticed that there are no tests provided and that candidates are not expected to write tests of any sort, but filling up solutions without testing it on the way is not my nature of coding. Especially when working with APIs of libraries and frameworks I want to see changes working. Also the second question requires quite a few steps and a number of data transformations to make which I would never approach with a "coding it first and hoping it works" way .)
I had to slightly change the existing solution to make it work first (see 57c1878, includes initial test for original occupancy calculation without room blocking)
Regarding Q1, I was tempted to add blocked rooms as additional
row_type
ofBookings
model and see how that looks (see 00bfaaf) .) but then made a separate model for storing it with number of blocked rooms per reservation date time (task description asks for a new model). There is a third option of storing blocks also with date range but that would make the entrypoint a bit more complex not saving much of db space and work (normally I would consult product to see what is the usual use of blocking rooms and implement it accordingly).I can see some room for improvements such as filling
occupancy_per_day
andrevenue_per_day
in Q2 together in one for loop, they're in separate loops right now as I added the occupancy and revenue curves functionalities one by one (see the commits flow).Having some tests, fun with optimising the selects or even trying the pure SQL can start ;) (I would still prefer python solution as it would be always more readable than SQL; readability counts)
On the way I was placing TODOs with comments of what I would focus on later if this is
a real live task, you can ignore them... .)