Skip to content
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

get_available_seats #5

Merged
merged 1 commit into from Oct 5, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -374,36 +374,49 @@ def halt_with_error(status = 500, message = 'unknown')
cast: false,
).first

premium_avail_seats = get_available_seats(train, from_station, to_station, 'premium', false)
premium_smoke_avail_seats = get_available_seats(train, from_station, to_station, 'premium', true)
reserved_avail_seats = get_available_seats(train, from_station, to_station, 'reserved', false)
reserved_smoke_avail_seats = get_available_seats(train, from_station, to_station, 'reserved', true)
premium_avail_seats = 0
premium_smoke_avail_seats = 0
reserved_avail_seats = 0
reserved_smoke_avail_seats = 0

all_available_seats = get_available_seats(train, from_station, to_station).each do |seat|
case
when seat[:seat_class] == "premium" && !seat[:is_smoking_seat]
premium_avail_seats += 1
when seat[:seat_class] == "premium" && seat[:is_smoking_seat]
premium_smoke_avail_seats += 1
when seat[:seat_class] == "reserved" && !seat[:is_smoking_seat]
reserved_avail_seats += 1
when seat[:seat_class] == "reserved" && seat[:is_smoking_seat]
reserved_smoke_avail_seats += 1
end
end

premium_avail = ''
if premium_avail_seats.length.zero?
if premium_avail_seats.zero?
premium_avail = '×'
elsif premium_avail_seats.length < 10
elsif premium_avail_seats < 10
premium_avail = ''
end

premium_smoke_avail = ''
if premium_smoke_avail_seats.length.zero?
if premium_smoke_avail_seats.zero?
premium_smoke_avail = '×'
elsif premium_smoke_avail_seats.length < 10
elsif premium_smoke_avail_seats < 10
premium_smoke_avail = ''
end

reserved_avail = ''
if reserved_avail_seats.length.zero?
if reserved_avail_seats.zero?
reserved_avail = '×'
elsif reserved_avail_seats.length < 10
elsif reserved_avail_seats < 10
reserved_avail = ''
end

reserved_smoke_avail = ''
if reserved_smoke_avail_seats.length.zero?
if reserved_smoke_avail_seats.zero?
reserved_smoke_avail = '×'
elsif reserved_smoke_avail_seats.length < 10
elsif reserved_smoke_avail_seats < 10
reserved_smoke_avail = ''
end

@@ -28,15 +28,13 @@ def get_usable_train_class_list(from_station, to_station)
usable.values
end

def get_available_seats(train, from_station, to_station, seat_class, is_smoking_seat)
def get_available_seats(train, from_station, to_station)
# 指定種別の空き座席を返す

# 全ての座席を取得する
seat_list = db.xquery(
'SELECT * FROM `seat_master` WHERE `train_class` = ? AND `seat_class` = ? AND `is_smoking_seat` = ?',
train[:train_class],
seat_class,
is_smoking_seat,
'SELECT * FROM `seat_master` WHERE `train_class` = ?',
train[:train_class]
)

available_seat_map = {}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.