forked from AdaGold/hotel
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Victoria Garcia - Ampers - Hotel -updated #28
Open
Lasiorhine
wants to merge
51
commits into
Ada-C9:master
Choose a base branch
from
Lasiorhine:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
35f4197
Initial batch of documents, including lib and spec files for hotel, r…
Lasiorhine 95d867c
Tests for Reservation class written and failing/error-ing in the desi…
Lasiorhine 8ec35b4
within reservation, assign_id method is working, even though it invol…
Lasiorhine b4b6585
Reseration Class is passing all tests, except for the 'calculate_pric…
Lasiorhine 73776ca
After consideration, price calculation methods added to reservation c…
Lasiorhine 4349a69
total calculation method in Reservation is now passing all tests.
Lasiorhine bc418d2
A bunch of tests stubbed for the Room class.
Lasiorhine 0b24d31
More tests stubbed for the Room class. It is a stubby kind of day.
Lasiorhine ac02b87
Some more test-ish stuff for Room, including variables that hold Date…
Lasiorhine c5d831e
got the first bit of my crazy-ass date system to start throwing a rea…
Lasiorhine 43f6209
My stars and garters but all the freaking tests for the freaking date…
Lasiorhine 77ea867
Beginning of the room-level lookup system now underway.
Lasiorhine 3c5f7ee
A few minor comments in the Reservation class and spec. Got my crazy…
Lasiorhine 52baa85
basic functionality for 'add reservation' working in room, with tests…
Lasiorhine 52cdb0c
tests for conflict-checking mechanism in room are failing in the desi…
Lasiorhine fa8d67f
a whole bunch of the tests for the conflict-checking machinery are no…
Lasiorhine b0e3aa3
closer to functional with the conflict-checking mechanism. One more …
Lasiorhine aaf782f
all tests passing for the conflict-checking system in Room. Also, ad…
Lasiorhine 3a17352
tests for date conflict resolution helper method written and failing …
Lasiorhine 27704ae
all tests for conflict resolution helper method are passing.
Lasiorhine 0658e5e
all the conflict-oriented machinery for Room is now passing all its t…
Lasiorhine 93b0463
tests for reporting method written and failing/erroring appropriately.
Lasiorhine 83c8cb6
last functionality added to Room class. Tests passing.
Lasiorhine 05e25d0
wrote a couple more tests for Room. all functionality for Room, inclu…
Lasiorhine 661cb71
stubbed a whole lot of stuff for FrontDesk.
Lasiorhine 94d4064
some changes to the initialize method for room, which I fought with a…
Lasiorhine 5a6e28d
Lots of stuff stubbed, test-wise, in Front Desk
Lasiorhine 8fc9eed
first few tests passing for FrontDesk
Lasiorhine 47b5909
report_all_rooms is passing its tests.
Lasiorhine 46daa3b
Tests written and failing in the desired way for the availability che…
Lasiorhine bab282a
the room availability lookup procedure in FrontDesk is passing all it…
Lasiorhine 7b1b62c
tests written and failing in the desired way for the front desk's per…
Lasiorhine a79308d
initial tests for per-day reservation report in FrontDesk are passing…
Lasiorhine 93595f8
all tests for the FrontDesk's reservation lookup system are passing, …
Lasiorhine 03913cb
the method for generating a list of available rooms for a given date …
Lasiorhine 864dc7f
the available room-reporting and -choosing methods for FrontDesk are …
Lasiorhine fb5fe9f
tests written for FrontDesk's reservation creation method, and failin…
Lasiorhine a79376a
helper method for the reservation addint now in place and passing tests.
Lasiorhine 5201052
another small helper method for the reservation creation mechanism in…
Lasiorhine f1cafbf
fixed up some stuff having to do with reservation price calculation.
Lasiorhine 6c23ed1
tests written for FrontDesk's reservation price calculation method, a…
Lasiorhine 306b345
last of the pre-Wave 3 FrontDesk methods are now passing all tests. t…
Lasiorhine 8ba2485
room identificaiton method for the block stuff is now passing all tests.
Lasiorhine 7e63aa6
a whole bunch of machinery for hte Block Resrvation stuff is now func…
Lasiorhine cf17877
the block set-aside mechanism in FrontDesk is passing initial tests.
Lasiorhine 620f317
The availability-checking mechanisms for within the blocks is now wor…
Lasiorhine 4c1f2de
This is as far as I'm going. One method shy of finishing Wave 3.
Lasiorhine 554ac8b
All prompts answered.
Lasiorhine b6dd3c5
Added to the design-activity document, and while doing so, made a few…
Lasiorhine 59dc145
made changes to room availability report-generating mechanisms in Roo…
Lasiorhine fa4d9e3
Modifications to the room availability report generation mechanism in…
Lasiorhine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs = ["lib"] | ||
t.warning = true | ||
t.test_files = FileList['specs/*_spec.rb'] | ||
end | ||
|
||
task default: :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
|
||
module Hotel | ||
class BlockRoom < Hotel::Room | ||
|
||
attr_reader :room_number, :base_resv_price, :min_res_sec, :rate_with_discount, :block_id, :block_start, :block_end | ||
|
||
attr_accessor :discount, :reservations, :dates_unavailable | ||
|
||
|
||
def initialize(room_number, block_id, discount, block_start, block_end) | ||
|
||
super(room_number) | ||
|
||
@room_number = room_number.concat("-B") | ||
@block_id = block_id | ||
@block_start = DateTime.parse(block_start) | ||
@block_end = DateTime.parse(block_end) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
require 'date' | ||
require 'pry' | ||
|
||
require_relative 'reservation' | ||
require_relative 'room' | ||
|
||
module Hotel | ||
class FrontDesk | ||
|
||
attr_accessor :rooms, :blocks | ||
|
||
TOTAL_ROOMS_IN_FACILITY = 20 | ||
@@last_block_base = 100 | ||
|
||
def initialize | ||
|
||
@rooms = generate_rooms | ||
@blocks = [] | ||
|
||
end | ||
|
||
def generate_rooms | ||
room_array = [] | ||
for i in 1 .. TOTAL_ROOMS_IN_FACILITY | ||
room_number = i.to_s | ||
new_room = Hotel::Room.new(room_number) | ||
room_array << new_room | ||
end | ||
return room_array | ||
end | ||
|
||
def report_all_rooms | ||
all_rooms = @rooms | ||
return all_rooms | ||
end | ||
|
||
def find_all_reservations_for_date(date) | ||
query_date = DateTime.parse(date).jd.to_s | ||
overall_report = {} | ||
@rooms.each do |room| | ||
per_room_report = nil | ||
per_room_report = room.report_reservations_for_day(query_date) | ||
unless per_room_report == nil | ||
resv_id_array = [] | ||
per_room_report.each {|reservation| resv_id_array << reservation.id } | ||
per_room_report = {room.room_number => resv_id_array} | ||
overall_report.merge!(per_room_report) | ||
end | ||
end | ||
return overall_report | ||
end | ||
|
||
def report_all_available_rooms(start_dt, end_dt, room_set) | ||
imaginary_reservation = Hotel::Reservation.new(start_dt, end_dt) | ||
all_available_rooms = [] | ||
room_set.each do |room| | ||
available_room = nil | ||
availability = room.can_accept_reservation?(imaginary_reservation) | ||
if availability[:accept] == true | ||
available_room = room | ||
end | ||
unless available_room == nil | ||
available_room = available_room.room_number | ||
all_available_rooms << available_room | ||
end | ||
end | ||
return all_available_rooms | ||
end | ||
|
||
def find_available_room(start_d, end_d, room_set) | ||
|
||
room_to_assign = nil | ||
rooms_available = report_all_available_rooms(start_d, end_d, room_set) | ||
unless rooms_available.empty? | ||
rooms_by_int = rooms_available.map{ |rm_numb| rm_numb.to_i } | ||
rooms_by_int.sort! | ||
room_to_assign = rooms_by_int[0].to_s | ||
end | ||
return room_to_assign | ||
end | ||
|
||
def look_up_per_night_price_for_room(query_room_numb) | ||
target_room = @rooms.find {|room| room.room_number == query_room_numb} | ||
target_price = target_room.rate_with_discount | ||
end | ||
|
||
def locate_room_by_id(query_rm_numb) | ||
target_room = @rooms.find {|room| room.room_number == query_rm_numb} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is duplicated in the method above, so why not just use this instead of duplicating? |
||
return target_room | ||
end | ||
|
||
def create_reservation_basic(start_date, end_date, room_set) | ||
room_numb_for_new_res = find_available_room(start_date, end_date, room_set) | ||
if room_numb_for_new_res.nil? | ||
raise StandardError.new ("Alas, no rooms are available for this reservation.") | ||
else | ||
new_reservation = Hotel::Reservation.new(start_date, end_date) | ||
end | ||
new_reservation.hotel_room_id = room_numb_for_new_res | ||
|
||
new_reservation.per_night_price = look_up_per_night_price_for_room(room_numb_for_new_res) | ||
|
||
room_instance_for_res = locate_room_by_id(room_numb_for_new_res) | ||
|
||
room_instance_for_res.add_reservation(new_reservation) | ||
|
||
return new_reservation | ||
end | ||
|
||
|
||
|
||
|
||
def find_reservation_price(query_id) | ||
|
||
target_reservation = nil | ||
price_of_target = nil | ||
@rooms.each do |room| | ||
unless target_reservation != nil | ||
room.reservations.each do |reservation| | ||
if reservation.id == query_id | ||
target_reservation = reservation | ||
price_of_target = target_reservation.total_reservation_cost | ||
end | ||
end | ||
end | ||
end | ||
return price_of_target | ||
end | ||
|
||
|
||
def check_block_feasibility(st_dt, end_dt,room_set, block_size) | ||
block_y_or_n = nil | ||
elig_for_block = report_all_available_rooms(st_dt, end_dt, room_set) | ||
if elig_for_block.length >= block_size | ||
block_y_or_n = {:yes => elig_for_block} | ||
else | ||
block_y_or_n = {:no => []} | ||
end | ||
return block_y_or_n | ||
end | ||
|
||
def create_placeholder_res(start_date, end_date, room_id, block_id) | ||
|
||
reservation_for_block = Hotel::Reservation.new(start_date, end_date) | ||
|
||
reservation_for_block.hotel_room_id = room_id | ||
reservation_for_block.block_set_aside = true | ||
reservation_for_block.block_id = block_id | ||
|
||
return reservation_for_block | ||
end | ||
|
||
def create_room_block(st_date, end_date, block_size, room_set, block_discount) | ||
feasability_result = check_block_feasibility(st_date, end_date, room_set, block_size) | ||
if feasability_result.keys.include?(:no) | ||
raise StandardError.new("There are not enough available rooms to create this block") | ||
else | ||
block_id = @@last_block_base.to_s | ||
@@last_block_base += 1 | ||
rooms_available_for_block = feasability_result[:yes] | ||
room_surplus = rooms_available_for_block.length - block_size | ||
as_many_rooms_as_needed = rooms_available_for_block.drop(room_surplus) | ||
rooms_reserved_in_block = [] | ||
as_many_rooms_as_needed.each do |room_id| | ||
room_for_block = locate_room_by_id(room_id) | ||
placeholder_res = create_placeholder_res(st_date, end_date, room_id, block_id) | ||
room_for_block.add_reservation(placeholder_res) | ||
block_availability_object = Hotel::BlockRoom.new(room_id, block_id, block_discount, st_date, end_date) | ||
block_availability_object.discount = block_discount | ||
rooms_reserved_in_block << block_availability_object | ||
end | ||
block = {block_id.to_sym => rooms_reserved_in_block} | ||
@blocks << block | ||
end | ||
return block | ||
end | ||
|
||
def check_availability_within_block(start_date, end_date, block_id) | ||
block_key = block_id.to_sym | ||
target_block = @blocks.find {|element| element.has_key?(block_key)} | ||
available_block_rooms = report_all_available_rooms(start_date, end_date, target_block.values[0]) | ||
return available_block_rooms | ||
end | ||
|
||
# RIGHT HERE IS WHERE I RAN OUT OF GAS. | ||
|
||
#I ALMOST GOT THROGUH WAVE 3, but at 6:00 am, I just had nothing left. | ||
|
||
|
||
# def create_reservation_within_block(start_date, end_date, block_id) | ||
# rooms_available = check_availability_within_block(start_date, end_date, block_id) | ||
# room_instances_for_reservation = rooms_available.map {|id| @blocks.find } | ||
# | ||
# | ||
# new_block_reservation = create_reservation_basic(start_date, end_date, rooms_available) | ||
# return new_block_reservation | ||
# end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
require 'date' | ||
require 'pry' | ||
|
||
# require_relative 'room' | ||
# require_relative 'front_desk' | ||
|
||
|
||
module Hotel | ||
class Reservation | ||
attr_accessor :start_date, :end_date, :hotel_room_id, :days_booked_am_and_pm, :per_night_price, :block_set_aside, :block_id | ||
attr_reader :id, :total_nights, :total_reservation_cost | ||
|
||
@@last_id_base = 0 | ||
|
||
# The constant below, MIN_RES_IN_SEC, is the length of the minimum reservation, in seconds. This figure was arrived at by calculating the number of seconds between an early-but-common check-out time (10:00 am) and the change of date at midnight. The putative customer could, of course, change this to whatever they wanted. | ||
MIN_RES_IN_SEC = 36000 | ||
|
||
def initialize(start_date, end_date) | ||
@id = assign_id | ||
@start_date = DateTime.parse(start_date) | ||
@end_date = DateTime.parse(end_date) | ||
@hotel_room_id = nil | ||
@days_booked_am_and_pm = days_with_am_and_pm_occupation | ||
@total_nights = calculate_total_nights | ||
@per_night_price = 200.00 # Assigning this as a default, but there is a mechanism for overwriting during reservation creation in FrontDesk. | ||
@total_reservation_cost = calculate_reservation_price | ||
@block_set_aside = false | ||
@block_id = nil | ||
|
||
#THIS IS GOOD, BUT IT BORKS YOUR ABILITY TO TEST CERTAIN THINGS. MAYBE PUT THE VALIDATION MEASURE FOR START-DATES IN THE PAST IN FrontDesk??? OR RESCUE?? | ||
## Commenting out the req about not starting reservations in the past--- for now. | ||
|
||
## GOING TO HAVE THIS LOOK UP THE MIN_RES_IN_SEC on the room to which it is being assigned, using the room numer ID. YASS. | ||
if (@end_date.to_time.to_i - @start_date.to_time.to_i) < MIN_RES_IN_SEC #|| @start_date.to_time.to_i < Time.now.to_i | ||
raise StandardError.new("A reservation's end date must come after its start date, and it must be at least one night long.") | ||
end | ||
end | ||
|
||
def assign_id | ||
new_id_base = (@@last_id_base += 1).to_s | ||
zeroes_needed = 8 - new_id_base.length | ||
leading_zero_array = (1..zeroes_needed).collect {"0"} | ||
new_id = leading_zero_array.join.concat(new_id_base) | ||
return new_id | ||
end | ||
|
||
def calculate_total_nights | ||
(@end_date.to_date - @start_date.to_date).to_i | ||
end | ||
|
||
def days_with_am_and_pm_occupation | ||
# This creates a hash of hashes for the dates within a reservation. For | ||
# each date, the key of the base hash is the date in Julian. The value of | ||
# that hash is a second hash with two key-value pairs, the key of the | ||
# first being :am, and the key of the second being :pm. The values of these | ||
# can be either true or false. | ||
|
||
# For a date in the middle of the hash, the :am and :pm keys will both have | ||
# the value true. For the start date of a reservation, the :am key will | ||
# have the value false, and the :pm key will have the value true. | ||
# The end-date will have a value of true for its :am key and false for its :pm key. | ||
first_key = @start_date.jd.to_s | ||
last_key = @end_date.jd.to_s | ||
start_and_end_days = { | ||
first_key => { | ||
:am => false, | ||
:pm => true | ||
}, | ||
last_key => { | ||
:am => true, | ||
:pm => false | ||
} | ||
} | ||
intervening_span = (last_key.to_i - first_key.to_i - 1) | ||
mid_keys_array = [] | ||
while intervening_span > 0 | ||
mid_key = (first_key.to_i + intervening_span).to_s | ||
mid_keys_array << mid_key | ||
intervening_span -= 1 | ||
end | ||
full_days_in_use = {} | ||
unless mid_keys_array.empty? | ||
full_days_in_use = mid_keys_array.map {|day| [day, {:am => true, :pm => true}] } | ||
end | ||
all_days_in_use = start_and_end_days.merge(full_days_in_use.to_h) | ||
end | ||
|
||
def calculate_reservation_price | ||
(@total_nights * @per_night_price).round(2) | ||
end | ||
end | ||
end |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you need a separate method for this rather than using an
attr
?