Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Planet Express Reporting
#Homework - Day 4
#NORMAL MODE
#Good news Rubyists!
#We have a week of records tracking what we shipped at Planet Express.
#I need you to answer a few questions for Hermes.
#How much money did we make this week?
require 'csv'
week_total = []
CSV.foreach("planet_express_logs.csv", headers: true) do |row|
week_total << row[" Money we made"]
end
puts week_total.collect{|num| num.to_i}.inject(:+)
#How much of a bonus did each employee get? (bonuses are paid to employees who pilot the Planet Express)
#Different employees have favorite destinations they always pilot to
#Fry - pilots to Earth (because he isn’t allowed into space)
#Amy - pilots to Mars (so she can visit her family)
#Bender - pilots to Uranus (teeheee…)
#Leela - pilots everywhere else because she is the only responsible one
fry_bonus = 0
amy_bonus = 0
bender_bonus = 0
leela_bonus = 0
CSV.foreach("planet_express_logs.csv", headers: true) do |item|
if item["Destination"] == "Earth"
fry_bonus = fry_bonus + item[" Money we made"].to_i / 10
elsif item["Destination"] == "Mars"
amy_bonus = amy_bonus + item[" Money we made"].to_i / 10
elsif item["Destination"] == "Uranus"
bender_bonus = bender_bonus + item[" Money we made"].to_i / 10
else
leela_bonus = leela_bonus + item[" Money we made"].to_i / 10
end
end
puts fry_bonus
puts amy_bonus
puts bender_bonus
puts leela_bonus
#How many trips did each employee pilot?
fry_trips = 0
amy_trips = 0
bender_trips = 0
leela_trips = 0
CSV.foreach("planet_express_logs.csv", headers: true) do |item|
if item["Destination"] == "Earth"
fry_trips = fry_trips + 1
elsif item["Destination"] == "Mars"
amy_trips = amy_trips + 1
elsif item["Destination"] == "Uranus"
bender_trips = bender_trips + 1
else
leela_trips = leela_trips + 1
end
end
puts fry_trips
puts amy_trips
puts bender_trips
puts leela_trips
#Define and use your Delivery class to represent each shipment
require 'csv'
class Delivery
attr_accessor :place,:what,:amount,:dollaz,:pilot
def initialize(place,what,amount,dollaz)
self.place = place
self.what = what
self.amount = amount
self.dollaz = dollaz
if place == "Earth"
self.pilot = "Fry"
elsif place == "Mars"
self.pilot = "Amy"
elsif place == "Uranus"
self.pilot = "Bender"
else
self.pilot = "Leela"
end
end
end
px = []
CSV.foreach("planet_express_logs.csv", headers: true) do |x|
px << Delivery.new(x["Destination"], x[" What got shipped"], x[" Number of crates"], x[" Money we made"])
end
puts px
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.