Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
82872fa
Update README.md
esther-ng Sep 6, 2016
7c2b3c7
Set up basic structure and specs for baseline
esther-ng Sep 6, 2016
11e5c97
Remove extraneous requires and files
esther-ng Sep 6, 2016
d3e2fb5
Merge branch 'master' of https://github.com/esther-ng/FarMar
esther-ng Sep 6, 2016
77696f9
Completed Market all and find class methods and associated specs
esther-ng Sep 6, 2016
2064480
Completed Vendor all and find class methods and associated specs
esther-ng Sep 6, 2016
4539873
Completed Product all and find class methods and associated specs
esther-ng Sep 6, 2016
c9e0c83
Completed Sale all and find class methods and associated specs
esther-ng Sep 6, 2016
fcbecb3
Added Market #vendors instance method and specs
esther-ng Sep 6, 2016
a7f6fab
WIP, pick up at Vendor Methods products
esther-ng Sep 7, 2016
994092d
Completed additional Vendor methods and specs
esther-ng Sep 7, 2016
3244056
Completed additional Product methods and specs
esther-ng Sep 7, 2016
31fd12d
Resolved DateTime issue but need to complete final spec to confirm co…
esther-ng Sep 7, 2016
aa2f105
Completed additional Sale methods
esther-ng Sep 8, 2016
515e9cd
Refactored specs with less instantiation
esther-ng Sep 8, 2016
3ece880
Added Market class methods find_by_name and find_all_by_state
esther-ng Sep 8, 2016
48796eb
Completed optional market methods up to preferred_vendor, need to che…
esther-ng Sep 8, 2016
2e4b0fc
Added optional Market methods but test efficiency is very slow
esther-ng Sep 9, 2016
49f1b7c
Missing Vendor most_revenue, most_items(n_ and revenue(date) methods
esther-ng Sep 9, 2016
7febba2
Still couldn't get optional Vendor methods or speed up tests
esther-ng Sep 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id
### Baseline
#### Project Setup
1. You'll be working as an individual on this project.
1. Fork the Ada-C6 repo to your Github account.
1. Clone your fork to your projects directory, and `cd` into the cloned repo.
1. Create a _gemset_ for your project
1. Fork the Ada-C6 repo to your Github account. DONE
1. Clone your fork to your projects directory, and `cd` into the cloned repo. DONE
1. Create a _gemset_ for your project IGNORE
1. `$ echo 2.3.0 > .ruby-version`
1. `$ echo farmar > .ruby-gemset`
1. `$ cd .`
1. Install necessary gems via Terminal:
1. Install necessary gems via Terminal: DONE
- `$ gem install minitest-reporters`
- `$ gem install simplecov`

#### Baseline Requirements
- Create a class for each of the data types listed above. Each class should be a part of the `FarMar` module.
- You should be able to create instances of these classes that know about their associated data file.
- Create your `far_mar.rb` file which will bring together all classes created in the previous step.
- Complete the boilerplate necessary for testing. You should be able to `$ rake` from the project root to run your specs. Have at least one spec to verify this setup before submitting your baseline.
- Create a class for each of the data types listed above. Each class should be a part of the `FarMar` module. DONE
- You should be able to create instances of these classes that know about their associated data file. DONE (specific CSV to be read in)
- Create your `far_mar.rb` file which will bring together all classes created in the previous step. DONE
- Complete the boilerplate necessary for testing. You should be able to `$ rake` from the project root to run your specs. Have at least one spec to verify this setup before submitting your baseline. DONE
- **Once you have completed your baseline, you must submit a pull-request and get it approved by an instructor.**

## Primary Requirements
Expand Down Expand Up @@ -154,4 +154,4 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id

#### Try some inheritance or some composition
- __Inheritance:__ Create a new _class_ that defines the shared/duplicated methods (i.e., `find`, `all`). Update your data classes to _inherit_ this _class_ .
- __Composition with a Mixin:__ Create a new _module_ that defines the duplicated methods (i.e., `find`, `all`). Update your data classes to _mixin_ this _module_.
- __Composition with a Mixin:__ Create a new _module_ that defines the duplicated methods (i.e., `find`, `all`). Update your data classes to _mixin_ this _module_.
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
9 changes: 9 additions & 0 deletions far_mar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'csv'
require 'date'

module FarMar; end

require_relative 'lib/farmar_market'
require_relative 'lib/farmar_vendor'
require_relative 'lib/farmar_product'
require_relative 'lib/farmar_sale'
111 changes: 111 additions & 0 deletions lib/farmar_market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
module FarMar
class Market
attr_reader :id, :name, :state

def initialize(id, name, address, city, county, state, zip)
@id = id.to_i
@name = name
@address = address
@city = city
@county = county
@state = state
@zip = zip
end

def self.all
all_markets = []
CSV.read('support/markets.csv').each do |line|
all_markets << FarMar::Market.new(line[0], line[1], line[2], line[3], line[4], line[5], line[6])
end
return all_markets
end

def self.find(id)
self.all.find do |market|
market.id == id
end
end


def self.find_by_name(name)
self.all.find do |market|
market.name.upcase == name.upcase
end
end

# def self.find_all_by_state(state)
# state_markets = self.all.select do |market|
# market.state.upcase == state.upcase
# end
# return state_markets
# end

def vendors
FarMar::Vendor.all.select do |vendor|
vendor.market_id == @id
end
end

def self.search(search_term)
all_markets = self.all
all_vendors = FarMar::Vendor.all

matching_market_names = all_markets.select do |market|
market.name.upcase.include?(search_term.upcase)
end

# matching_vendor_name_markets = [] stalls in terminal
# all_vendors.each do |vendor|
# if vendor.name.upcase.include?(search_term.upcase)
# matching_vendor_name_markets << FarMar::Market.find(vendor.market_id)
# end
# end
matching_vendors = all_vendors.select do |vendor|
vendor.name.upcase.include?(search_term.upcase)
end

matching_vendor_name_markets = matching_vendors.map do |vendor|
FarMar::Market.find(vendor.market_id)
end

matching_markets = matching_market_names + matching_vendor_name_markets

return matching_markets.uniq
end

def products
market_products = []
vendors.each do |vendor|
market_products += vendor.products
end
return market_products
end

def preferred_vendor(date = nil) # use default/optional date?
if date == nil
preferred_vendor = vendors.max_by do |vendor|
vendor.revenue
end
else
preferred_vendor = vendors.max_by do |vendor|
vendor.revenue(date)
end
end
return preferred_vendor
end

def worst_vendor(date = nil)
if date == nil
preferred_vendor = vendors.min_by do |vendor|
vendor.revenue
end
else
preferred_vendor = vendors.min_by do |vendor|
vendor.revenue(date)
end
end
return preferred_vendor
end

end
end
60 changes: 60 additions & 0 deletions lib/farmar_product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module FarMar
class Product
attr_reader :id, :name, :vendor_id

def initialize(id, name, vendor_id)
@id = id.to_i
@name = name
@vendor_id = vendor_id.to_i
end

def self.all
all_products = []
CSV.read('support/products.csv').each do |line|
all_products << FarMar::Product.new(line[0], line[1], line[2])
end
return all_products
end

def self.find(id)
self.all.find do |product|
product.id == id
end
end

# def self.find_by_name(name)
# self.all.find do |product|
# product.name.upcase == name.upcase
# end
# end

def vendor
FarMar::Vendor.find(@vendor_id)
end

def sales
product_sales = FarMar::Sale.all.select do |sale|
sale.product_id == @id
end
return product_sales
end

def number_of_sales
sales.length
end

def self.by_vendor(vendor_id)
vendor_products = self.all.select do |product|
product.vendor_id == vendor_id
end
return vendor_products
end

# def self.most_revenue(n)
# all_products = self.all.sort_by do |product|
# product.
#
# end

end
end
44 changes: 44 additions & 0 deletions lib/farmar_sale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module FarMar
class Sale

attr_reader :id, :amount, :vendor_id, :product_id, :purchase_time

def initialize(id, amount, purchase_time, vendor_id, product_id)
@id = id.to_i
@amount = amount.to_i
@purchase_time = DateTime.parse(purchase_time.to_s)
@vendor_id = vendor_id.to_i
@product_id = product_id.to_i
end

def self.all
all_sales = []
CSV.read('support/sales.csv').each do |line|
all_sales << FarMar::Sale.new(line[0], line[1], line[2], line[3], line[4])
end
return all_sales
end

def self.find(id)
self.all.find do |sale|
sale.id == id
end
end

def vendor
FarMar::Vendor.find(@vendor_id)
end

def product
FarMar::Product.find(@product_id)
end

def self.between(beginning_time, end_time)
sales_window = self.all.select do |sale|
sale.purchase_time > beginning_time && sale.purchase_time < end_time
end
return sales_window
end

end
end
92 changes: 92 additions & 0 deletions lib/farmar_vendor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module FarMar
class Vendor
attr_reader :id, :name, :market_id

def initialize(id, name, employee_count, market_id)
@id = id.to_i
@name = name
@employee_count = employee_count.to_i
@market_id = market_id.to_i
end

def self.all
all_vendors = []
CSV.read('support/vendors.csv').each do |line|
all_vendors << FarMar::Vendor.new(line[0], line[1], line[2], line[3])
end
return all_vendors
end

def self.find(id)
all_vendors = self.all
all_vendors.each do |vendor|
if vendor.id == id
return vendor
end
end
end

# def self.find_by_name(name)
# self.all.each do |vendor|
# vendor.name.upcase == name.upcase
# end
# end

def market
FarMar::Market.find(@market_id)
end

def products
FarMar::Product.all.select do |product|
product.vendor_id == @id
end
end

def sales
FarMar::Sale.all.select do |sale|
sale.vendor_id == @id
end
end

def revenue(date = nil)
vendor_sales = sales
if date != nil
beginning_time = DateTime.new(date.year, date.month, date.day, 0, 0, 0, '-8')
end_time = DateTime.new(date.year, date.month, date.day, 23, 59, 59, '-8')

vendor_sales_by_date = vendor_sales.select do |sale|
sale.purchase_time > beginning_time && sale.purchase_time < end_time
end

vendor_sales = vendor_sales_by_date
end

revenue = 0
vendor_sales.each do |sale|
revenue += sale.amount
end

# revenue_total = revenue_array.reduce(:+)

if revenue == nil
return 0
else
return revenue
end
end

# def self.most_revenue(n)
# vendors_by_revenue = self.all.sort_by do |vendor|
# vendor.revenue
# end
# return vendors_by_revenue[-n..-1]
# end

def self.by_market(market_id)
self.all.select do |vendor|
vendor.market_id == market_id
end
end

end
end
Loading