From 14548da10c04f5add3bde986464516db223c254a Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Tue, 31 May 2022 15:25:23 -0600 Subject: [PATCH 001/131] Add Merchant, Sales_Engine classes, tests --- lib/merchant.rb | 9 +++++++++ lib/sales_engine.rb | 14 ++++++++++++++ test/merchant_spec.rb | 14 ++++++++++++++ test/sales_engine_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 lib/merchant.rb create mode 100644 lib/sales_engine.rb create mode 100644 test/merchant_spec.rb create mode 100644 test/sales_engine_spec.rb diff --git a/lib/merchant.rb b/lib/merchant.rb new file mode 100644 index 0000000000..4690561fb9 --- /dev/null +++ b/lib/merchant.rb @@ -0,0 +1,9 @@ +class Merchant + attr_reader :id, :name + + def initialize(data) + @id = data[:id] + @name = data[:name] + end + +end diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb new file mode 100644 index 0000000000..11d95f7f3c --- /dev/null +++ b/lib/sales_engine.rb @@ -0,0 +1,14 @@ +class SalesEngine + attr_reader :item_collection, :merchant_collection + + def initialize(items_path, merchants_path) + @item_collection = ItemCollection.new(items_path) + @merchant_collection = MerchantCollection.new(merchants_path) + end + + def self.from_csv(data) + # binding.pry + return SalesEngine.new(data[:items], data[:merchants]) + end + +end diff --git a/test/merchant_spec.rb b/test/merchant_spec.rb new file mode 100644 index 0000000000..f4232efe7f --- /dev/null +++ b/test/merchant_spec.rb @@ -0,0 +1,14 @@ +require './lib/merchant' + +RSpec.describe Merchant do + it "exists" do + merchant = Merchant.new(1, "Bob's Burgers") + expect(merchant).to be_instance_of (Merchant) + end + + it "can return a name and id" do + merchant = Merchant.new(:id => 1, :name => "Bob's Burgers") + expect(merchant.id).to eq(1) + expect(merchant.name).to eq("Bob's Burgers") + end +end diff --git a/test/sales_engine_spec.rb b/test/sales_engine_spec.rb new file mode 100644 index 0000000000..124634cd1b --- /dev/null +++ b/test/sales_engine_spec.rb @@ -0,0 +1,39 @@ +require "./lib/sales_engine" +require "./lib/item_collection" +require "./lib/merchant_collection" + +#You may need to add more `expect` lines to each test to make it more robust...! +RSpec.describe SalesEngine do + it "exists" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + expect(sales_engine).to be_instance_of SalesEngine + end + + it "can return an array of all items" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + + expect(sales_engine.item_collection).to be_instance_of ItemCollection + + + + end + + it "can return an array of all merchants" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + + expect(sales_engine.merchant_collection).to be_instance_of MerchantCollection + + + + end + +end From 97f782ac070da58c00cb4ce9d3346730e481e238 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Tue, 31 May 2022 17:36:13 -0400 Subject: [PATCH 002/131] Add SimpleCov to Gemfile --- Gemfile | 1 + Gemfile.lock | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile index 342acdd559..6e302d8def 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ gem 'cane' gem 'reek' gem 'rake' gem 'rspec' +gem 'simplecov', require: false, group: :test diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..1b921dde78 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,50 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + cane (3.0.0) + parallel + diff-lcs (1.5.0) + docile (1.4.0) + kwalify (0.7.2) + parallel (1.22.1) + parser (3.1.2.0) + ast (~> 2.4.1) + rainbow (3.1.1) + rake (13.0.6) + reek (6.1.1) + kwalify (~> 0.7.0) + parser (~> 3.1.0) + rainbow (>= 2.0, < 4.0) + rspec (3.11.0) + rspec-core (~> 3.11.0) + rspec-expectations (~> 3.11.0) + rspec-mocks (~> 3.11.0) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-support (3.11.0) + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + +PLATFORMS + x86_64-darwin-21 + +DEPENDENCIES + cane + rake + reek + rspec + simplecov + +BUNDLED WITH + 2.3.13 From 8ab1ee28760c72779be7dc0e860b09e71675c252 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Tue, 31 May 2022 17:37:18 -0400 Subject: [PATCH 003/131] Change test folder to spec folder --- {test => spec}/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {test => spec}/.gitignore (100%) diff --git a/test/.gitignore b/spec/.gitignore similarity index 100% rename from test/.gitignore rename to spec/.gitignore From 3345ca44385e5ab92d5430bc573d6ab02d861e59 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Tue, 31 May 2022 17:41:38 -0400 Subject: [PATCH 004/131] Add spec_helper file for SimpleCov --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 spec/spec_helper.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000000..39e075fadc --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'simplecov' +SimpleCov.start From ec10368d93054bb82bf4ab424038e2016c7e00e1 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Tue, 31 May 2022 18:06:39 -0600 Subject: [PATCH 005/131] Current work Iter 0 --- lib/merchant_repository.rb | 18 ++++++++++++++++++ spec/merchant_repository_spec.rb | 18 ++++++++++++++++++ {test => spec}/merchant_spec.rb | 0 {test => spec}/sales_engine_spec.rb | 0 4 files changed, 36 insertions(+) create mode 100644 lib/merchant_repository.rb create mode 100644 spec/merchant_repository_spec.rb rename {test => spec}/merchant_spec.rb (100%) rename {test => spec}/sales_engine_spec.rb (100%) diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb new file mode 100644 index 0000000000..30a93e7685 --- /dev/null +++ b/lib/merchant_repository.rb @@ -0,0 +1,18 @@ +require 'CSV' +require './lib/merchant.rb' +class MerchantRepository + attr_reader :all + def initialize(file_path) + @file_path = file_path + @all = [] + + CSV.foreach(@file_path, headers: true, header_converters: :symbol) do |row| + @all << Merchant.new(:id => row[:id],:name => row[:name]) + + end + + + end + + +end diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb new file mode 100644 index 0000000000..ead0506a4b --- /dev/null +++ b/spec/merchant_repository_spec.rb @@ -0,0 +1,18 @@ +require './lib/merchant.rb' +require './lib/merchant_repository.rb' + +RSpec.describe MerchantRepository do + it 'exists' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo).to be_a(MerchantRepository) + end + + it 'returns an array of all known Merchant instances' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo.all).to eq([]) + merchant = Merchant.new({:id => 1, :name => "Bob's Burgers"}) + expect(merchant_repo.all).to eq([merchant]) + + end + +end diff --git a/test/merchant_spec.rb b/spec/merchant_spec.rb similarity index 100% rename from test/merchant_spec.rb rename to spec/merchant_spec.rb diff --git a/test/sales_engine_spec.rb b/spec/sales_engine_spec.rb similarity index 100% rename from test/sales_engine_spec.rb rename to spec/sales_engine_spec.rb From acea9ffa8a31925ba2043914138a0de60a7fc58d Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Tue, 31 May 2022 20:54:56 -0600 Subject: [PATCH 006/131] Create item class and item test --- lib/item.rb | 9 +++++++++ lib/merchant_repository.rb | 4 +++- spec/item_spec.rb | 19 +++++++++++++++++++ spec/merchant_repository_spec.rb | 7 ++++++- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 lib/item.rb create mode 100644 spec/item_spec.rb diff --git a/lib/item.rb b/lib/item.rb new file mode 100644 index 0000000000..b6d8204d8e --- /dev/null +++ b/lib/item.rb @@ -0,0 +1,9 @@ +require 'CSV' + +class Item + attr_reader :id, :name + + def initialize (id, name) + + end +end diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 30a93e7685..ab187e92b4 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -10,7 +10,9 @@ def initialize(file_path) @all << Merchant.new(:id => row[:id],:name => row[:name]) end - + def find_by_id(id) + + end end diff --git a/spec/item_spec.rb b/spec/item_spec.rb new file mode 100644 index 0000000000..8c6f4d3a44 --- /dev/null +++ b/spec/item_spec.rb @@ -0,0 +1,19 @@ +require './lib/items.rb' + +RSpec.describe Item do + + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 +}) + + it 'exists' do + expect(i).to be_a(Item) + end + +end diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index ead0506a4b..7373780a98 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -12,7 +12,12 @@ expect(merchant_repo.all).to eq([]) merchant = Merchant.new({:id => 1, :name => "Bob's Burgers"}) expect(merchant_repo.all).to eq([merchant]) - + end + it 'can identify customer by its ID' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + + expect(merchant_repo.find_by_id(1)).to eq(Customer) + end From 2e4cd0c91587f3ec238022c70b4361ecaaa0a29c Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Tue, 31 May 2022 21:06:26 -0600 Subject: [PATCH 007/131] Complete item_spec --- spec/item_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 8c6f4d3a44..9ce27858cd 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -15,5 +15,18 @@ it 'exists' do expect(i).to be_a(Item) end - + + it 'item has attributes' do + time = Time.new + expect(i.id).to eq(1) + expect(i.name).to eq("Pencil") + expect(i.description).to eq("You can use it to write things") + expect(i.unit_price).to eq(BigDecimal(10.99,4)) + expect(i.created_at).to eq(time) + expect(i.updated_at).to eq(time) + expect(i.merchant_id).to eq(2) + end + it 'returns the price of the item in dollars' do + expect(i.unit_price_to_dollars).to eq(10.99) + end end From d40508329ae6c7806d750e7bcb9a39852c7be567 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Tue, 31 May 2022 21:36:05 -0600 Subject: [PATCH 008/131] Item class needs correcting --- lib/item.rb | 15 ++++++++++++--- spec/item_spec.rb | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/item.rb b/lib/item.rb index b6d8204d8e..4c1ebf48d7 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,9 +1,18 @@ require 'CSV' class Item - attr_reader :id, :name + attr_reader :id, :name, :description, :unit_price, :created_at, :updated_at, :merchant_id - def initialize (id, name) - + def initialize(item_attributes) + @id = item_attributes[:id].to_i + @name = item_attributes[:name] + @description = item_attributes[:description] + @unit_price = item_attributes[:unit_price] + @created_at = item_attributes[:created_at] + @updated_at = item_attributes[:updated_at] + @merchant_id = item_attributes[:merchant_id].to_i + end + def unit_price_to_dollars + @unit_price.to_f end end diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 9ce27858cd..acbc96f502 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -1,5 +1,5 @@ -require './lib/items.rb' - +require './lib/item.rb' +require 'BigDecimal' RSpec.describe Item do i = Item.new({ From 5311f42a4afc1d26cb19b25c0b660b5e0cc58981 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 15:07:23 -0400 Subject: [PATCH 009/131] Create Item class and tests --- lib/item.rb | 19 ++++++++ spec/item_spec.rb | 120 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 lib/item.rb create mode 100644 spec/item_spec.rb diff --git a/lib/item.rb b/lib/item.rb new file mode 100644 index 0000000000..9a65f76b59 --- /dev/null +++ b/lib/item.rb @@ -0,0 +1,19 @@ +class Item + attr_reader :id, + :name, + :description, + :unit_price, + :created_at, + :updated_at, + :merchant_id + + def initialize(data) + @id = data[:id] + @name = data[:name] + @description = data[:description] + @unit_price = data[:unit_price] + @created_at = data[:created_at] + @updated_at = data[:updated_at] + @merchant_id = data[:merchant_id] + end +end diff --git a/spec/item_spec.rb b/spec/item_spec.rb new file mode 100644 index 0000000000..daabd74e00 --- /dev/null +++ b/spec/item_spec.rb @@ -0,0 +1,120 @@ +require './lib/item' +require 'time' +require 'bigdecimal' + +RSpec.describe Item do + + it 'exists' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 + }) + + expect(i).to be_instance_of(Item) + end + + it 'returns the item id' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 + }) + + expect(i.id).to eq(1) + end + + it 'returns the item name' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 + }) + + expect(i.name).to eq("Pencil") + end + + it 'returns the item description' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 + }) + + expect(i.description).to eq("You can use it to write things") + end + + it 'returns the item unit price' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 + }) + + expect(i.unit_price).to eq(BigDecimal(10.99,4)) + end + + it 'returns the time the item was created' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now.round, + :updated_at => Time.now.round, + :merchant_id => 2 + }) + + expect(i.created_at).to eq(Time.now.round) + end + + it 'returns the time the item was updated' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now.round, + :updated_at => Time.now.round, + :merchant_id => 2 + }) + + expect(i.updated_at).to eq(Time.now.round) + end + + it 'returns the merchant id' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 + }) + + expect(i.merchant_id).to eq(2) + end + + +end From 2d001dd8dbdd57afeec2759a2f876307c172c204 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 15:41:13 -0400 Subject: [PATCH 010/131] Add unit price to dollars method and tests --- lib/item.rb | 4 ++++ spec/item_spec.rb | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/item.rb b/lib/item.rb index 9a65f76b59..1f1a9696ed 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -16,4 +16,8 @@ def initialize(data) @updated_at = data[:updated_at] @merchant_id = data[:merchant_id] end + + def unit_price_to_dollars + @unit_price.to_f + end end diff --git a/spec/item_spec.rb b/spec/item_spec.rb index daabd74e00..70f4d466cd 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -112,9 +112,22 @@ :updated_at => Time.now, :merchant_id => 2 }) - expect(i.merchant_id).to eq(2) end + it 'returns the unit price as a float' do + i = Item.new({ + :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2 + }) + + expect(i.unit_price_to_dollars).to eq(10.99) + end + end From 3862eea680dc7fc7cba5c808d9101afc7c7a0f5e Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 16:18:23 -0400 Subject: [PATCH 011/131] Create item_repository class and spec file --- lib/item_repository.rb | 2 ++ spec/item_repository_spec.rb | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 lib/item_repository.rb create mode 100644 spec/item_repository_spec.rb diff --git a/lib/item_repository.rb b/lib/item_repository.rb new file mode 100644 index 0000000000..56a5e54628 --- /dev/null +++ b/lib/item_repository.rb @@ -0,0 +1,2 @@ +class ItemRepository +end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb new file mode 100644 index 0000000000..816fc7b7a2 --- /dev/null +++ b/spec/item_repository_spec.rb @@ -0,0 +1,5 @@ +require '.lib/item_repository' + +RSpec.describe ItemRepository do + +end From a79bc4c9dc1df505af5e1cc6ea3b6b910b1f09d0 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 16:23:06 -0400 Subject: [PATCH 012/131] Replace last test with two separate tests --- spec/merchant_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 spec/merchant_spec.rb diff --git a/spec/merchant_spec.rb b/spec/merchant_spec.rb new file mode 100644 index 0000000000..c86ed514fe --- /dev/null +++ b/spec/merchant_spec.rb @@ -0,0 +1,20 @@ +require './lib/merchant' + +RSpec.describe Merchant do + it "exists" do + merchant = Merchant.new(1, "Bob's Burgers") + expect(merchant).to be_instance_of (Merchant) + end + + it "can return a name" do + merchant = Merchant.new(:id => 1, :name => "Bob's Burgers") + + expect(merchant.name).to eq("Bob's Burgers") + end + + it "can return an id" do + merchant = Merchant.new(:id => 1, :name => "Bob's Burgers") + + expect(merchant.id).to eq(1) + end +end From 107432ec0b5beed4b04cce382d7a8bcd3c97de2b Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 16:25:04 -0400 Subject: [PATCH 013/131] Remove test/merchant_spec and test/sales_engine_spec --- test/merchant_spec.rb | 14 -------------- test/sales_engine_spec.rb | 39 --------------------------------------- 2 files changed, 53 deletions(-) delete mode 100644 test/merchant_spec.rb delete mode 100644 test/sales_engine_spec.rb diff --git a/test/merchant_spec.rb b/test/merchant_spec.rb deleted file mode 100644 index f4232efe7f..0000000000 --- a/test/merchant_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require './lib/merchant' - -RSpec.describe Merchant do - it "exists" do - merchant = Merchant.new(1, "Bob's Burgers") - expect(merchant).to be_instance_of (Merchant) - end - - it "can return a name and id" do - merchant = Merchant.new(:id => 1, :name => "Bob's Burgers") - expect(merchant.id).to eq(1) - expect(merchant.name).to eq("Bob's Burgers") - end -end diff --git a/test/sales_engine_spec.rb b/test/sales_engine_spec.rb deleted file mode 100644 index 124634cd1b..0000000000 --- a/test/sales_engine_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "./lib/sales_engine" -require "./lib/item_collection" -require "./lib/merchant_collection" - -#You may need to add more `expect` lines to each test to make it more robust...! -RSpec.describe SalesEngine do - it "exists" do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv" - }) - expect(sales_engine).to be_instance_of SalesEngine - end - - it "can return an array of all items" do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv" - }) - - expect(sales_engine.item_collection).to be_instance_of ItemCollection - - - - end - - it "can return an array of all merchants" do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv" - }) - - expect(sales_engine.merchant_collection).to be_instance_of MerchantCollection - - - - end - -end From 2ec00a183f062e550509e7fa00f0dcc32ad04ba4 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 16:28:26 -0400 Subject: [PATCH 014/131] Make changes to class names in spec and class files --- lib/sales_engine.rb | 5 ++--- spec/sales_engine_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 spec/sales_engine_spec.rb diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb index 11d95f7f3c..540f563293 100644 --- a/lib/sales_engine.rb +++ b/lib/sales_engine.rb @@ -2,12 +2,11 @@ class SalesEngine attr_reader :item_collection, :merchant_collection def initialize(items_path, merchants_path) - @item_collection = ItemCollection.new(items_path) - @merchant_collection = MerchantCollection.new(merchants_path) + @item_repository = ItemRepository.new(items_path) + @merchant_repository = MerchantRepository.new(merchants_path) end def self.from_csv(data) - # binding.pry return SalesEngine.new(data[:items], data[:merchants]) end diff --git a/spec/sales_engine_spec.rb b/spec/sales_engine_spec.rb new file mode 100644 index 0000000000..c797332ab2 --- /dev/null +++ b/spec/sales_engine_spec.rb @@ -0,0 +1,39 @@ +require "./lib/sales_engine" +require "./lib/item_repository" +require "./lib/merchant_repository" + +#You may need to add more `expect` lines to each test to make it more robust...! +RSpec.describe SalesEngine do + it "exists" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + expect(sales_engine).to be_instance_of SalesEngine + end + + it "can return an array of all items" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + + expect(sales_engine.item_repository).to be_instance_of ItemRepository + + + + end + + it "can return an array of all merchants" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + + expect(sales_engine.merchant_repository).to be_instance_of MerchantRepository + + + + end + +end From 84827b610aab051cc879ccc71811ef86bee76564 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 16:32:00 -0400 Subject: [PATCH 015/131] Add tests to spec file --- spec/item_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 70f4d466cd..b6f5011462 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -125,7 +125,7 @@ :updated_at => Time.now, :merchant_id => 2 }) - + expect(i.unit_price_to_dollars).to eq(10.99) end From 721a6fcb6dc41c5d0e9b981bfb784ae40e0f6eef Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 16:32:46 -0400 Subject: [PATCH 016/131] Create merchant repository class and spec file --- lib/merchant_repository.rb | 2 ++ spec/merchant_repository_spec.rb | 0 2 files changed, 2 insertions(+) create mode 100644 lib/merchant_repository.rb create mode 100644 spec/merchant_repository_spec.rb diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb new file mode 100644 index 0000000000..10b1c9d55e --- /dev/null +++ b/lib/merchant_repository.rb @@ -0,0 +1,2 @@ +class MerchantRepository +end diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb new file mode 100644 index 0000000000..e69de29bb2 From 994526cef4d8c3d605477fabb572a554dcd6bcc2 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Wed, 1 Jun 2022 16:52:44 -0400 Subject: [PATCH 017/131] Change merchant repository class and spec file to include previous code --- lib/merchant_repository.rb | 16 ++++++++++++++++ spec/merchant_repository_spec.rb | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 10b1c9d55e..30a93e7685 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -1,2 +1,18 @@ +require 'CSV' +require './lib/merchant.rb' class MerchantRepository + attr_reader :all + def initialize(file_path) + @file_path = file_path + @all = [] + + CSV.foreach(@file_path, headers: true, header_converters: :symbol) do |row| + @all << Merchant.new(:id => row[:id],:name => row[:name]) + + end + + + end + + end diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index e69de29bb2..e465eaaaa6 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -0,0 +1,18 @@ +require './lib/merchant.rb' +require './lib/merchant_repository.rb' + +RSpec.describe MerchantRepository do + it 'exists' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo).to be_a(MerchantRepository) + end + + it 'returns an array of all known Merchant instances' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo.all).to eq([]) + merchant = Merchant.new({:id => 1, :name => "Bob's Burgers"}) + expect(merchant_repo.all).to eq([merchant]) + + end + +end From 09d6d0bf65f5429a20abc331c0fb5b69fd1d87ba Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 15:48:14 -0600 Subject: [PATCH 018/131] Test: Merchant repo can find by merchant ID --- spec/merchant_repository_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index 31c31ee302..a1c440fb10 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -9,9 +9,12 @@ it 'returns an array of all known Merchant instances' do merchant_repo = MerchantRepository.new('./data/merchants.csv') - expect(merchant_repo.all).to eq([]) - merchant = Merchant.new({:id => 1, :name => "Bob's Burgers"}) - expect(merchant_repo.all).to eq([merchant]) + expect(merchant_repo.all.count).to eq(475) end + it 'can find merchant by ID' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + id = 12334105 + expect(merchant_repo.find_by_id).to eq('Shopin1901') + end end From b4c797cf4d0a7f80b5bff18c89363ad08a3739d7 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 16:05:23 -0600 Subject: [PATCH 019/131] Refactor: Test where merchant can find merchant by ID --- spec/merchant_repository_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index a1c440fb10..26e58df679 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -15,6 +15,7 @@ it 'can find merchant by ID' do merchant_repo = MerchantRepository.new('./data/merchants.csv') id = 12334105 - expect(merchant_repo.find_by_id).to eq('Shopin1901') + expect(merchant_repo.find_by_id(12334105)).to eq('Shopin1901') + expect(merchant_repo.find_by_id(12948129048)).to eq(nil) end end From 00c6b373c9e2f142b6c29b77fd5a3186c358f370 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 16:08:25 -0600 Subject: [PATCH 020/131] Feat: Pass test merchant repo finds by ID --- lib/merchant_repository.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 30a93e7685..387a7d59f9 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -7,12 +7,19 @@ def initialize(file_path) @all = [] CSV.foreach(@file_path, headers: true, header_converters: :symbol) do |row| - @all << Merchant.new(:id => row[:id],:name => row[:name]) + @all << Merchant.new({:id => row[:id], :name => row[:name]}) end - - end + def find_by_id(id) + @all.each do |merchant| + if merchant.id.to_i == id + return merchant.name + else + return nil + end + end + end end From b462b323132dfb828e99928485b2959f642c8c1c Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 16:12:36 -0600 Subject: [PATCH 021/131] Test: Merchant repo can find merchant by name --- spec/merchant_repository_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index 26e58df679..4e34573c21 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -14,8 +14,13 @@ it 'can find merchant by ID' do merchant_repo = MerchantRepository.new('./data/merchants.csv') - id = 12334105 expect(merchant_repo.find_by_id(12334105)).to eq('Shopin1901') expect(merchant_repo.find_by_id(12948129048)).to eq(nil) end + + it 'can find merchant by name' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo.find_by_name('InvalidName')).to eq(nil) + expect(merchant_repo.find_by_name('JUSTEmonsters')).to be_a(Merchant) + end end From 21ed75c74b4cd8e7242ad6aaf4f7ec54b1c0938d Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 17:42:38 -0600 Subject: [PATCH 022/131] Refactor: Test merchant repo can find merchant by name Co-authored-by: Nick Jones --- spec/merchant_repository_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index 4e34573c21..91f0cb4202 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -14,13 +14,14 @@ it 'can find merchant by ID' do merchant_repo = MerchantRepository.new('./data/merchants.csv') - expect(merchant_repo.find_by_id(12334105)).to eq('Shopin1901') + expect(merchant_repo.find_by_id(12334105)).to be_a(Merchant) expect(merchant_repo.find_by_id(12948129048)).to eq(nil) end it 'can find merchant by name' do merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo.find_by_name('Shopin1901')).to be_instance_of(Merchant) + expect(merchant_repo.find_by_name('sHoPiN1901')).to be_instance_of(Merchant) expect(merchant_repo.find_by_name('InvalidName')).to eq(nil) - expect(merchant_repo.find_by_name('JUSTEmonsters')).to be_a(Merchant) end end From c95079ed95e387ffe0fedf852f21d51edb4f2fc9 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 17:44:42 -0600 Subject: [PATCH 023/131] Feat: Pass test merchant repo finds by name Co-authored-by: Nick Jones --- lib/merchant_repository.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 387a7d59f9..6f06928278 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -15,11 +15,25 @@ def initialize(file_path) def find_by_id(id) @all.each do |merchant| if merchant.id.to_i == id - return merchant.name + return merchant else return nil end end end + def find_by_name(name) + @all.find do |merchant| + merchant.name.downcase.include?(name.downcase) + end + + # @all.each do |merchant| + # if merchant.name.downcase == name.downcase + # merchant + # else + # nil + # end + # end + end + end From 8dc045d235a5e60ed28a27cb560c806c3d9963e0 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 18:13:27 -0600 Subject: [PATCH 024/131] Test: Merchant repo can find all merchants by name fragment Co-authored-by: Nick Jones --- spec/merchant_repository_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index 91f0cb4202..7e7508d1ef 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -24,4 +24,16 @@ expect(merchant_repo.find_by_name('sHoPiN1901')).to be_instance_of(Merchant) expect(merchant_repo.find_by_name('InvalidName')).to eq(nil) end + + it 'can find all merchants by name fragment' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo.find_all_by_name('mini')).to be_instance_of(Array) + expect(merchant_repo.find_all_by_name('MiNi')).to be_instance_of(Array) + expect(merchant_repo.find_all_by_name('inG')).to be_instance_of(Array) + expect(merchant_repo.find_all_by_name('sHoPiN')).to be_instance_of(Array) + expect(merchant_repo.find_all_by_name('sHoPiN1901')).to be_instance_of(Array) + expect(merchant_repo.find_all_by_name('InvalidName')).to eq([]) + end + + #Nick and Thiago left off here, need to ask if lines 30 - 32 are valid tests end From 207478ce7f1d0c5fffea7349d972669ff458b43b Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 18:14:21 -0600 Subject: [PATCH 025/131] Feat: Pass test merchant repo finds all merchants by name fragment Co-authored-by: Nick Jones --- lib/merchant_repository.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 6f06928278..99274c52f7 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -26,14 +26,12 @@ def find_by_name(name) @all.find do |merchant| merchant.name.downcase.include?(name.downcase) end + end - # @all.each do |merchant| - # if merchant.name.downcase == name.downcase - # merchant - # else - # nil - # end - # end + def find_all_by_name(name_fragment) + @all.find_all do |merchant| + merchant.name.downcase.include?(name_fragment.downcase) + end end end From 13ffd9087bf4746f19315c19a19eadc91dac28ab Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Wed, 1 Jun 2022 18:15:53 -0600 Subject: [PATCH 026/131] Refactor: Sales engine attr reader --- lib/sales_engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb index 540f563293..334c34c54e 100644 --- a/lib/sales_engine.rb +++ b/lib/sales_engine.rb @@ -1,5 +1,5 @@ class SalesEngine - attr_reader :item_collection, :merchant_collection + attr_reader :item_repository, :merchant_repository def initialize(items_path, merchants_path) @item_repository = ItemRepository.new(items_path) From 18fca1331eb671092f5ef12115d262beaac5cab4 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Thu, 2 Jun 2022 08:46:39 -0600 Subject: [PATCH 027/131] Create Item repository --- spec/item_repository.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 spec/item_repository.rb diff --git a/spec/item_repository.rb b/spec/item_repository.rb new file mode 100644 index 0000000000..b025b6228c --- /dev/null +++ b/spec/item_repository.rb @@ -0,0 +1,5 @@ +require './spec/item_repository.rb' + +RSpec.describe ItemRepository do + +end From 88d579ffa2624d3c8464860a46c27941d8b8656b Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 10:25:20 -0600 Subject: [PATCH 028/131] Test: Add merchant_repository.rb method find_all_by_name, and test. Co-authored-by: Justin Co-authored-by: Thiago --- spec/merchant_repository_spec.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index 7e7508d1ef..4a71d949e0 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -27,13 +27,35 @@ it 'can find all merchants by name fragment' do merchant_repo = MerchantRepository.new('./data/merchants.csv') + merchant_repo.find_all_by_name("mini").each do |merchant| + expect(merchant.name.downcase.include?("mini")).to eq(true) + expect(merchant).to be_instance_of(Merchant) + end expect(merchant_repo.find_all_by_name('mini')).to be_instance_of(Array) + + merchant_repo.find_all_by_name("MiNi").each do |merchant| + expect(merchant.name.downcase.include?("mini")).to eq(true) + expect(merchant).to be_instance_of(Merchant) + end + expect(merchant_repo.find_all_by_name('MiNi')).to be_instance_of(Array) expect(merchant_repo.find_all_by_name('inG')).to be_instance_of(Array) expect(merchant_repo.find_all_by_name('sHoPiN')).to be_instance_of(Array) expect(merchant_repo.find_all_by_name('sHoPiN1901')).to be_instance_of(Array) + + merchant_repo.find_all_by_name("InvalidName").each do |merchant| + expect(merchant.name.downcase.include?("invalidname")).to eq(false) + expect(merchant).to eq(nil) + end expect(merchant_repo.find_all_by_name('InvalidName')).to eq([]) end - #Nick and Thiago left off here, need to ask if lines 30 - 32 are valid tests + it "can create a new merchant instance" do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + attribute = {name: "Turing School of Software and Design"} + merchant_repo.create(attribute) + new_merchant = merchant_repo.find_by_id(12337412) + expect(new_merchant.name).to be ("Turing School of Software and Design") + end + end From ac783d6ccfde3dc9bc623a473e97e04e5140c6c3 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 11:58:59 -0600 Subject: [PATCH 029/131] Pass Test: create method Feature: Add create method and test. Add update test Co-authored-by: Thiago Co-authored-by: Justin --- lib/merchant.rb | 3 ++- lib/merchant_repository.rb | 16 ++++++++++------ spec/merchant_repository_spec.rb | 17 ++++++++++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/merchant.rb b/lib/merchant.rb index 4690561fb9..44f52caf76 100644 --- a/lib/merchant.rb +++ b/lib/merchant.rb @@ -1,5 +1,6 @@ class Merchant - attr_reader :id, :name + attr_reader :id + attr_accessor :name def initialize(data) @id = data[:id] diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 99274c52f7..8ef7a4c09a 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -13,12 +13,8 @@ def initialize(file_path) end def find_by_id(id) - @all.each do |merchant| - if merchant.id.to_i == id - return merchant - else - return nil - end + @all.find do |merchant| + merchant.id.to_i == id end end @@ -34,4 +30,12 @@ def find_all_by_name(name_fragment) end end + def create(attribute) + new_id = @all.last.id.to_i + 1 + new_attribute = attribute + @all << Merchant.new(:id => new_id.to_s, :name => new_attribute) + return @all.last + end + + end diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index 4a71d949e0..e1d3e6b97f 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -52,10 +52,17 @@ it "can create a new merchant instance" do merchant_repo = MerchantRepository.new('./data/merchants.csv') - attribute = {name: "Turing School of Software and Design"} - merchant_repo.create(attribute) - new_merchant = merchant_repo.find_by_id(12337412) - expect(new_merchant.name).to be ("Turing School of Software and Design") - end + new_merchant = merchant_repo.create("Turing School of Software and Design") + expect(new_merchant.name).to eq("Turing School of Software and Design") + expect(merchant_repo.find_by_id(12337412)).to be_a(Merchant) + end + + it "can update a merchant object" do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo.find_by_id(12334105).name).to eq("Shopin1901") + merchant_repo.update(12334105, "Shopin2022") + expect(merchant_repo.find_by_id(12334105).name).to eq("Shopin2022") + expect(merchant_repo.find_by_name("Shopin1901")).to eq(nil) + end end From 9af2ad41ab0d8f4877ea1e5416dbfde0149ec4d5 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Thu, 2 Jun 2022 17:53:04 -0600 Subject: [PATCH 030/131] Feat: Pass test merchant repo updates a merchant object Co-authored: Nick --- lib/merchant_repository.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 8ef7a4c09a..e10216bed2 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -37,5 +37,9 @@ def create(attribute) return @all.last end + def update(id, attributes) + renamed_merchant = find_by_id(id) + renamed_merchant.name = attributes + end end From bcf25df61b980556ff98376b1f0e9accca675942 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Thu, 2 Jun 2022 17:58:18 -0600 Subject: [PATCH 031/131] Test: Merchant repo can delete a merchant object Co-authored: Nick --- spec/merchant_repository_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/merchant_repository_spec.rb b/spec/merchant_repository_spec.rb index e1d3e6b97f..aadeacb982 100644 --- a/spec/merchant_repository_spec.rb +++ b/spec/merchant_repository_spec.rb @@ -65,4 +65,11 @@ expect(merchant_repo.find_by_name("Shopin1901")).to eq(nil) end + it 'can delete a merchant object' do + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(merchant_repo.find_by_id(12334105)).to be_a(Merchant) + merchant_repo.delete(12334105) + expect(merchant_repo.find_by_id(12334105)).to eq(nil) + end + end From 439aecbf1affe0156edb823e6528f5bbaff7b1d0 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Thu, 2 Jun 2022 18:10:49 -0600 Subject: [PATCH 032/131] Feat: Pass test merchant repo deletes a merchant object Co-authored: Nick --- lib/merchant_repository.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index e10216bed2..9fdeb72c2d 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -42,4 +42,9 @@ def update(id, attributes) renamed_merchant.name = attributes end + def delete(id) + removed_merchant = find_by_id(id) + @all.delete(removed_merchant) + end + end From c7d9bf8d95bf5c662d60bc19642c602ac7d62118 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Thu, 2 Jun 2022 20:57:56 -0400 Subject: [PATCH 033/131] Change instance variables names in class and spec --- lib/sales_engine.rb | 6 +++--- spec/sales_engine_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb index 334c34c54e..b498e17f87 100644 --- a/lib/sales_engine.rb +++ b/lib/sales_engine.rb @@ -1,9 +1,9 @@ class SalesEngine - attr_reader :item_repository, :merchant_repository + attr_reader :items, :merchants def initialize(items_path, merchants_path) - @item_repository = ItemRepository.new(items_path) - @merchant_repository = MerchantRepository.new(merchants_path) + @items = ItemRepository.new(items_path) + @merchants = MerchantRepository.new(merchants_path) end def self.from_csv(data) diff --git a/spec/sales_engine_spec.rb b/spec/sales_engine_spec.rb index 4a7a1d603b..23edb76cb3 100644 --- a/spec/sales_engine_spec.rb +++ b/spec/sales_engine_spec.rb @@ -1,5 +1,4 @@ require "./lib/sales_engine" - require "./lib/item_repository" require "./lib/merchant_repository" @@ -10,6 +9,7 @@ :items => "./data/items.csv", :merchants => "./data/merchants.csv" }) + require "pry"; binding.pry expect(sales_engine).to be_instance_of SalesEngine end From be3653c89c8d8df2e439e6cea340a2f751ed4b79 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Thu, 2 Jun 2022 20:59:37 -0400 Subject: [PATCH 034/131] Add initialize method --- lib/item_repository.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 56a5e54628..22a88a5925 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -1,2 +1,21 @@ +require 'CSV' +require './lib/item.rb' + class ItemRepository + attr_reader :all + def initialize(items_path) + @items_path = items_path + @all = [] + + CSV.foreach(@items_path, headers: true, header_converters: :symbol) do |row| + @all << Item.new({ + :id => row[:id], + :name => row[:name], + :description => row[:description], + :unit_price => row[:unit_price], + :created_at => row[:created_at], + :updated_at => row[:updated_at], + :merchant_id => row[:merchant_id]}) + end + end end From 6d4882c37d1a87799dbfcbff4e7feb426a7d4f93 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 19:19:58 -0600 Subject: [PATCH 035/131] Test: add test for it exists in item repository spec Co-authored-by: Thiago --- spec/item_repository_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 816fc7b7a2..d2818981f1 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -1,5 +1,8 @@ -require '.lib/item_repository' +require './lib/item_repository' RSpec.describe ItemRepository do - + it "exists" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo).to be_a(ItemRepository) + end end From 87d4c6cc49f5cd1e575d4b4ec9fe3c5563c8726a Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 19:30:30 -0600 Subject: [PATCH 036/131] Test: item repository can return an array of all known item instances Co-authored-by: Thiago --- spec/item_repository_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index d2818981f1..9c3bc62d45 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -5,4 +5,9 @@ item_repo = ItemRepository.new('./data/items.csv') expect(item_repo).to be_a(ItemRepository) end + + it "can return an array of all known item instances" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.all.count).to eq(1367) + end end From f9ef70a319bdd2419b8b53c983cc61ce425ead3b Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 19:36:42 -0600 Subject: [PATCH 037/131] Test: item repository can find item by ID Co-authored-by: Thiago --- spec/item_repository_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 9c3bc62d45..1acb7766a1 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -1,3 +1,4 @@ +require './lib/item.rb' require './lib/item_repository' RSpec.describe ItemRepository do @@ -10,4 +11,10 @@ item_repo = ItemRepository.new('./data/items.csv') expect(item_repo.all.count).to eq(1367) end + + it "can find item by ID" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.find_by_id(263400305)).to be_a(Item) + expect(item_repo.find_by_id(12345678910)).to eq(nil) + end end From 0d03fef503e4379c4e95f32d686cdf99e26f246c Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 19:47:55 -0600 Subject: [PATCH 038/131] Test: item repository can find item by name Co-authored-by: Thiago --- lib/item_repository.rb | 6 ++++++ spec/item_repository_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 22a88a5925..3c391ecddd 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -18,4 +18,10 @@ def initialize(items_path) :merchant_id => row[:merchant_id]}) end end + + def find_by_id(id) + @all.find do |item| + item.id.to_i == id + end + end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 1acb7766a1..b9a520d323 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -17,4 +17,11 @@ expect(item_repo.find_by_id(263400305)).to be_a(Item) expect(item_repo.find_by_id(12345678910)).to eq(nil) end + + it "can find an item by name" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.find_by_name("Free standing Woden letters")).to be_instance_of(Item) + expect(item_repo.find_by_name("FREE stANDing wOdeN lEttErs")).to be_instance_of(Item) + expect(item_repo.find_by_name("InvalidName")).to eq(nil) + end end From 1ed68e9ee0bbf1c7e8a129c5310aaf78a5002f65 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 19:50:40 -0600 Subject: [PATCH 039/131] Feature:add method item repository can find item by name Co-authored-by: Thiago --- lib/item_repository.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 3c391ecddd..4cd4d68d29 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -24,4 +24,10 @@ def find_by_id(id) item.id.to_i == id end end + + def find_by_name(name) + @all.find do |item| + item.name.downcase.include?(name.downcase) + end + end end From 6971fcad7b9a511a1c2ff7152ad008ff1d16b6f2 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 19:58:11 -0600 Subject: [PATCH 040/131] Test: item repo spec can test for a method to return an item by a description Co-authored-by: Thiago --- spec/item_repository_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index b9a520d323..bdd2327fc1 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -24,4 +24,10 @@ expect(item_repo.find_by_name("FREE stANDing wOdeN lEttErs")).to be_instance_of(Item) expect(item_repo.find_by_name("InvalidName")).to eq(nil) end + + it "can return an item by parts of a description" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.find_all_with_description("Disney")).to be_instance_of(Array) + expect(item_repo.find_all_with_description("AAAAAAAAAAA")).to be([]) + end end From 9e0e9d789d08c765ade04a6c70e789677f3e892d Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 20:05:47 -0600 Subject: [PATCH 041/131] Test: added extra testing options for returning a description in item repository spec Co-authored-by: Thiago --- lib/item_repository.rb | 6 ++++++ spec/item_repository_spec.rb | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 4cd4d68d29..f670271e09 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -30,4 +30,10 @@ def find_by_name(name) item.name.downcase.include?(name.downcase) end end + + def find_all_with_description(description) + @all.find_all do |item| + item.description.downcase.include?(description.downcase) + end + end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index bdd2327fc1..1c804a9ce8 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -28,6 +28,7 @@ it "can return an item by parts of a description" do item_repo = ItemRepository.new('./data/items.csv') expect(item_repo.find_all_with_description("Disney")).to be_instance_of(Array) - expect(item_repo.find_all_with_description("AAAAAAAAAAA")).to be([]) + expect(item_repo.find_all_with_description("dISneY")).to be_instance_of(Array) + expect(item_repo.find_all_with_description("Thiago")).to eq([]) end end From f0dede0f7b500c06c5f3fdb047f168399e7a7ea6 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 20:36:04 -0600 Subject: [PATCH 042/131] Feature/Test: Add method find all by price, and test Co-authored-by: Thiago Co-authored-by: Kevin --- lib/item_repository.rb | 6 ++++++ spec/item_repository_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index f670271e09..7865c8a338 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -36,4 +36,10 @@ def find_all_with_description(description) item.description.downcase.include?(description.downcase) end end + + def find_all_by_price(unit_price) + @all.find_all do |item| + item.unit_price.include?(unit_price) + end + end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 1c804a9ce8..0f61ac5aa0 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -31,4 +31,10 @@ expect(item_repo.find_all_with_description("dISneY")).to be_instance_of(Array) expect(item_repo.find_all_with_description("Thiago")).to eq([]) end + + it "can find all items by price" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.find_all_by_price("1300")).to be_instance_of(Array) + expect(item_repo.find_all_by_price("1,000,000")).to eq([]) + end end From a4a79b7f1cae399851e28f281714fbe7e0bb5a11 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 20:44:35 -0600 Subject: [PATCH 043/131] Test: add test for finding all items in price range Co-authored-by: Thiago Co-authored-by: Kevin --- spec/item_repository_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 0f61ac5aa0..5e2816705e 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -37,4 +37,10 @@ expect(item_repo.find_all_by_price("1300")).to be_instance_of(Array) expect(item_repo.find_all_by_price("1,000,000")).to eq([]) end + + it "can find all items by price in a range" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.find_all_by_price_in_range(1..1400)).to be_instance_of(Array) + expect(item_repo.find_all_by_price_in_range(0..0)).to eq([]) + end end From b8e125437526c8ac7c9e0ecf5ed8143ceb6a4c43 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 20:49:22 -0600 Subject: [PATCH 044/131] Function: Add method for find all by price in range Co-authored-by: Thiago Co-authored-by: Kevin --- lib/item_repository.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 7865c8a338..c01e7a457b 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -41,5 +41,11 @@ def find_all_by_price(unit_price) @all.find_all do |item| item.unit_price.include?(unit_price) end - end + end + + def find_all_by_price_in_range(range) + @all.find_all do |item| + (range.min..range.max).include?(item.unit_price.to_i) + end + end end From 52d8e34434e7f716e5e3c1ff79d40459587c9294 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 20:55:39 -0600 Subject: [PATCH 045/131] Test: add test for finding all items by a merchant ID Co-authored-by: Thiago Co-authored-by: Kevin --- spec/item_repository_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 5e2816705e..ebd821eee4 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -1,5 +1,7 @@ require './lib/item.rb' require './lib/item_repository' +require './lib/merchant_repository' +require './lib/merchant' RSpec.describe ItemRepository do it "exists" do @@ -43,4 +45,9 @@ expect(item_repo.find_all_by_price_in_range(1..1400)).to be_instance_of(Array) expect(item_repo.find_all_by_price_in_range(0..0)).to eq([]) end + it "can find all by merchant id" do + item_repo = ItemRepository.new('./data/items.csv') + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(item_repo.find_all_by_merchant_id(12334105)).to be_instance_of(Array) + expect(item_repo.find_all_by_merchant_id(12334105)).to be eq([]) end From 7d03c1e0376ffb2805ca3dca490e3476064199b7 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 21:00:01 -0600 Subject: [PATCH 046/131] Feature: add method for searching for items by merchant id Co-authored-by: Thiago Co-authored-by: Kevin --- lib/item_repository.rb | 6 ++++++ spec/item_repository_spec.rb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index c01e7a457b..895c3fd175 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -48,4 +48,10 @@ def find_all_by_price_in_range(range) (range.min..range.max).include?(item.unit_price.to_i) end end + + def find_all_by_merchant_id(merchant_id) + @all.find_all do |item| + merchant_id.to_i == item.merchant_id.to_i + end + end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index ebd821eee4..ad065707b8 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -45,9 +45,11 @@ expect(item_repo.find_all_by_price_in_range(1..1400)).to be_instance_of(Array) expect(item_repo.find_all_by_price_in_range(0..0)).to eq([]) end + it "can find all by merchant id" do item_repo = ItemRepository.new('./data/items.csv') merchant_repo = MerchantRepository.new('./data/merchants.csv') expect(item_repo.find_all_by_merchant_id(12334105)).to be_instance_of(Array) - expect(item_repo.find_all_by_merchant_id(12334105)).to be eq([]) + expect(item_repo.find_all_by_merchant_id(12345678910112)).to eq([]) + end end From 3b9c0179be4fc3bcd0168d04d3855e606f81e8c7 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 21:28:28 -0600 Subject: [PATCH 047/131] Feature: add create an item with attributes and worked on test Co-authored-by: Thiago Co-authored-by: Kevin --- lib/item_repository.rb | 10 +++++++++- spec/item_repository_spec.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 895c3fd175..a3d9b6cad2 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -53,5 +53,13 @@ def find_all_by_merchant_id(merchant_id) @all.find_all do |item| merchant_id.to_i == item.merchant_id.to_i end - end + end + #Ask instructor if only adding a name for a new item is okay...Ran out of time lol. + + def create(attributes) + new_id = @all.last.id.to_i + 1 + new_attribute = attributes + @all << Item.new(:id => new_id.to_s, :name => new_attribute) + return @all.last + end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index ad065707b8..5c4293a1ed 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -52,4 +52,12 @@ expect(item_repo.find_all_by_merchant_id(12334105)).to be_instance_of(Array) expect(item_repo.find_all_by_merchant_id(12345678910112)).to eq([]) end + + #Ask instructor if only adding a name for a new item is okay...Ran out of time lol. + it "can create a new item with provided attributes" do + item_repo = ItemRepository.new('./data/items.csv') + new_item = (item_repo.create("Oreos")) + expect(new_item.name).to eq("Oreos") + expect(item_repo.find_by_id(263567475)).to be_a(Item) + end end From a593079a1c9b9db01fb8ef0ca2b224d964aabea5 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 22:00:56 -0600 Subject: [PATCH 048/131] Feature/Test: Add method to update an item and test Co-authored-by: Thiago Co-authored-by: Kevin --- lib/item.rb | 7 ++++--- lib/item_repository.rb | 7 +++++++ spec/item_repository_spec.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/item.rb b/lib/item.rb index 1f1a9696ed..d39dc245b4 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,11 +1,12 @@ class Item attr_reader :id, - :name, - :description, - :unit_price, :created_at, :updated_at, :merchant_id + + attr_accessor :name, + :description, + :unit_price def initialize(data) @id = data[:id] diff --git a/lib/item_repository.rb b/lib/item_repository.rb index a3d9b6cad2..ca939307a3 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -62,4 +62,11 @@ def create(attributes) @all << Item.new(:id => new_id.to_s, :name => new_attribute) return @all.last end + + def update(id, attributes) + updated_item = find_by_id(id) + updated_item.name = attributes[:name] + updated_item.unit_price = attributes[:unit_price] + updated_item.description = attributes[:description] + end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 5c4293a1ed..f07b6136ef 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -60,4 +60,17 @@ expect(new_item.name).to eq("Oreos") expect(item_repo.find_by_id(263567475)).to be_a(Item) end + + it "can update an item's attributes" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.find_by_id(263567474).name).to eq("Minty Green Knit Crochet Infinity Scarf") + expect(item_repo.find_by_id(263567474).description).to eq("- Super Chunky knit infinity scarf\n- Soft mixture of 97% Acrylic and 3% Viscose\n- Beautiful, Warm, and Stylish\n- Very easy to care for\n\nHand wash with cold water and lay flat to dry") + expect(item_repo.find_by_id(263567474).unit_price).to eq("3800") + new_test_attributes = {:name => "New Test Scarf", :description => "A beautiful testing scarf", :unit_price => "1"} + item_repo.update(263567474, new_test_attributes) + expect(item_repo.find_by_id(263567474).name).to eq("New Test Scarf") + expect(item_repo.find_by_id(263567474).description).to eq("A beautiful testing scarf") + expect(item_repo.find_by_id(263567474).unit_price).to eq("1") + + end end From 2d8c2bf7cfb97be5c49c4abbe9e6bfe482fd6049 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Thu, 2 Jun 2022 22:07:53 -0600 Subject: [PATCH 049/131] Feature/Test: add delete and delete test Co-authored-by: Thiago Co-authored-by: Kevin --- lib/item_repository.rb | 5 +++++ spec/item_repository_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index ca939307a3..2a9d40518c 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -69,4 +69,9 @@ def update(id, attributes) updated_item.unit_price = attributes[:unit_price] updated_item.description = attributes[:description] end + + def delete(id) + removed_item = find_by_id(id) + @all.delete(removed_item) + end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index f07b6136ef..d3285562f4 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -71,6 +71,12 @@ expect(item_repo.find_by_id(263567474).name).to eq("New Test Scarf") expect(item_repo.find_by_id(263567474).description).to eq("A beautiful testing scarf") expect(item_repo.find_by_id(263567474).unit_price).to eq("1") + end + it "can delete an item" do + item_repo = ItemRepository.new('./data/items.csv') + expect(item_repo.find_by_id(263567474)).to be_a(Item) + item_repo.delete(263567474) + expect(item_repo.find_by_id(263567474)).to eq(nil) end end From c453b3bb46cf37cb532d971075a2d5be141c3aac Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Fri, 3 Jun 2022 11:19:04 -0400 Subject: [PATCH 050/131] Fix spec to ensure acorrect amount of arguments were passed --- spec/merchant_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/merchant_spec.rb b/spec/merchant_spec.rb index 99d7a0bb35..6b228668fc 100644 --- a/spec/merchant_spec.rb +++ b/spec/merchant_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Merchant do it "exists" do - merchant = Merchant.new(1, "Bob's Burgers") + merchant = Merchant.new(:id => 1, :name => "Bob's Burgers") expect(merchant).to be_instance_of (Merchant) end From a1501646840217639161fe4771cc81e0235ecaee Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Fri, 3 Jun 2022 10:24:58 -0600 Subject: [PATCH 051/131] Feature: update create method and test to account for all elements of an object --- lib/item_repository.rb | 4 +++- spec/item_repository_spec.rb | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 2a9d40518c..a50c9d1581 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -1,4 +1,5 @@ require 'CSV' +require "BigDecimal" require './lib/item.rb' class ItemRepository @@ -59,7 +60,8 @@ def find_all_by_merchant_id(merchant_id) def create(attributes) new_id = @all.last.id.to_i + 1 new_attribute = attributes - @all << Item.new(:id => new_id.to_s, :name => new_attribute) + @all << Item.new(:id => new_id.to_s, :name => new_attribute[:name], :unit_price => + new_attribute[:unit_price], :description => new_attribute[:description], :created_at => Time.now) return @all.last end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index d3285562f4..aca136bf01 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -56,8 +56,13 @@ #Ask instructor if only adding a name for a new item is okay...Ran out of time lol. it "can create a new item with provided attributes" do item_repo = ItemRepository.new('./data/items.csv') - new_item = (item_repo.create("Oreos")) + new_item_attributes = {:name => "Oreos", :description => "a sandwich cookie", + :unit_price => "50", } + new_item = (item_repo.create(new_item_attributes)) expect(new_item.name).to eq("Oreos") + expect(new_item.unit_price).to eq("50") + expect(new_item.description).to eq("a sandwich cookie") + expect(new_item.created_at).to be_instance_of(Time) expect(item_repo.find_by_id(263567475)).to be_a(Item) end From 0268a2d1f109d923be27fe26e0fc7b3a18df940a Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Fri, 3 Jun 2022 10:41:49 -0600 Subject: [PATCH 052/131] Feature/Test: Addd updated at and test for updated at in item repository and item repository spec, had to change updated at to accessor --- lib/item.rb | 6 +++--- lib/item_repository.rb | 1 + spec/item_repository_spec.rb | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/item.rb b/lib/item.rb index d39dc245b4..0c77fe5269 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,12 +1,12 @@ class Item attr_reader :id, :created_at, - :updated_at, :merchant_id - + attr_accessor :name, :description, - :unit_price + :unit_price, + :updated_at def initialize(data) @id = data[:id] diff --git a/lib/item_repository.rb b/lib/item_repository.rb index a50c9d1581..6f21db9f02 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -70,6 +70,7 @@ def update(id, attributes) updated_item.name = attributes[:name] updated_item.unit_price = attributes[:unit_price] updated_item.description = attributes[:description] + updated_item.updated_at = Time.now end def delete(id) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index aca136bf01..68fe7913ff 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -76,6 +76,7 @@ expect(item_repo.find_by_id(263567474).name).to eq("New Test Scarf") expect(item_repo.find_by_id(263567474).description).to eq("A beautiful testing scarf") expect(item_repo.find_by_id(263567474).unit_price).to eq("1") + expect(item_repo.find_by_id(263567474).updated_at).to be_instance_of(Time) end it "can delete an item" do From 3641d0e333b26c60d2fe6a0111f125d5f610d5be Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Fri, 3 Jun 2022 10:57:07 -0600 Subject: [PATCH 053/131] Save to pull recent group work --- lib/item.rb | 2 +- lib/sales_analyst.rb | 4 ++ spec/item_repository.rb | 5 -- spec/item_spec.rb | 134 +------------------------------------ spec/sales_analyst_spec.rb | 35 ++++++++++ 5 files changed, 42 insertions(+), 138 deletions(-) create mode 100644 lib/sales_analyst.rb delete mode 100644 spec/item_repository.rb create mode 100644 spec/sales_analyst_spec.rb diff --git a/lib/item.rb b/lib/item.rb index 0e2ab001c4..d2236f679d 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -16,7 +16,7 @@ def initialize(item_attributes) def unit_price_to_dollars @unit_price.to_f end -======= + class Item attr_reader :id, :name, diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb new file mode 100644 index 0000000000..7072db863f --- /dev/null +++ b/lib/sales_analyst.rb @@ -0,0 +1,4 @@ +class SalesAnalyst +attr_reader + +def initialize diff --git a/spec/item_repository.rb b/spec/item_repository.rb deleted file mode 100644 index b025b6228c..0000000000 --- a/spec/item_repository.rb +++ /dev/null @@ -1,5 +0,0 @@ -require './spec/item_repository.rb' - -RSpec.describe ItemRepository do - -end diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 9090d3b265..b0cb7f1124 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -1,4 +1,4 @@ -<<<<<<< HEAD + require './lib/item.rb' require 'BigDecimal' RSpec.describe Item do @@ -11,7 +11,7 @@ :created_at => Time.now, :updated_at => Time.now, :merchant_id => 2 -}) + }) it 'exists' do expect(i).to be_a(Item) @@ -30,138 +30,8 @@ it 'returns the price of the item in dollars' do expect(i.unit_price_to_dollars).to eq(10.99) end -======= -require './lib/item' -require 'time' -require 'bigdecimal' - -RSpec.describe Item do - - it 'exists' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - - expect(i).to be_instance_of(Item) - end - - it 'returns the item id' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - - expect(i.id).to eq(1) - end - - it 'returns the item name' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - - expect(i.name).to eq("Pencil") - end - - it 'returns the item description' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - - expect(i.description).to eq("You can use it to write things") - end - - it 'returns the item unit price' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - - expect(i.unit_price).to eq(BigDecimal(10.99,4)) - end - - it 'returns the time the item was created' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now.round, - :updated_at => Time.now.round, - :merchant_id => 2 - }) - - expect(i.created_at).to eq(Time.now.round) - end - - it 'returns the time the item was updated' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now.round, - :updated_at => Time.now.round, - :merchant_id => 2 - }) - - expect(i.updated_at).to eq(Time.now.round) - end - it 'returns the merchant id' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - expect(i.merchant_id).to eq(2) - end - it 'returns the unit price as a float' do - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - - expect(i.unit_price_to_dollars).to eq(10.99) - end ->>>>>>> d60f6a0a63a73fa7870db962ee7545ed9f4d505f end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb new file mode 100644 index 0000000000..9414df797b --- /dev/null +++ b/spec/sales_analyst_spec.rb @@ -0,0 +1,35 @@ +require './lib/sales_analyst' +require './lib/sales_engine' + +RSpec.describe SalesAnalyst do + + sales_analyst = sales_engine.analyst + + it 'exists' do + expect(sales_analyst).to be_a(SalesAnalyst) + end + + it 'is able to find average items per merchant' do + expect(sales_analyst.average_items_per_merchant).to eq(2.88) + end + + it 'is able to find the standard deviation' do + expect (sales_analyst.average_items_per_merchant_standard_deviation).to eq(3.26) + end + + it 'is able to find merchants with high item counts' do + expect(sales_analyst.merchants_with_high_item_count).to eq(Merchant) + end + + it 'is able to find average price of merchant items' do + expect(sales_analyst.average_item_price_for_merchant(12334159)).to eq(BigDecimal) + end + + it 'is able to find average of average price per merchants' do + expect(sales_analyst.average_average_price_per_merchant).to eq(BigDecimal) + end + + it 'is able to find Golden items of merchants' do + expect(sales_analyst.golden_items). to eq(Item) + end +end From e3a0c63b561f21d3b417cce66c0fba85580005da Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Fri, 3 Jun 2022 11:03:58 -0600 Subject: [PATCH 054/131] Test: updated return an item by parts of a description to include a expect for a given length of the returned array --- spec/item_repository_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 68fe7913ff..968bc86a92 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -31,6 +31,9 @@ item_repo = ItemRepository.new('./data/items.csv') expect(item_repo.find_all_with_description("Disney")).to be_instance_of(Array) expect(item_repo.find_all_with_description("dISneY")).to be_instance_of(Array) + #This next one was tricky, I had to look through the items.csv, and filter + #out anything that wasn't a specific item (lots of pitches, dialogues) + expect(item_repo.find_all_with_description("Disney").length).to eq (5) expect(item_repo.find_all_with_description("Thiago")).to eq([]) end From 137388871fddc3db465e4e25aa08f5fa817d89ff Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Fri, 3 Jun 2022 11:23:41 -0600 Subject: [PATCH 055/131] Feature/test: changed find_all_by_price to item.unit_price, added test to reflect count --- lib/item_repository.rb | 2 +- spec/item_repository_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 6f21db9f02..bb4b8864fc 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -40,7 +40,7 @@ def find_all_with_description(description) def find_all_by_price(unit_price) @all.find_all do |item| - item.unit_price.include?(unit_price) + item.unit_price == unit_price end end diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 968bc86a92..fc9a83c27b 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -40,6 +40,7 @@ it "can find all items by price" do item_repo = ItemRepository.new('./data/items.csv') expect(item_repo.find_all_by_price("1300")).to be_instance_of(Array) + expect(item_repo.find_all_by_price("1300").count).to eq(8) expect(item_repo.find_all_by_price("1,000,000")).to eq([]) end From 25d35d83427a4770f809d37eb35261efc1729b69 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Fri, 3 Jun 2022 13:32:25 -0400 Subject: [PATCH 056/131] Change instance variables in spec so methods work --- spec/sales_engine_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/sales_engine_spec.rb b/spec/sales_engine_spec.rb index 23edb76cb3..4438df3ba3 100644 --- a/spec/sales_engine_spec.rb +++ b/spec/sales_engine_spec.rb @@ -2,14 +2,12 @@ require "./lib/item_repository" require "./lib/merchant_repository" -#You may need to add more `expect` lines to each test to make it more robust...! RSpec.describe SalesEngine do it "exists" do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", :merchants => "./data/merchants.csv" }) - require "pry"; binding.pry expect(sales_engine).to be_instance_of SalesEngine end @@ -19,7 +17,7 @@ :merchants => "./data/merchants.csv" }) - expect(sales_engine.item_repository).to be_instance_of ItemRepository + expect(sales_engine.items).to be_instance_of ItemRepository end it "can return an array of all merchants" do @@ -27,7 +25,7 @@ :items => "./data/items.csv", :merchants => "./data/merchants.csv" }) - expect(sales_engine.merchant_repository).to be_instance_of MerchantRepository + expect(sales_engine.merchants).to be_instance_of MerchantRepository end From ad9178be9bb3b8292a81db00ee356589a3636030 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Fri, 3 Jun 2022 11:44:47 -0600 Subject: [PATCH 057/131] Test: changed find all by merchant id in item repository spec to check for an array of a certain size --- spec/item_repository_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index fc9a83c27b..97c78a519a 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -54,6 +54,7 @@ item_repo = ItemRepository.new('./data/items.csv') merchant_repo = MerchantRepository.new('./data/merchants.csv') expect(item_repo.find_all_by_merchant_id(12334105)).to be_instance_of(Array) + expect(item_repo.find_all_by_merchant_id(12334105).length).to eq(3) expect(item_repo.find_all_by_merchant_id(12345678910112)).to eq([]) end From 368828ee7580ff6690a37ec615589a4f202917b1 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Fri, 3 Jun 2022 11:57:44 -0600 Subject: [PATCH 058/131] Fix merge conflict --- lib/item.rb | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/item.rb b/lib/item.rb index b3df99d900..ec4f445fe8 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,28 +1,12 @@ -<<<<<<< HEAD -require 'CSV' - -class Item - attr_reader :id, :name, :description, :unit_price, :created_at, :updated_at, :merchant_id - def initialize(item_attributes) - @id = item_attributes[:id].to_i - @name = item_attributes[:name] - @description = item_attributes[:description] - @unit_price = item_attributes[:unit_price] - @created_at = item_attributes[:created_at] - @updated_at = item_attributes[:updated_at] - @merchant_id = item_attributes[:merchant_id].to_i - end - def unit_price_to_dollars - @unit_price.to_f - end +require 'CSV' class Item attr_reader :id, :created_at, :updated_at, :merchant_id - + attr_accessor :name, :description, :unit_price @@ -40,5 +24,5 @@ def initialize(data) def unit_price_to_dollars @unit_price.to_f end ->>>>>>> d60f6a0a63a73fa7870db962ee7545ed9f4d505f + end From 723948fb646db5fc620268b6b2493a6fe7951d3a Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Fri, 3 Jun 2022 14:33:55 -0400 Subject: [PATCH 059/131] Add analyst method to SalesEngine class --- lib/sales_engine.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb index b498e17f87..eb51ba900a 100644 --- a/lib/sales_engine.rb +++ b/lib/sales_engine.rb @@ -10,4 +10,8 @@ def self.from_csv(data) return SalesEngine.new(data[:items], data[:merchants]) end + def analyst + return SalesAnalyst.new + end + end From 6b51a59e056606e39f1be84b017a2ebce58a78cb Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Fri, 3 Jun 2022 14:34:37 -0400 Subject: [PATCH 060/131] Create SalesAnalyst class --- lib/sales_analyst.rb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lib/sales_analyst.rb diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb new file mode 100644 index 0000000000..75fa8f91b4 --- /dev/null +++ b/lib/sales_analyst.rb @@ -0,0 +1,4 @@ +class SalesAnalyst + def initialize + end +end From 8d2e4224779b7c009388ab989cef3e266ac09ad0 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Fri, 3 Jun 2022 14:34:57 -0400 Subject: [PATCH 061/131] Create SalesAnalyst spec --- spec/sales_analyst_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/sales_analyst_spec.rb diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb new file mode 100644 index 0000000000..34291cbea2 --- /dev/null +++ b/spec/sales_analyst_spec.rb @@ -0,0 +1,29 @@ +require "./lib/sales_engine" +require "./lib/item_repository" +require "./lib/merchant_repository" +require "./lib/sales_analyst" + +RSpec.describe SalesAnalyst do + it 'exists' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst).to be_an_instance_of(SalesAnalyst) + end + + it 'can return the average items per merchant' do + #total items divided by total merchants + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_items_per_merchant).to eq(2.88) + + end + +end From e08e295deb2e4fdb42599cb9c68442f727e96397 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Fri, 3 Jun 2022 20:19:59 -0400 Subject: [PATCH 062/131] Edit analyst method --- lib/sales_engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb index eb51ba900a..6b24a0e065 100644 --- a/lib/sales_engine.rb +++ b/lib/sales_engine.rb @@ -11,7 +11,7 @@ def self.from_csv(data) end def analyst - return SalesAnalyst.new + return SalesAnalyst.new(items, merchants) end end From 04e8a2ccae229975374ceedc699caaaf898d304f Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Fri, 3 Jun 2022 18:21:04 -0600 Subject: [PATCH 063/131] work on sales analyst --- lib/sales_analyst.rb | 15 +++++++++++++-- spec/sales_analyst_spec.rb | 11 +++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 7072db863f..46db7ab51c 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -1,4 +1,15 @@ +require "./lib/sales_engine" +require "./lib/item_repository" +require "./lib/merchant_repository" + class SalesAnalyst -attr_reader + attr_reader :items, :merchants + def initialize(items, merchants) + @items = items + @merchants = merchants + end -def initialize + def average_items_per_merchant + items.all.count.to_f / merchants.all.count.to_f + end +end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 9414df797b..f0d381a12c 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -1,10 +1,17 @@ require './lib/sales_analyst' require './lib/sales_engine' +require './lib/sales_analyst' +require 'BigDecimal' RSpec.describe SalesAnalyst do + it 'exists' do + sales_engine = SalesEngine.from_csv({ + :item => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + end - sales_analyst = sales_engine.analyst - it 'exists' do expect(sales_analyst).to be_a(SalesAnalyst) end From 4c1e80a2ca5eb45b226829ec66c5e2d7a6d8d687 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Fri, 3 Jun 2022 20:24:10 -0400 Subject: [PATCH 064/131] Add average items per merchant and standard deviation Co-authored-by:Nick Jones Co-authored-by:Kevin Ta Co-authored-by:Thiago S --- lib/sales_analyst.rb | 36 +++++++++++++++++++++++++++++++++++- spec/sales_analyst_spec.rb | 10 ++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 75fa8f91b4..96f4ac1cdb 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -1,4 +1,38 @@ +require "./lib/sales_engine" +require "./lib/item_repository" +require "./lib/merchant_repository" +require "bigdecimal" + class SalesAnalyst - def initialize + attr_reader :items, :merchants + def initialize(items, merchants) + @items = items + @merchants = merchants end + + def average_items_per_merchant + average_number = items.all.count.to_f / merchants.all.count.to_f + return average_number.round(2) + end + + def items_by_merchant + items_per_merchant = Hash.new(0) + merchant_ids = items.all.map {|item| item.merchant_id} + merchant_ids.each do |id| + items_per_merchant[id] += 1 + end + return items_per_merchant + end + + + def average_items_per_merchant_standard_deviation + set = items_by_merchant.values + mean = average_items_per_merchant + sums = set.sum { |num| (num - mean)**2 } + std_dev = Math.sqrt(sums / (set.length - 1).to_f) + std_dev.round(2) + end + + + end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 34291cbea2..e5b0c77292 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -26,4 +26,14 @@ end + it 'can return the standard deviation of average items per merchant' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_items_per_merchant_standard_deviation).to eq(3.26) + end + end From 0f87e9e04aebfb5366cd21eba7f489bb4fad4167 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Fri, 3 Jun 2022 21:40:51 -0600 Subject: [PATCH 065/131] Test: Sales analyst can display the merchants who have the most items for sale Co-authored-by: Nick Co-authored-by: Kevin --- spec/sales_analyst_spec.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index e5b0c77292..6f1bd6c75e 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -23,7 +23,6 @@ sales_analyst = sales_engine.analyst expect(sales_analyst.average_items_per_merchant).to eq(2.88) - end it 'can return the standard deviation of average items per merchant' do @@ -32,8 +31,20 @@ :merchants => "./data/merchants.csv" }) sales_analyst = sales_engine.analyst - + expect(sales_analyst.average_items_per_merchant_standard_deviation).to eq(3.26) end + it 'can display the merchants who have the most items for sale' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.merchants_with_high_item_count).to be_a(Array) + # 52 was the length of our merchants_with_high_sales array + expect(sales_analyst.merchants_with_high_item_count.count).to eq(52) + end + end From bbe2e8588e76875fa0f9de473ca38b32e7b9ac1f Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Fri, 3 Jun 2022 21:41:52 -0600 Subject: [PATCH 066/131] Feat: Pass test sales analyst displays merchants who have the most items for sale Co-authored-by: Nick Co-authored-by: Kevin --- lib/sales_analyst.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 96f4ac1cdb..33be9f4726 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -24,7 +24,6 @@ def items_by_merchant return items_per_merchant end - def average_items_per_merchant_standard_deviation set = items_by_merchant.values mean = average_items_per_merchant @@ -33,6 +32,14 @@ def average_items_per_merchant_standard_deviation std_dev.round(2) end - + def merchants_with_high_item_count + standard_deviation = average_items_per_merchant_standard_deviation + mean_and_standard_dev = standard_deviation + average_items_per_merchant + merchants_with_high_sales = [] + items_by_merchant.each_pair do |merchant, items| + merchants_with_high_sales << merchant if items > mean_and_standard_dev + end + return merchants_with_high_sales + end end From e5b6c28eddc08b3b44da7a9590f14e1086dcc8bb Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Fri, 3 Jun 2022 22:25:53 -0600 Subject: [PATCH 067/131] Test: Sales analyst can return avg price of a merchants items Co-authored-by: Nick Co-authored-by: Kevin --- spec/sales_analyst_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 6f1bd6c75e..12eb51cf7f 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -47,4 +47,15 @@ expect(sales_analyst.merchants_with_high_item_count.count).to eq(52) end + it 'can return average price of a merchants items' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_item_price_for_merchant(12334159)).to be_a(BigDecimal) + expect(sales_analyst.average_item_price_for_merchant(12334159)).to eq(3150.0) + end + end From 15eecc0fced1ca7d054475f1e47c774a7a7efae6 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Fri, 3 Jun 2022 22:27:56 -0600 Subject: [PATCH 068/131] Feat: Pass test sales analyst returns avg price of a merchants items Co-authored-by: Nick Co-authored-by: Kevin --- lib/sales_analyst.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 33be9f4726..a72be17094 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -2,6 +2,7 @@ require "./lib/item_repository" require "./lib/merchant_repository" require "bigdecimal" +require "bigdecimal/util" class SalesAnalyst attr_reader :items, :merchants @@ -42,4 +43,12 @@ def merchants_with_high_item_count return merchants_with_high_sales end + def average_item_price_for_merchant(merchant_id) + find_merchant = @items.find_all_by_merchant_id(merchant_id) + items_sum = find_merchant.sum do |item| + item.unit_price.to_f + end + (items_sum / find_merchant.count).to_d(3) + end + end From 0ea782f60a47145ae71cd266697cf4071fbd92cc Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Fri, 3 Jun 2022 23:15:51 -0600 Subject: [PATCH 069/131] Test/Feat: Sales analyst can return avg of the avg prices per merchant Co-authored-by: Nick Co-authored-by: Kevin --- lib/sales_analyst.rb | 9 +++++++++ spec/sales_analyst_spec.rb | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index a72be17094..d4e375dabc 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -51,4 +51,13 @@ def average_item_price_for_merchant(merchant_id) (items_sum / find_merchant.count).to_d(3) end + def average_average_price_per_merchant + merchant_price_sums = [] + merchant_ids = items.all.map {|item| item.merchant_id.to_i} + merchant_ids.each do |id| + merchant_price_sums << average_item_price_for_merchant(id).to_f + end + (merchant_price_sums.sum / merchant_price_sums.size).to_d(3) + end + end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 12eb51cf7f..b41a78bb1f 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -58,4 +58,15 @@ expect(sales_analyst.average_item_price_for_merchant(12334159)).to eq(3150.0) end + it 'can return average of the average price per merchant' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_average_price_per_merchant).to be_a(BigDecimal) + expect(sales_analyst.average_average_price_per_merchant).to eq(0.251e5) #(25108.91441111924) + end + end From 523442b59d54e453df5049f7e603575bd2c8a13c Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Fri, 3 Jun 2022 23:56:16 -0600 Subject: [PATCH 070/131] In Progress: Sales analyst can return golden items Co-authored-by: Nick Co-authored-by: Kevin --- lib/all_items.csv | 1367 ++++++++++++++++++++++++++++++++++++ lib/sales_analyst.rb | 22 + spec/sales_analyst_spec.rb | 10 + 3 files changed, 1399 insertions(+) create mode 100644 lib/all_items.csv diff --git a/lib/all_items.csv b/lib/all_items.csv new file mode 100644 index 0000000000..a626a97a43 --- /dev/null +++ b/lib/all_items.csv @@ -0,0 +1,1367 @@ +1200, + 1300, + 1350, + 700, + 2999, + 14900, + 1490, + 690, + 40000, + 13000, + 399, + 8000, + 60000, + 65000, + 4000, + 2390, + 50000, + 2390, + 50000, + 8000, + 2390, + 55000, + 11900, + 60000, + 2400, + 4800, + 60000, + 4995, + 2000, + 1200, + 5000, + 5000, + 11000, + 3000, + 60000, + 15000, + 3700, + 20000, + 40000, + 3000, + 17000, + 7000, + 2500, + 17000, + 2500, + 2000, + 2000, + 2000, + 16150, + 2000, + 5000, + 2500, + 25000, + 4900, + 2500, + 300000, + 86000, + 72000, + 500, + 4999, + 12000, + 19, + 6000, + 300, + 1000, + 5000, + 1000, + 4500, + 4500, + 300, + 7000, + 2500, + 6000, + 2199, + 2600, + 2100, + 10000, + 495, + 7500, + 795, + 4000, + 22500, + 3000, + 15000, + 15000, + 795, + 7500, + 7500, + 795, + 7500, + 10000, + 10000, + 15000, + 795, + 199, + 7500, + 3000, + 495, + 5000, + 10000, + 15000, + 11000, + 15000, + 7500, + 3500, + 7500, + 7500, + 795, + 1000, + 1500, + 11000, + 1500, + 75, + 46000, + 9999900, + 4000, + 1000, + 390, + 14900, + 1500, + 1500, + 54900, + 245, + 2500, + 25000, + 14900, + 2000, + 4800, + 14900, + 3000, + 4000, + 3000, + 250, + 1200, + 150, + 245, + 9500, + 14900, + 160000, + 245, + 1200, + 900, + 4000, + 50000, + 600, + 3000, + 250, + 2500, + 245, + 800, + 50000, + 24900, + 9000, + 1499, + 800, + 250, + 800, + 3000, + 12500, + 12000, + 3000, + 12000, + 700, + 16000, + 400, + 4500, + 4000, + 16000, + 100000, + 250000, + 16000, + 2500, + 1200, + 2500, + 2495, + 89500, + 5000, + 1250, + 190000, + 2999, + 995, + 3000, + 1500, + 2800, + 1495, + 22500, + 19900, + 4500, + 4000, + 1800, + 1750, + 2500, + 2500, + 13500, + 3000, + 2500, + 8000, + 5000, + 1500, + 1699, + 370, + 400, + 135000, + 2050, + 5500, + 1295, + 3500, + 1000, + 4500, + 2500, + 3200, + 145000, + 180000, + 1000, + 3995, + 2700, + 40000, + 1500, + 4000, + 145000, + 6000, + 1800, + 15000, + 10000, + 2700, + 3000, + 150000, + 250, + 125000, + 1000, + 995, + 12500, + 1500, + 1790, + 10000, + 1790, + 1790, + 320000, + 4990, + 2000, + 1200, + 400, + 80000, + 50000, + 1790, + 400, + 7500, + 1790, + 400, + 1790, + 50000, + 70000, + 3000, + 80000, + 1790, + 40000, + 1790, + 3900, + 400, + 3000, + 25000, + 1000, + 500, + 5000, + 7500, + 2900, + 28000, + 895, + 1695, + 15000, + 25000, + 4000, + 4000, + 1900, + 500, + 16800, + 1000, + 700, + 6500, + 1000, + 10000, + 1900, + 25000, + 6500, + 7000, + 2450, + 3000, + 2000, + 990, + 8000, + 900, + 3500, + 20000, + 1200, + 1899, + 7500, + 4599, + 4000, + 100000, + 3800, + 600, + 5000, + 14900, + 500, + 1300, + 10999, + 1200, + 2995, + 4800, + 500, + 1500, + 500, + 5000, + 500, + 9900, + 6999, + 3500, + 500, + 1400, + 1900, + 1297, + 4900, + 9000, + 1000, + 2800, + 1500, + 1499, + 970, + 1200, + 2500, + 7999, + 15000, + 6800, + 3500, + 3900, + 2000, + 2500, + 1399, + 12000, + 500, + 4000, + 1200, + 9500, + 10000, + 20000, + 2000, + 4800, + 9000, + 10000, + 1500, + 1000, + 1500, + 5000, + 200000, + 4000, + 1000, + 1500, + 6500, + 700, + 8500, + 1200, + 1990, + 3000, + 1200, + 3200, + 17500, + 18500, + 1200, + 3000, + 16000, + 4990, + 9500, + 400, + 4000, + 4000, + 1000, + 4800, + 2400, + 300, + 6000, + 16000, + 2200, + 3000, + 250, + 1000, + 1700, + 500, + 4500, + 800, + 3995, + 16000, + 1999, + 800, + 1000, + 4999, + 3000, + 3400, + 2500, + 400, + 17000, + 2500, + 2400, + 6000, + 4500, + 1260, + 2700, + 1000, + 8000, + 1000, + 1500, + 5760, + 1000, + 1599, + 2500, + 220, + 499, + 2700, + 3860, + 3500, + 22000, + 800, + 6000, + 1500, + 1570, + 2500, + 18000, + 450, + 900, + 1000, + 1000, + 1000, + 16000, + 17000, + 4000, + 2700, + 23000, + 37500, + 2500, + 750, + 1000, + 1500, + 6500, + 695, + 2500, + 2700, + 5470, + 1000, + 3970, + 4970, + 1500, + 600, + 2500, + 2500, + 2000, + 2300, + 1900, + 11000, + 2000, + 3500, + 500, + 59500, + 11770, + 2000, + 1900, + 1200, + 750, + 500, + 4000, + 800, + 2500, + 1300, + 900, + 9000, + 1200, + 749500, + 1500, + 30000, + 2500, + 2500, + 52900, + 6000, + 2100, + 125000, + 30000, + 27000, + 1500, + 1000, + 1100, + 2000, + 7500, + 8500, + 1900, + 1500, + 12000, + 890, + 11000, + 8000, + 600, + 1000, + 3500, + 1000, + 28000, + 1900, + 32900, + 9000, + 1500, + 3500, + 7500, + 700, + 1900, + 1300, + 3500, + 4995, + 600, + 650, + 900, + 600, + 2500, + 1000, + 2000, + 2500, + 2000, + 4995, + 47500, + 3500, + 4400, + 1400, + 2500, + 8000, + 47500, + 2499500, + 2500, + 695, + 200, + 700, + 750, + 5495, + 4000, + 4995, + 4500, + 1000, + 36500, + 2000, + 595, + 1500, + 8000, + 750, + 1900, + 3500, + 29500, + 4995, + 1050, + 1500, + 5800, + 599, + 1995, + 750, + 350000, + 1900, + 2100, + 750, + 60300, + 1300, + 395, + 30000, + 3500, + 119500, + 2500, + 59400, + 15000, + 24500, + 4500, + 1500, + 1500, + 500, + 3500, + 79400, + 3000, + 1815, + 2000, + 4995, + 1500, + 795, + 28200, + 30000, + 450, + 40600, + 4000, + 2000, + 1800, + 4000, + 14900, + 1150, + 495, + 6000, + 1400, + 600, + 1505, + 1200, + 3600, + 3500, + 28200, + 2000, + 250, + 36900, + 2000, + 1500, + 9000, + 93800, + 4000, + 3000, + 4000, + 20000, + 495, + 550000, + 30000, + 1200, + 4995, + 5000, + 62500, + 4200, + 1500, + 1000, + 2500, + 4995, + 5000, + 6000, + 51300, + 2500, + 3000, + 50000, + 1500, + 500, + 1600, + 2200, + 3000, + 1000, + 4500, + 2000, + 22500, + 19900, + 1200, + 2500, + 300, + 3000, + 35000, + 500, + 2500, + 900, + 300, + 19500, + 1500, + 25000, + 2000, + 10000, + 1800, + 75000, + 10000, + 720, + 600, + 50000, + 6900, + 250, + 60000, + 4900, + 999, + 1400, + 3500, + 50000, + 4500, + 60000, + 999, + 6000, + 50000, + 1500, + 1890, + 20000, + 7000, + 2390, + 2500, + 15300, + 10000, + 790, + 2500, + 600, + 16900, + 2600, + 3600, + 1500, + 65000, + 72000, + 5999, + 15000, + 3500, + 200, + 2500, + 3500, + 5800, + 2000, + 1400, + 10000, + 2500, + 4500, + 5000, + 200, + 300, + 5000, + 15000, + 5000, + 500, + 2000, + 2500, + 250, + 10000, + 1800, + 5000, + 200000, + 2000, + 495, + 180000, + 4290, + 500, + 45000, + 5000, + 10000, + 15000, + 86000, + 15000, + 795, + 900, + 15000, + 495, + 7500, + 2100, + 10000, + 7500, + 495, + 10000, + 250, + 495, + 795, + 20000, + 6000, + 795, + 7500, + 999, + 5000, + 20000, + 7500, + 7500, + 6500, + 1800, + 795, + 600, + 6000, + 8000, + 245, + 7500, + 2500, + 1730, + 1000, + 8000, + 1000, + 245, + 1200, + 1000, + 250, + 1200, + 245, + 100, + 1000, + 245, + 500, + 20000, + 12000, + 3500, + 2500, + 2500, + 5000, + 2500, + 245, + 2500, + 14900, + 5000, + 3000, + 5000, + 2200, + 3400, + 800, + 3000, + 7800, + 6000, + 80000, + 800, + 3000, + 250, + 800, + 1400, + 3000, + 2000, + 7500, + 110000, + 350, + 3500, + 16000, + 3000, + 16000, + 1200, + 1000, + 3500, + 110000, + 3500, + 16000, + 80000, + 6000, + 25000, + 1800, + 3500, + 3000, + 2300, + 800, + 1900, + 9000, + 1000, + 2700, + 800, + 100, + 5599, + 6000, + 9900, + 150000, + 2500, + 19000, + 1150, + 1200, + 11000, + 4000, + 1769, + 1500, + 2500, + 2200, + 800, + 3000, + 700, + 12500, + 1499, + 3200, + 1500, + 3000, + 4500, + 1499, + 250, + 1500, + 5000, + 15000, + 8000, + 2500, + 9500, + 45000, + 19500, + 7000, + 2346, + 1500, + 1000, + 30000, + 5000, + 145000, + 1200, + 250, + 3500, + 3200, + 2000, + 2700, + 1400, + 35000, + 2000, + 3000, + 1395, + 80000, + 100, + 1200, + 1800, + 150000, + 9500, + 500, + 5900, + 1790, + 15000, + 3000, + 70000, + 1790, + 15000, + 250, + 10000, + 1200, + 3000, + 4900, + 400, + 600, + 20000, + 1595, + 1000, + 55000, + 7000, + 695, + 16500, + 45000, + 2200, + 2000, + 400, + 2500, + 500, + 10000, + 2500, + 400, + 3500, + 1200, + 3300, + 5000, + 3000, + 500, + 25000, + 1299, + 900, + 250, + 2500, + 500, + 10000, + 6500, + 9500, + 7500, + 1200, + 2500, + 1400, + 1700, + 35000, + 7000, + 8000, + 5500, + 89500, + 5900, + 500000, + 5000, + 80000, + 6000, + 600, + 5000, + 900, + 5000, + 2900, + 5999, + 5000, + 2500, + 15000, + 1000, + 1200, + 500, + 30000, + 500, + 140000, + 250, + 7500, + 6800, + 700, + 500, + 400, + 600, + 1000, + 5500, + 800, + 40000, + 500, + 500, + 1000, + 4000, + 500, + 2000, + 1000, + 2500, + 32000, + 8500, + 7999, + 7500, + 80000, + 1000, + 400, + 1500, + 27500, + 4800, + 10000, + 900, + 1000, + 5800, + 1200, + 2900, + 1199, + 1300, + 16000, + 200000, + 2500, + 1200, + 600, + 600, + 15000, + 1800, + 2000, + 800, + 9000, + 35000, + 3000, + 1500, + 2000, + 2500, + 700, + 3500, + 4000, + 499, + 4500, + 13000, + 1795, + 1000, + 120000, + 15000, + 45000, + 4500, + 2500, + 9000, + 500, + 650, + 12500, + 5000, + 3500, + 1500, + 1500, + 400, + 400, + 9000, + 2500, + 12500, + 59500, + 5000, + 400, + 2500, + 16300, + 800, + 1500, + 400, + 2500, + 1000, + 400, + 3000, + 800, + 15000, + 400, + 2500, + 40000, + 5499, + 25000, + 250, + 120000, + 3500, + 2500, + 8500, + 3500, + 5000, + 450, + 3400, + 1799, + 3400, + 1000, + 3900, + 10000, + 3000, + 3400, + 450, + 29500, + 112000, + 5900, + 1000, + 1000, + 1000, + 3500, + 2500, + 1300, + 1400, + 3500, + 3995, + 400, + 1500, + 1500, + 85000, + 2500, + 2500, + 1500, + 3000, + 450, + 10000, + 1000, + 2000, + 1000, + 400, + 34900, + 6000, + 4500, + 8500, + 1200, + 99500, + 2400, + 4000, + 2200, + 1000, + 10000, + 29500, + 22000, + 2100, + 900, + 400, + 500, + 19900, + 4500, + 1900, + 2500, + 800, + 8000, + 599, + 500, + 29500, + 1900, + 1599, + 900, + 11000, + 80000, + 23999, + 3500, + 59500, + 3500, + 2400, + 1500, + 1900, + 3000, + 7500, + 3500, + 699, + 3500, + 500000, + 3500, + 999, + 4970, + 29900, + 4800, + 17500, + 3500, + 3500, + 2700, + 16500, + 8000, + 4500, + 890, + 25000, + 1599, + 1000, + 55999, + 30000, + 2499, + 2500, + 3500, + 310000, + 3000, + 650, + 800, + 3000, + 1200, + 27000, + 39900, + 1000, + 1200, + 500, + 800, + 1500, + 8000, + 79500, + 1900, + 999, + 9500, + 1500, + 3000, + 2100, + 2195, + 1500, + 2000, + 2000, + 599, + 2000, + 1000, + 2000, + 3000, + 10000, + 800, + 600, + 890, + 3500, + 1500, + 400, + 1400, + 1000, + 2000, + 1900, + 695, + 8000, + 2500, + 15000, + 500, + 2499500, + 8000, + 2000, + 6200, + 599, + 100, + 3500, + 500, + 800, + 1200, + 1500, + 6500, + 3500, + 6000, + 250000, + 8000, + 4995, + 1100, + 1500, + 700, + 8000, + 2500, + 1200, + 2000, + 4000, + 1500, + 9500, + 650, + 250, + 6500, + 450, + 4995, + 1300, + 90000, + 3500, + 1000, + 1500, + 125000, + 1500, + 500, + 24000, + 2500, + 1200, + 4400, + 2500, + 1900, + 3500, + 1800, + 1205, + 999, + 7000, + 4995, + 1000, + 40000, + 2000, + 2500, + 2000, + 31800, + 20000, + 595, + 3500, + 1500, + 2500, + 4499, + 4995, + 700000, + 3500, + 4000, + 795, + 23000, + 1200, + 4000, + 30000, + 1505, + 50000, + 2500, + 1600, + 2500, + 1200, + 1500, + 3500, + 1500, + 21000, + 3000, + 2500, + 29500, + 200, + 29900, + 3400, + 6500, + 1800, + 3600, + 1250, + 2000, + 550, + 22000, + 2000, + 5000, + 5000, + 4000, + 20000, + 2000, + 3499, + 4000, + 3200, + 4000, + 1995, + 28000, + 4900, + 5000, + 2500, + 22500, + 4000, + 2995, + 1400, + 71900, + 5000, + 23000, + 18000, + 2000, + 1499, + 395, + 1800, + 1200, + 6999, + 4000, + 13000, + 2500, + 795, + 13000, + 3000, + 1200, + 25000, + 500, + 25000, + 1000, + 1199, + 2500, + 10000, + 1500, + 5000, + 4500, + 1000, + 9500, + 1200, + 999, + 7500, + 3000, + 2000, + 1000, + 2750, + 2999, + 6100, + 25000, + 3800 diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index d4e375dabc..49862aa476 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -60,4 +60,26 @@ def average_average_price_per_merchant (merchant_price_sums.sum / merchant_price_sums.size).to_d(3) end + def golden_items + require "pry"; binding.pry + average_item_price_per_merchant_standard_deviation + + # standard_deviation = average_items_per_merchant_standard_deviation + # golden_item_standard = standard_deviation + average_average_price_per_merchant + # merchants_with_high_sales = [] + # items_by_merchant.each_pair do |merchant, items| + # merchants_with_high_sales << merchant if items > mean_and_standard_dev + # end + # return merchants_with_high_sales + end + + def average_item_price_per_merchant_standard_deviation + array_of_all_prices = @items.all.map {|item| item.unit_price.to_i} + set = array_of_all_prices + mean = array_of_all_prices.sum / array_of_all_prices.size + sums = set.sum { |num| (num - mean)**2 } + std_dev = Math.sqrt(sums / (set.length - 1).to_f) + std_dev.round(2) + end + end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index b41a78bb1f..13b21a149b 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -69,4 +69,14 @@ expect(sales_analyst.average_average_price_per_merchant).to eq(0.251e5) #(25108.91441111924) end + it 'can return the golden items' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.golden_items).to be_a(Array) + end + end From ea8d635f9789466b9796ee1e8320d26e768a477c Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 15:28:22 -0600 Subject: [PATCH 071/131] Test: added a test for standard deviation method, and test for returning golden items --- spec/sales_analyst_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 13b21a149b..159bf23e5c 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -69,6 +69,15 @@ expect(sales_analyst.average_average_price_per_merchant).to eq(0.251e5) #(25108.91441111924) end + it "can return a standard deviation" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv" + }) + sales_analyst = sales_engine.analyst + expect(sales_analyst.standard_deviation([1, 2 ,3], 2)).to eq(1) + end + it 'can return the golden items' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", From e5d491a5a3925ffc588b5fcc98047a8822c1a323 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 15:29:00 -0600 Subject: [PATCH 072/131] Feature: added standard deviation method, and method to return golden items in an array --- lib/sales_analyst.rb | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 49862aa476..e191fc1c4e 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -60,26 +60,19 @@ def average_average_price_per_merchant (merchant_price_sums.sum / merchant_price_sums.size).to_d(3) end - def golden_items - require "pry"; binding.pry - average_item_price_per_merchant_standard_deviation - - # standard_deviation = average_items_per_merchant_standard_deviation - # golden_item_standard = standard_deviation + average_average_price_per_merchant - # merchants_with_high_sales = [] - # items_by_merchant.each_pair do |merchant, items| - # merchants_with_high_sales << merchant if items > mean_and_standard_dev - # end - # return merchants_with_high_sales - end + def standard_deviation(values, mean) + sums = values.sum { |value| (value - mean)**2 } + std_dev = Math.sqrt(sums / (values.length - 1).to_f) + std_dev.round(2) + end - def average_item_price_per_merchant_standard_deviation + def golden_items array_of_all_prices = @items.all.map {|item| item.unit_price.to_i} set = array_of_all_prices mean = array_of_all_prices.sum / array_of_all_prices.size - sums = set.sum { |num| (num - mean)**2 } - std_dev = Math.sqrt(sums / (set.length - 1).to_f) - std_dev.round(2) + std_dev = standard_deviation(set, mean) + minimum_golden_price = mean += (2 * std_dev) + items.all.find_all{ |item| item.unit_price.to_i > minimum_golden_price } end end From 8d1f53f837b3428110333d4b18ab940a7b485734 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 16:06:09 -0600 Subject: [PATCH 073/131] Fix: changed require in lib files to require relative Co-authored-by: Thiago --- lib/{all_items.csv => all_items_test_file.csv} | 0 lib/item_repository.rb | 2 +- lib/merchant_repository.rb | 2 +- lib/sales_analyst.rb | 6 +++--- spec/item_repository_spec.rb | 1 - 5 files changed, 5 insertions(+), 6 deletions(-) rename lib/{all_items.csv => all_items_test_file.csv} (100%) diff --git a/lib/all_items.csv b/lib/all_items_test_file.csv similarity index 100% rename from lib/all_items.csv rename to lib/all_items_test_file.csv diff --git a/lib/item_repository.rb b/lib/item_repository.rb index bb4b8864fc..6fd23bcfd3 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -1,6 +1,6 @@ require 'CSV' require "BigDecimal" -require './lib/item.rb' +require_relative'./item.rb' class ItemRepository attr_reader :all diff --git a/lib/merchant_repository.rb b/lib/merchant_repository.rb index 9fdeb72c2d..b99a4312bb 100644 --- a/lib/merchant_repository.rb +++ b/lib/merchant_repository.rb @@ -1,5 +1,5 @@ require 'CSV' -require './lib/merchant.rb' +require_relative './merchant.rb' class MerchantRepository attr_reader :all def initialize(file_path) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index e191fc1c4e..2d210163f3 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -1,6 +1,6 @@ -require "./lib/sales_engine" -require "./lib/item_repository" -require "./lib/merchant_repository" +require_relative "./sales_engine" +require_relative "./item_repository" +require_relative "./merchant_repository" require "bigdecimal" require "bigdecimal/util" diff --git a/spec/item_repository_spec.rb b/spec/item_repository_spec.rb index 97c78a519a..e421bd199f 100644 --- a/spec/item_repository_spec.rb +++ b/spec/item_repository_spec.rb @@ -58,7 +58,6 @@ expect(item_repo.find_all_by_merchant_id(12345678910112)).to eq([]) end - #Ask instructor if only adding a name for a new item is okay...Ran out of time lol. it "can create a new item with provided attributes" do item_repo = ItemRepository.new('./data/items.csv') new_item_attributes = {:name => "Oreos", :description => "a sandwich cookie", From 88f8d0363699aee4cffdcc4473bf950d38e7d2b2 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 16:26:43 -0600 Subject: [PATCH 074/131] Test: add test for it exists for invoice Co-authored-by: Thiago --- lib/invoice.rb | 2 ++ spec/invoice_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 lib/invoice.rb create mode 100644 spec/invoice_spec.rb diff --git a/lib/invoice.rb b/lib/invoice.rb new file mode 100644 index 0000000000..194df07139 --- /dev/null +++ b/lib/invoice.rb @@ -0,0 +1,2 @@ +class Invoice +end diff --git a/spec/invoice_spec.rb b/spec/invoice_spec.rb new file mode 100644 index 0000000000..c17d4d76c4 --- /dev/null +++ b/spec/invoice_spec.rb @@ -0,0 +1,16 @@ +require './lib/item' +require 'time' +require 'bigdecimal' + +RSpec.describe Invoice do + + it "exists" do + inv = Invoice.new({ :id => 1, + :name => "Pencil", + :description => "You can use it to write things", + :unit_price => BigDecimal(10.99,4), + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 2}) + end +end From ba1beda3f9720dd85563f58c64ba3e2017b4b258 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 16:43:20 -0600 Subject: [PATCH 075/131] Test: add test for returning the ID Co-authored-by: Thiago --- lib/invoice.rb | 17 +++++++++++++++++ spec/invoice_spec.rb | 25 ++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/lib/invoice.rb b/lib/invoice.rb index 194df07139..b9785abe13 100644 --- a/lib/invoice.rb +++ b/lib/invoice.rb @@ -1,2 +1,19 @@ class Invoice + +attr_reader :id, + :customer_id, + :status, + :created_at, + :updated_at, + :merchant_id + + + def initialize(data) + @id = data[:id] + @customer_id = data[:customer_id] + @status = data[:status] + @created_at = data[:created_at] + @updated_at = data[:updated_at] + @merchant_id = data[:merchant_id] + end end diff --git a/spec/invoice_spec.rb b/spec/invoice_spec.rb index c17d4d76c4..a279f185fb 100644 --- a/spec/invoice_spec.rb +++ b/spec/invoice_spec.rb @@ -1,16 +1,31 @@ require './lib/item' require 'time' require 'bigdecimal' +require './lib/invoice.rb' RSpec.describe Invoice do it "exists" do - inv = Invoice.new({ :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), + inv = Invoice.new({ + :id => 6, + :customer_id => 7, + :status => "pending", :created_at => Time.now, :updated_at => Time.now, - :merchant_id => 2}) + :merchant_id => 8}) + + expect(inv).to be_instance_of(Invoice) + end + + it "returns the id" do + inv = Invoice.new({ + :id => 6, + :customer_id => 7, + :status => "pending", + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 8}) + + expect(inv.id).to eq(6) end end From 3fe6ffdf34af6da9e5f9a8e6f97c28eb742c578e Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 17:09:07 -0600 Subject: [PATCH 076/131] Test: finished tests and methods for invoice.rb Co-authored-by: Thiago --- spec/invoice_spec.rb | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spec/invoice_spec.rb b/spec/invoice_spec.rb index a279f185fb..84f543c495 100644 --- a/spec/invoice_spec.rb +++ b/spec/invoice_spec.rb @@ -28,4 +28,53 @@ expect(inv.id).to eq(6) end + + it "returns the customer_id" do + inv = Invoice.new({ + :id => 6, + :customer_id => 7, + :status => "pending", + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 8}) + + expect(inv.customer_id).to eq(7) + end + + it "returns the merchant_id" do + inv = Invoice.new({ + :id => 6, + :customer_id => 7, + :status => "pending", + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 8}) + + expect(inv.merchant_id).to eq(8) + end + + it "returns the status" do + inv = Invoice.new({ + :id => 6, + :customer_id => 7, + :status => "pending", + :created_at => Time.now, + :updated_at => Time.now, + :merchant_id => 8}) + + expect(inv.status).to eq("pending") + end + + it "returns the time updated at and created at" do + inv = Invoice.new({ + :id => 6, + :customer_id => 7, + :status => "pending", + :created_at => Time.now.round, + :updated_at => Time.now.round, + :merchant_id => 8}) + + expect(inv.created_at).to eq(Time.now.round) + expect(inv.updated_at).to eq(Time.now.round) + end end From ec33de36d0e25cc170de61b9d621d9703cf8bbce Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 17:22:18 -0600 Subject: [PATCH 077/131] Test: refactored sales engine class to account for tests for invoice and invoice repo Co-authored-by: Thiago --- lib/invoice_repository.rb | 9 +++++++++ lib/sales_analyst.rb | 5 +++-- lib/sales_engine.rb | 9 +++++---- spec/sales_engine_spec.rb | 22 +++++++++++++++++++--- 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 lib/invoice_repository.rb diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb new file mode 100644 index 0000000000..2b9ece99b6 --- /dev/null +++ b/lib/invoice_repository.rb @@ -0,0 +1,9 @@ +require 'CSV' +require "BigDecimal" +require_relative'./invoice.rb' + +class InvoiceRepository + def initialize(invoice_path) + @invoice_path = invoice_path + end +end diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 2d210163f3..e857d70e6b 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -5,10 +5,11 @@ require "bigdecimal/util" class SalesAnalyst - attr_reader :items, :merchants - def initialize(items, merchants) + attr_reader :items, :merchants, :invoices + def initialize(items, merchants, invoices) @items = items @merchants = merchants + @invoices = invoices end def average_items_per_merchant diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb index 6b24a0e065..4edcc015df 100644 --- a/lib/sales_engine.rb +++ b/lib/sales_engine.rb @@ -1,17 +1,18 @@ class SalesEngine - attr_reader :items, :merchants + attr_reader :items, :merchants, :invoices - def initialize(items_path, merchants_path) + def initialize(items_path, merchants_path, invoice_path) @items = ItemRepository.new(items_path) @merchants = MerchantRepository.new(merchants_path) + @invoices = InvoiceRepository.new(invoice_path) end def self.from_csv(data) - return SalesEngine.new(data[:items], data[:merchants]) + return SalesEngine.new(data[:items], data[:merchants], data[:invoices]) end def analyst - return SalesAnalyst.new(items, merchants) + return SalesAnalyst.new(items, merchants, invoices) end end diff --git a/spec/sales_engine_spec.rb b/spec/sales_engine_spec.rb index 4438df3ba3..a100aa1804 100644 --- a/spec/sales_engine_spec.rb +++ b/spec/sales_engine_spec.rb @@ -1,12 +1,14 @@ require "./lib/sales_engine" require "./lib/item_repository" require "./lib/merchant_repository" +require "./lib/invoice_repository" RSpec.describe SalesEngine do it "exists" do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) expect(sales_engine).to be_instance_of SalesEngine end @@ -14,7 +16,9 @@ it "can return an array of all items" do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) expect(sales_engine.items).to be_instance_of ItemRepository @@ -23,10 +27,22 @@ it "can return an array of all merchants" do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) expect(sales_engine.merchants).to be_instance_of MerchantRepository end + it "can return an array of all merchants" do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + + }) + expect(sales_engine.invoices).to be_instance_of InvoiceRepository + + end end From b32b258477acb93596c0d6a65de1b8c635501ef0 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 17:35:42 -0600 Subject: [PATCH 078/131] Test: create test for invoice repository, it exists Co-authored-by: Thiago --- lib/invoice_repository.rb | 11 +++++++++++ spec/invoice_repository_spec.rb | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 spec/invoice_repository_spec.rb diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index 2b9ece99b6..d9f5bd00fe 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -5,5 +5,16 @@ class InvoiceRepository def initialize(invoice_path) @invoice_path = invoice_path + @all_invoices = [] + + CSV.foreach(@invoice_path, headers: true, header_converters: :symbol) do |row| + @all_invoices << Invoice.new({ + :id => row[:id], + :customer_id => row[:customer_id], + :status => row[:status], + :created_at => row[:created_at], + :updated_at => row[:updated_at], + :merchant_id => row[:merchant_id]}) + end end end diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb new file mode 100644 index 0000000000..6c2b385103 --- /dev/null +++ b/spec/invoice_repository_spec.rb @@ -0,0 +1,13 @@ +require './lib/item.rb' +require './lib/item_repository' +require './lib/merchant_repository' +require './lib/merchant' +require './lib/invoice' +require './lib/invoice_repository' + +RSpec.describe InvoiceRepository do + it "exists" do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + expect(invoice_repo).to be_a(InvoiceRepository) + end +end From bdce1c65b3491eb92a3670f098c7dc2074bb23e6 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 17:51:42 -0600 Subject: [PATCH 079/131] Test: add test for returning an array of all invoices and finding an invoice by id Co-authored-by: Thiago --- lib/invoice_repository.rb | 7 ++++--- spec/invoice_repository_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index d9f5bd00fe..4dcab64fc6 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -1,14 +1,15 @@ require 'CSV' require "BigDecimal" require_relative'./invoice.rb' - class InvoiceRepository + attr_reader :all + def initialize(invoice_path) @invoice_path = invoice_path - @all_invoices = [] + @all = [] CSV.foreach(@invoice_path, headers: true, header_converters: :symbol) do |row| - @all_invoices << Invoice.new({ + @all << Invoice.new({ :id => row[:id], :customer_id => row[:customer_id], :status => row[:status], diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index 6c2b385103..0e8440879e 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -6,8 +6,20 @@ require './lib/invoice_repository' RSpec.describe InvoiceRepository do + it "exists" do invoice_repo = InvoiceRepository.new('./data/invoices.csv') expect(invoice_repo).to be_a(InvoiceRepository) end + + it "can return an array of all invoices" do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + expect(invoice_repo.all.count).to eq(4985) + end + + it "can find a invoice by an id" do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + expect(invoice_repo.find_by_id(1)).to be_a(Invoice) + expect(invoice_repo.find_by_id(123542345293423)).to eq(nil) + end end From 86430130e533d21872f9f40b1e86a6534cd21070 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 17:58:19 -0600 Subject: [PATCH 080/131] Test: add test to item repository spec for finding all invoices by specific customer id Co-authored-by: Thiago --- lib/invoice_repository.rb | 6 ++++++ spec/invoice_repository_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index 4dcab64fc6..ff284bfbde 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -18,4 +18,10 @@ def initialize(invoice_path) :merchant_id => row[:merchant_id]}) end end + + def find_by_id(id) + @all.find do |invoice| + invoice.id.to_i == id + end + end end diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index 0e8440879e..c7f82075b5 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -22,4 +22,13 @@ expect(invoice_repo.find_by_id(1)).to be_a(Invoice) expect(invoice_repo.find_by_id(123542345293423)).to eq(nil) end + + it "can find all invoices by a specific customer id" do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + item_repo = ItemRepository.new('./data/items.csv') + merchant_repo = MerchantRepository.new('./data/merchants.csv') + expect(invoice_repo.find_all_by_customer_id(1)).to be_instance_of(Array) + expect(invoice_repo.find_all_by_customer_id(1).length).to eq(3) + expect(invoice_repo.find_all_by_customer_id(12345678910112)).to eq([]) + end end From c1c9d158f0bbebb3a5a308792dff62371930328b Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 18:03:01 -0600 Subject: [PATCH 081/131] Feature: Add find all by customer id --- lib/invoice_repository.rb | 6 ++++++ lib/item_repository.rb | 1 - spec/invoice_repository_spec.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index ff284bfbde..fe703dc204 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -24,4 +24,10 @@ def find_by_id(id) invoice.id.to_i == id end end + + def find_all_by_customer_id(customer_id) + @all.find_all do |invoice| + customer_id.to_i == invoice.customer_id.to_i + end + end end diff --git a/lib/item_repository.rb b/lib/item_repository.rb index 6fd23bcfd3..ce2cdd615a 100644 --- a/lib/item_repository.rb +++ b/lib/item_repository.rb @@ -55,7 +55,6 @@ def find_all_by_merchant_id(merchant_id) merchant_id.to_i == item.merchant_id.to_i end end - #Ask instructor if only adding a name for a new item is okay...Ran out of time lol. def create(attributes) new_id = @all.last.id.to_i + 1 diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index c7f82075b5..02029bbd07 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -28,7 +28,7 @@ item_repo = ItemRepository.new('./data/items.csv') merchant_repo = MerchantRepository.new('./data/merchants.csv') expect(invoice_repo.find_all_by_customer_id(1)).to be_instance_of(Array) - expect(invoice_repo.find_all_by_customer_id(1).length).to eq(3) + expect(invoice_repo.find_all_by_customer_id(1).length).to eq(8) expect(invoice_repo.find_all_by_customer_id(12345678910112)).to eq([]) end end From 5ba79c67cab5ffc294722510f3f8b45e173c8076 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Sat, 4 Jun 2022 18:11:54 -0600 Subject: [PATCH 082/131] Feature/Test: add method to find all by merchant id and test Co-authored-by: Thiago --- lib/invoice_repository.rb | 6 ++++++ spec/invoice_repository_spec.rb | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index fe703dc204..72ace605f6 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -30,4 +30,10 @@ def find_all_by_customer_id(customer_id) customer_id.to_i == invoice.customer_id.to_i end end + + def find_all_by_merchant_id(merchant_id) + @all.find_all do |invoice| + merchant_id.to_i == invoice.merchant_id.to_i + end + end end diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index 02029bbd07..5ed8a64d23 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -25,10 +25,15 @@ it "can find all invoices by a specific customer id" do invoice_repo = InvoiceRepository.new('./data/invoices.csv') - item_repo = ItemRepository.new('./data/items.csv') - merchant_repo = MerchantRepository.new('./data/merchants.csv') expect(invoice_repo.find_all_by_customer_id(1)).to be_instance_of(Array) expect(invoice_repo.find_all_by_customer_id(1).length).to eq(8) expect(invoice_repo.find_all_by_customer_id(12345678910112)).to eq([]) end + + it "can find all invoices by a matching merchant id" do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + expect(invoice_repo.find_all_by_merchant_id(12335938)).to be_instance_of(Array) + expect(invoice_repo.find_all_by_merchant_id(12335938).length).to eq(16) + expect(invoice_repo.find_all_by_merchant_id(12345678910112)).to eq([]) + end end From 5a31b21994f81f432aed21d12fe784036bebb4ef Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 21:08:52 -0600 Subject: [PATCH 083/131] Refactor: Added invoices to sales_engine hash within sales analyst spec Co-authored-by: Nick Co-authored-by: Kevin --- lib/sales_engine.rb | 16 ++++++++-------- spec/sales_analyst_spec.rb | 25 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/sales_engine.rb b/lib/sales_engine.rb index 4edcc015df..cb02716f10 100644 --- a/lib/sales_engine.rb +++ b/lib/sales_engine.rb @@ -1,18 +1,18 @@ class SalesEngine - attr_reader :items, :merchants, :invoices + attr_reader :items, + :merchants, + :invoices, + :analyst def initialize(items_path, merchants_path, invoice_path) - @items = ItemRepository.new(items_path) - @merchants = MerchantRepository.new(merchants_path) - @invoices = InvoiceRepository.new(invoice_path) + @items = ItemRepository.new(items_path) + @merchants = MerchantRepository.new(merchants_path) + @invoices = InvoiceRepository.new(invoice_path) + @analyst = SalesAnalyst.new(items, merchants, invoices) end def self.from_csv(data) return SalesEngine.new(data[:items], data[:merchants], data[:invoices]) end - def analyst - return SalesAnalyst.new(items, merchants, invoices) - end - end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 159bf23e5c..759227bb65 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -1,13 +1,15 @@ require "./lib/sales_engine" require "./lib/item_repository" require "./lib/merchant_repository" +require "./lib/invoice_repository" require "./lib/sales_analyst" RSpec.describe SalesAnalyst do it 'exists' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst @@ -18,7 +20,8 @@ #total items divided by total merchants sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst @@ -28,7 +31,8 @@ it 'can return the standard deviation of average items per merchant' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst @@ -38,7 +42,8 @@ it 'can display the merchants who have the most items for sale' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst @@ -50,7 +55,8 @@ it 'can return average price of a merchants items' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst @@ -61,7 +67,8 @@ it 'can return average of the average price per merchant' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst @@ -72,7 +79,8 @@ it "can return a standard deviation" do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst expect(sales_analyst.standard_deviation([1, 2 ,3], 2)).to eq(1) @@ -81,7 +89,8 @@ it 'can return the golden items' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", - :merchants => "./data/merchants.csv" + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst From 842473b5278380badbdf4b29f810c0f9f6e8c5a7 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 21:19:27 -0600 Subject: [PATCH 084/131] Test: Invoice repo can find all invoices by a matching status Co-authored-by: Nick Co-authored-by: Kevin --- spec/invoice_repository_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index 5ed8a64d23..5e44270d8e 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -36,4 +36,12 @@ expect(invoice_repo.find_all_by_merchant_id(12335938).length).to eq(16) expect(invoice_repo.find_all_by_merchant_id(12345678910112)).to eq([]) end + + it 'can find all invoices by a matching status' do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + expect(invoice_repo.find_all_by_status("shipped")).to be_a(Array) + expect(invoice_repo.find_all_by_status("returned")).to be_a(Array) + expect(invoice_repo.find_all_by_status("pending")).to be_a(Array) + expect(invoice_repo.find_all_by_status("super cool status")).to eq([]) + end end From c94f666e7bab83ceb52013018489fe476168a2d6 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 21:20:38 -0600 Subject: [PATCH 085/131] Feat: Invoice repo finds all invoices by a matching status Co-authored-by: Nick Co-authored-by: Kevin --- lib/invoice_repository.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index 72ace605f6..3f0e10960f 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -35,5 +35,11 @@ def find_all_by_merchant_id(merchant_id) @all.find_all do |invoice| merchant_id.to_i == invoice.merchant_id.to_i end - end + end + + def find_all_by_status(status) + @all.find_all do |invoice| + status == invoice.status + end + end end From bc6914a9f6fcfe109fa04efa7bdc156d01d5da0f Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 21:47:42 -0600 Subject: [PATCH 086/131] Test: Invoice repo can create an invoice instance with provided attributes Co-authored-by: Nick Co-authored-by: Kevin --- spec/invoice_repository_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index 5e44270d8e..a0eb2886ac 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -44,4 +44,14 @@ expect(invoice_repo.find_all_by_status("pending")).to be_a(Array) expect(invoice_repo.find_all_by_status("super cool status")).to eq([]) end + + it 'can create an invoice instance with provided attributes' do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + new_invoice_attributes = {:customer_id => "1000", + :merchant_id => "12334372"} + new_invoice = (invoice_repo.create(new_invoice_attributes)) + expect(new_invoice.customer_id).to eq("1000") + expect(new_invoice.merchant_id).to eq("12334372") + expect(invoice_repo.find_all_by_merchant_id(12334372)).to be_a(Array) + end end From 436a1170c4db69cadb2beb7eb0680100d79a7cd0 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 21:48:55 -0600 Subject: [PATCH 087/131] Feat: Pass test invoice repo creates an invoice instance with provided attributes Co-authored-by: Nick Co-authored-by: Kevin --- lib/invoice_repository.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index 3f0e10960f..f92ebe9628 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -42,4 +42,12 @@ def find_all_by_status(status) status == invoice.status end end + + def create(new_invoice_attributes) + new_id = @all.last.id.to_i + 1 + new_attribute = new_invoice_attributes + @all << Invoice.new(:id => new_id.to_s, :customer_id => new_attribute[:customer_id], :merchant_id => + new_attribute[:merchant_id], :status => "pending", :created_at => Time.now, :updated_at => Time.now) + return @all.last + end end From 5bb87a7b53505145895a314608059b351e690e4a Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Sat, 4 Jun 2022 21:55:34 -0600 Subject: [PATCH 088/131] Create invoice item spec Co-authored-by: Nick Co-authored-by: Thiago --- lib/sales_analyst.rb | 14 ++-- spec/invoice_item_spec.rb | 131 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 spec/invoice_item_spec.rb diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 49862aa476..02ff8763f1 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -74,12 +74,14 @@ def golden_items end def average_item_price_per_merchant_standard_deviation - array_of_all_prices = @items.all.map {|item| item.unit_price.to_i} - set = array_of_all_prices - mean = array_of_all_prices.sum / array_of_all_prices.size - sums = set.sum { |num| (num - mean)**2 } - std_dev = Math.sqrt(sums / (set.length - 1).to_f) - std_dev.round(2) + # array_of_all_prices = @items.all.map {|item| item.unit_price.to_i} + # set = array_of_all_prices + # mean = array_of_all_prices.sum / array_of_all_prices.size + # sums = set.sum { |num| (num - mean)**2 } + # std_dev = Math.sqrt(sums / (set.length - 1).to_f) + # std_dev.round(2) + + end end diff --git a/spec/invoice_item_spec.rb b/spec/invoice_item_spec.rb new file mode 100644 index 0000000000..774b0da2b1 --- /dev/null +++ b/spec/invoice_item_spec.rb @@ -0,0 +1,131 @@ +require './lib/invoice_item' +require 'BigDecimal' + +RSpec.describe InvoiceItem do + + it 'exists' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.new).to be_a(InvoiceItem) + end + + it 'returns the integer id' + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.id).to eq(6) + end + + it 'returns the item id' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.item_id).to eq(8) + end + + it 'returns the invoice id' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.invoice_id).to eq(8) + end + + it 'returns the quantity' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.quantity).to eq(1) + end + + it 'returns the unit price' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.unit_price).to eq(BigDecimal(10.99, 4)) + end + + it 'returns a Time instance for the date when invoice item was created' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.created_at).to eq(Time.now.round) + end + + it 'returns a Time instance for the date when invoice item was updated' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.updated_at).to eq(Time.now.round) + end + + it 'returns the price of the invoice item in dollars formated as a float' do + ii = InvoiceItem.new({ + :id => 6, + :item_id => 7, + :invoice_id => 8, + :quantity => 1, + :unit_price => BigDecimal(10.99, 4), + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(ii.unit_price_to_dollars).to eq(10.99) + end +end From 6b1b675ef5c0234bd0bcfc93679f13e50401bdd4 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 22:11:49 -0600 Subject: [PATCH 089/131] Refactor: Attr accessor update and reformatting Co-authored-by: Nick Co-authored-by: Kevin --- lib/invoice.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/invoice.rb b/lib/invoice.rb index b9785abe13..b4c6ddf034 100644 --- a/lib/invoice.rb +++ b/lib/invoice.rb @@ -1,19 +1,19 @@ class Invoice -attr_reader :id, - :customer_id, - :status, - :created_at, - :updated_at, - :merchant_id + attr_reader :id, + :customer_id, + :created_at, + :merchant_id + attr_accessor :status, + :updated_at def initialize(data) - @id = data[:id] - @customer_id = data[:customer_id] - @status = data[:status] - @created_at = data[:created_at] - @updated_at = data[:updated_at] - @merchant_id = data[:merchant_id] + @id = data[:id] + @customer_id = data[:customer_id] + @status = data[:status] + @created_at = data[:created_at] + @updated_at = data[:updated_at] + @merchant_id = data[:merchant_id] end end From e592ba02c8f97b8fdea068624e01a2985aca10f9 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 22:12:49 -0600 Subject: [PATCH 090/131] Test: Invoice repo can update an invoices attributes Co-authored-by: Nick Co-authored-by: Kevin --- spec/invoice_repository_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index a0eb2886ac..d7000c2d85 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -54,4 +54,24 @@ expect(new_invoice.merchant_id).to eq("12334372") expect(invoice_repo.find_all_by_merchant_id(12334372)).to be_a(Array) end + + it 'can update an invoices attributes' do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + new_invoice_attributes = {:customer_id => "1000", + :merchant_id => "12334372"} + new_invoice = (invoice_repo.create(new_invoice_attributes)) + + expect(invoice_repo.find_by_id(4986).customer_id).to eq("1000") + expect(invoice_repo.find_by_id(4986).merchant_id).to eq("12334372") + expect(invoice_repo.find_by_id(4986).status).to eq("pending") + + new_test_attributes = {:status => "shipped"} + invoice_repo.update(4986, new_test_attributes) + + expect(invoice_repo.find_by_id(4986).customer_id).to eq("1000") + expect(invoice_repo.find_by_id(4986).merchant_id).to eq("12334372") + expect(invoice_repo.find_by_id(4986).status).to eq("shipped") + expect(invoice_repo.find_by_id(4986).updated_at).to be_instance_of(Time) + end + end From 8fdba30b65c7a77a8ce3d99d2e04b625a770020a Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 22:13:37 -0600 Subject: [PATCH 091/131] Feat: Pass test invoice repo updates an invoice attributes Co-authored-by: Nick Co-authored-by: Kevin --- lib/invoice_repository.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index f92ebe9628..7472c37b01 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -50,4 +50,10 @@ def create(new_invoice_attributes) new_attribute[:merchant_id], :status => "pending", :created_at => Time.now, :updated_at => Time.now) return @all.last end + + def update(id, attributes) + updated_item = find_by_id(id) + updated_item.status = attributes[:status] + updated_item.updated_at = Time.now + end end From b7ac936215074dada485d98ab59dd4d46d2f807c Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 22:17:23 -0600 Subject: [PATCH 092/131] Test: Pass test invoice repo deletes an invoice Co-authored-by: Nick Co-authored-by: Kevin --- spec/invoice_repository_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/invoice_repository_spec.rb b/spec/invoice_repository_spec.rb index d7000c2d85..7f1e4d1b8f 100644 --- a/spec/invoice_repository_spec.rb +++ b/spec/invoice_repository_spec.rb @@ -74,4 +74,11 @@ expect(invoice_repo.find_by_id(4986).updated_at).to be_instance_of(Time) end + it 'can delete an invoice' do + invoice_repo = InvoiceRepository.new('./data/invoices.csv') + expect(invoice_repo.find_by_id(4985)).to be_a(Invoice) + invoice_repo.delete(4985) + expect(invoice_repo.find_by_id(4985)).to eq(nil) + end + end From 03f7c38105832615b5e9dec8f126cda8c96b453e Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 22:17:55 -0600 Subject: [PATCH 093/131] Feat: Invoice repo deletes an invoice Co-authored-by: Nick Co-authored-by: Kevin --- lib/invoice_repository.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/invoice_repository.rb b/lib/invoice_repository.rb index 7472c37b01..ff6deb3606 100644 --- a/lib/invoice_repository.rb +++ b/lib/invoice_repository.rb @@ -56,4 +56,9 @@ def update(id, attributes) updated_item.status = attributes[:status] updated_item.updated_at = Time.now end + + def delete(id) + removed_item = find_by_id(id) + @all.delete(removed_item) + end end From d603181431d9d2d61c73c6089e1eb84526ea3494 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 22:31:50 -0600 Subject: [PATCH 094/131] Test/Feat: Sales analyst can average invoices per merchant Co-authored-by: Nick Co-authored-by: Kevin --- lib/sales_analyst.rb | 4 ++++ spec/sales_analyst_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index e857d70e6b..78de1f238c 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -76,4 +76,8 @@ def golden_items items.all.find_all{ |item| item.unit_price.to_i > minimum_golden_price } end + def average_invoices_per_merchant + (@invoices.all.size / @merchants.all.size.to_f).round(2) + end + end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 759227bb65..aef325f800 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -97,4 +97,15 @@ expect(sales_analyst.golden_items).to be_a(Array) end + it 'can average invoices per merchant' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_invoices_per_merchant).to eq(10.49) + end + end From daf6d4863799054404101ee40c9659be815ef30f Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Sat, 4 Jun 2022 22:44:40 -0600 Subject: [PATCH 095/131] Test/Feat: Sales analyst an return standard deviation of average invoices per merchant Co-authored-by: Nick Co-authored-by: Kevin --- lib/sales_analyst.rb | 15 +++++++++++++++ spec/sales_analyst_spec.rb | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 78de1f238c..6c5a7d93d4 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -80,4 +80,19 @@ def average_invoices_per_merchant (@invoices.all.size / @merchants.all.size.to_f).round(2) end + def average_invoices_per_merchant_standard_deviation + set = invoices_by_merchant.values + avg = average_invoices_per_merchant + standard_deviation(set, avg) + end + + def invoices_by_merchant + invoices_per_merchant = Hash.new(0) + merchant_ids = invoices.all.map {|invoice| invoice.merchant_id} + merchant_ids.each do |id| + invoices_per_merchant[id] += 1 + end + return invoices_per_merchant + end + end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index aef325f800..a539dbe580 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -108,4 +108,15 @@ expect(sales_analyst.average_invoices_per_merchant).to eq(10.49) end + it 'can return standard deviation of average invoices per merchant' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_invoices_per_merchant_standard_deviation).to eq(3.29) + end + end From 81818f736cb772d5a070b857328745efe7325b21 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Sun, 5 Jun 2022 19:50:18 -0400 Subject: [PATCH 096/131] Add test for top_merchants_by_invoice count and helper methods --- spec/sales_analyst_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index a539dbe580..6737d3d602 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -119,4 +119,28 @@ expect(sales_analyst.average_invoices_per_merchant_standard_deviation).to eq(3.29) end + it 'can calculate zscore for a merchant' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.z_score(4)).to eq(-1.97) + end + + it 'can return the top performing merchants by invoice count' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.top_merchants_by_invoice_count.length).to eq(12) + end + + + end From a985b8d543ad0d85a2a4ad0ddc50f8a3a82bf7ae Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Sun, 5 Jun 2022 20:22:19 -0400 Subject: [PATCH 097/131] Add test for merchants_by_z_score helper method --- spec/sales_analyst_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 6737d3d602..a81acbc3ce 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -130,6 +130,18 @@ expect(sales_analyst.z_score(4)).to eq(-1.97) end + it 'can create a hash of merchants by zscore' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.merchants_by_zscore.keys.include?("12334753")).to eq(true) + expect(sales_analyst.merchants_by_zscore.values.include?(1.07)).to eq(true) + end + it 'can return the top performing merchants by invoice count' do sales_engine = SalesEngine.from_csv({ :items => "./data/items.csv", From 4d1fb4e4db19187fb1075f3cffdae36afb5c6b4b Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Sun, 5 Jun 2022 20:23:28 -0400 Subject: [PATCH 098/131] Add test for bottom_merchants_by_invoice_count method --- spec/sales_analyst_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index a81acbc3ce..ab9a70863e 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -153,6 +153,17 @@ expect(sales_analyst.top_merchants_by_invoice_count.length).to eq(12) end + it 'can return the bottom performing merchants by invoice count' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.bottom_merchants_by_invoice_count.length).to eq(463) +end + end From 120f2025a00f266a1ba8cbf517b8132600c9f0c6 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Sun, 5 Jun 2022 20:24:11 -0400 Subject: [PATCH 099/131] Add top_merchants_by_invoice count and bottom_merchants_by_invoice count methods --- lib/sales_analyst.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 6c5a7d93d4..90e28bde43 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -95,4 +95,35 @@ def invoices_by_merchant return invoices_per_merchant end + def z_score(invoice_count) + mean = average_invoices_per_merchant + std_dev = average_invoices_per_merchant_standard_deviation + z_score = (invoice_count - mean) / std_dev + return z_score.round(2) + end + + def merchants_by_zscore + merchant_by_z_score = Hash.new + invoices_by_merchant.each do |merchant, invoice_count| + merchant_by_z_score[merchant] = z_score(invoice_count) + end + return merchant_by_z_score + end + + def top_merchants_by_invoice_count + top_merchants = [] + merchants_by_zscore.each do |merchants, zscore| + top_merchants << merchants if zscore > 2 + end + return top_merchants + end + + def bottom_merchants_by_invoice_count + bottom_merchants = [] + merchants_by_zscore.each do |merchants, zscore| + bottom_merchants << merchants if zscore < 2 + end + return top_merchants + end + end From e9fd35645658088ae61da9801cc65e271fc08029 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Sun, 5 Jun 2022 20:25:41 -0400 Subject: [PATCH 100/131] Change bottom_merchants_by_invoice_count method --- lib/sales_analyst.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 90e28bde43..88644a1972 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -126,4 +126,6 @@ def bottom_merchants_by_invoice_count return top_merchants end + + end From cfda7aec8773e09f79249c248bcafb5916eaeb8b Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Sun, 5 Jun 2022 20:29:04 -0400 Subject: [PATCH 101/131] Add test for top_days_by_invoice_count method --- spec/sales_analyst_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index ab9a70863e..9a37db761c 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -164,6 +164,16 @@ expect(sales_analyst.bottom_merchants_by_invoice_count.length).to eq(463) end +it 'can return the days of the week that see the most sales' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect (sales_analyst.top_days_by_invoice_count).to eq(["Sunday", "Saturday"]) +end end From a43cf2cd04e465c6938ee1d721d8211d099f63ab Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Sun, 5 Jun 2022 23:58:09 -0400 Subject: [PATCH 102/131] Add test for date_to_day helper method --- spec/sales_analyst_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 9a37db761c..3574204bbe 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -171,9 +171,19 @@ :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst - + expect (sales_analyst.top_days_by_invoice_count).to eq(["Sunday", "Saturday"]) end +it 'can return the day of the week' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + expect(sales_analyst.date_to_day("2009-02-07")).to eq("Saturday") +end + end From 8a7d9833f5c488df4cb322c8d543de893701fa66 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 00:05:28 -0400 Subject: [PATCH 103/131] Add test for invoices_by_day helper method --- spec/sales_analyst_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 3574204bbe..056e826c0c 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -171,7 +171,7 @@ :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst - + expect (sales_analyst.top_days_by_invoice_count).to eq(["Sunday", "Saturday"]) end @@ -185,5 +185,15 @@ expect(sales_analyst.date_to_day("2009-02-07")).to eq("Saturday") end +it 'can return the invoices by day of the week' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + expect(sales_analyst.invoices_by_day).to be_a Hash +end + end From b56f166e11293376204813fd83062a1cc66a3be4 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 00:26:36 -0400 Subject: [PATCH 104/131] Add test for average_invoices_per_day helper method --- spec/sales_analyst_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 056e826c0c..85f928fd2a 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -192,7 +192,19 @@ :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst - expect(sales_analyst.invoices_by_day).to be_a Hash + + expect(sales_analyst.invoices_by_day.values.count).to eq(7) +end + +it 'can return the average invoices per day' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_invoices_per_day).to eq(712) end From 6037be834e5a99531fc2fd0df39e39ecc488787f Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 00:33:11 -0400 Subject: [PATCH 105/131] Add average_invoices_per_day_standard_deviation helper method --- spec/sales_analyst_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 85f928fd2a..57414dab24 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -207,5 +207,15 @@ expect(sales_analyst.average_invoices_per_day).to eq(712) end +it 'can return the average invoices per day standard deviation' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.average_invoices_per_day_standard_deviation).to eq(18.07) + end From abbb3c77a6ce98fd71c34fdab563363ea04f63e9 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 10:36:53 -0400 Subject: [PATCH 106/131] Add helper methods and edits to top_days_by_invoice_count --- lib/sales_analyst.rb | 54 +++++++++++++++++-- spec/sales_analyst_spec.rb | 103 +++++++++++++++++++++---------------- 2 files changed, 109 insertions(+), 48 deletions(-) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 88644a1972..114ff40d08 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -3,6 +3,7 @@ require_relative "./merchant_repository" require "bigdecimal" require "bigdecimal/util" +require "date" class SalesAnalyst attr_reader :items, :merchants, :invoices @@ -95,7 +96,7 @@ def invoices_by_merchant return invoices_per_merchant end - def z_score(invoice_count) + def merchant_z_score(invoice_count) mean = average_invoices_per_merchant std_dev = average_invoices_per_merchant_standard_deviation z_score = (invoice_count - mean) / std_dev @@ -105,7 +106,7 @@ def z_score(invoice_count) def merchants_by_zscore merchant_by_z_score = Hash.new invoices_by_merchant.each do |merchant, invoice_count| - merchant_by_z_score[merchant] = z_score(invoice_count) + merchant_by_z_score[merchant] = merchant_z_score(invoice_count) end return merchant_by_z_score end @@ -123,9 +124,56 @@ def bottom_merchants_by_invoice_count merchants_by_zscore.each do |merchants, zscore| bottom_merchants << merchants if zscore < 2 end - return top_merchants + return bottom_merchants + end + + def top_days_by_invoice_count + top_days = [] + weekday_by_zscore.each do |day, zscore| + top_days << day if zscore > 1 + end + return top_days + end + + def date_to_day(date) + weekday = Date.parse(date) + weekday_num = weekday.wday + weekday_name = Date::DAYNAMES[weekday_num] + return weekday_name end + def invoices_by_day + invoices_per_day = Hash.new(0) + invoice_dates = invoices.all.map {|invoice| invoice.created_at} + invoice_dates.each do |date| + invoices_per_day[date_to_day(date)] += 1 + end + return invoices_per_day + end + + def average_invoices_per_day + invoices_by_day.values.sum / invoices_by_day.count + end + def average_invoices_per_day_standard_deviation + set = invoices_by_day.values + avg = average_invoices_per_day + standard_deviation(set, avg) + end + + def weekday_by_zscore + day_by_z_score = Hash.new + invoices_by_day.each do |day, invoice_count| + day_by_z_score[day] = weekday_z_score(invoice_count) + end + return day_by_z_score + end + + def weekday_z_score(invoice_count) + mean = average_invoices_per_day + std_dev = average_invoices_per_day_standard_deviation + z_score = (invoice_count - mean) / std_dev + return z_score.round(2) + end end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 57414dab24..e8ac8298ea 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -127,7 +127,7 @@ }) sales_analyst = sales_engine.analyst - expect(sales_analyst.z_score(4)).to eq(-1.97) + expect(sales_analyst.merchant_z_score(4)).to eq(-1.97) end it 'can create a hash of merchants by zscore' do @@ -164,58 +164,71 @@ expect(sales_analyst.bottom_merchants_by_invoice_count.length).to eq(463) end -it 'can return the days of the week that see the most sales' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst + it 'can return the days of the week that see the most sales' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst - expect (sales_analyst.top_days_by_invoice_count).to eq(["Sunday", "Saturday"]) -end + expect(sales_analyst.top_days_by_invoice_count).to eq(["Wednesday"]) + end -it 'can return the day of the week' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - expect(sales_analyst.date_to_day("2009-02-07")).to eq("Saturday") -end + it 'can return the day of the week' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + expect(sales_analyst.date_to_day("2009-02-07")).to eq("Saturday") + end -it 'can return the invoices by day of the week' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst + it 'can return the invoices by day of the week' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst - expect(sales_analyst.invoices_by_day.values.count).to eq(7) -end + expect(sales_analyst.invoices_by_day.values.count).to eq(7) + end -it 'can return the average invoices per day' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst + it 'can return the average invoices per day' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst - expect(sales_analyst.average_invoices_per_day).to eq(712) -end + expect(sales_analyst.average_invoices_per_day).to eq(712) + end -it 'can return the average invoices per day standard deviation' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst + it 'can return the average invoices per day standard deviation' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst - expect(sales_analyst.average_invoices_per_day_standard_deviation).to eq(18.07) + expect(sales_analyst.average_invoices_per_day_standard_deviation).to eq(18.07) + end + it 'can calculate z score for a day of the week' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + + expect(sales_analyst.weekday_by_zscore.keys.include?("Saturday")).to eq(true) + expect(sales_analyst.weekday_by_zscore.values[0].class).to eq(Float) + end end From 5257d1c48fe70853e74be281ab5b556a8c63f809 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 11:01:34 -0400 Subject: [PATCH 107/131] Add test for invoice_status method --- spec/sales_analyst_spec.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index e8ac8298ea..60f97140e1 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -225,10 +225,25 @@ :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst - + expect(sales_analyst.weekday_by_zscore.keys.include?("Saturday")).to eq(true) expect(sales_analyst.weekday_by_zscore.values[0].class).to eq(Float) end + it 'can return the percentage of invoices by status' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + + expect(sales_analyst.invoice_status(:pending)).to eq(29.55) + expect(sales_analyst.invoice_status(:shipped)).to eq(56.95) + expect(sales_analyst.invoice_status(:returned)).to eq(13.5) + end + + end From 960d1a7435817c63ef097216c799315ab76d4d6a Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 09:51:37 -0600 Subject: [PATCH 108/131] Save work before pull from main --- spec/invoice_item_repository.rb | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/invoice_item_repository.rb diff --git a/spec/invoice_item_repository.rb b/spec/invoice_item_repository.rb new file mode 100644 index 0000000000..aaab5db80a --- /dev/null +++ b/spec/invoice_item_repository.rb @@ -0,0 +1,46 @@ +require './lib/invoice_item_repository' +require 'BigDecimal' +require CSV + +Rspec.describe InvoiceItemRepository do + it 'exists' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + expect(ii_repo).to be_a(InvoiceItemRepository) + end + + it 'returns an array of all known InvoiceItem instances' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + expect(ii_repo.all).to be_a(Array) + + it '' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + end + + it '' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + end + + it '' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + end + + it '' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + end + + it '' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + end + + it '' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + end +end From 91d67f9c21660605db9a64a3dd72d72fe9c6b0b7 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 12:58:59 -0400 Subject: [PATCH 109/131] Add additional expectation to merchants_by_zscore method Co-authored-by: Thiago S Co-authored-by: Kevin Ta --- spec/sales_analyst_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index 60f97140e1..2a7a7a8292 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -139,7 +139,8 @@ sales_analyst = sales_engine.analyst expect(sales_analyst.merchants_by_zscore.keys.include?("12334753")).to eq(true) - expect(sales_analyst.merchants_by_zscore.values.include?(1.07)).to eq(true) + expect(sales_analyst.merchants_by_zscore.values.include?(1.37)).to eq(true) + expect(sales_analyst.merchants_by_zscore["12334753"]).to eq(1.37) end it 'can return the top performing merchants by invoice count' do @@ -239,7 +240,6 @@ }) sales_analyst = sales_engine.analyst - expect(sales_analyst.invoice_status(:pending)).to eq(29.55) expect(sales_analyst.invoice_status(:shipped)).to eq(56.95) expect(sales_analyst.invoice_status(:returned)).to eq(13.5) From f9d9c8bc8e2775c4212fc9858a3fd67c2015604d Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 12:59:43 -0400 Subject: [PATCH 110/131] Add invoice_status method and helper methods Co-authored-by: Thiago S Co-authored-by: Kevin Ta --- lib/sales_analyst.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index 114ff40d08..5994f0e091 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -176,4 +176,26 @@ def weekday_z_score(invoice_count) return z_score.round(2) end + def invoice_status(status) + status_percentage = ((invoice_by_status_count[(status)].to_f / invoice_by_status_count.values.sum.to_f)*100) + return status_percentage.round(2) + end + + def invoice_by_status + invoices_per_status = Hash.new + invoices.all.each do |invoice| + invoices_per_status[invoice.id] = invoice.status + end + return invoices_per_status + end + + def invoice_by_status_count + status_count = Hash.new(0) + invoice_by_status.each do |id, status| + status_count[status.to_sym] += 1 + end + return status_count + end + + end From 6870d901901d1d4783cad51a619464179e15e492 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Mon, 6 Jun 2022 18:34:28 -0600 Subject: [PATCH 111/131] Test: add test for if invoice item if it exists --- lib/invoice_item.rb | 2 ++ spec/invoice_item_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 lib/invoice_item.rb create mode 100644 spec/invoice_item_spec.rb diff --git a/lib/invoice_item.rb b/lib/invoice_item.rb new file mode 100644 index 0000000000..ddf7925847 --- /dev/null +++ b/lib/invoice_item.rb @@ -0,0 +1,2 @@ +class InvoiceItem +end diff --git a/spec/invoice_item_spec.rb b/spec/invoice_item_spec.rb new file mode 100644 index 0000000000..eb4c6ec537 --- /dev/null +++ b/spec/invoice_item_spec.rb @@ -0,0 +1,10 @@ +require "./lib/invoice_item" +require "Rspec" + +RSpec.describe InvoiceItem do + + it 'exists' do + invoiceitem = InvoiceItem.new + expect(invoiceitem).to be_an_instance_of(InvoiceItem) + end +end From adaf0a636d84f2ed5d2242b522502923a56f523a Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Mon, 6 Jun 2022 18:52:00 -0600 Subject: [PATCH 112/131] Test: add test for returning the details of an invoice ID Co-authored-by: Thiago Co-authored-by: Kevin --- lib/invoice_item.rb | 13 ++++++++++++- spec/invoice_item_spec.rb | 23 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/invoice_item.rb b/lib/invoice_item.rb index ddf7925847..8369991260 100644 --- a/lib/invoice_item.rb +++ b/lib/invoice_item.rb @@ -1,2 +1,13 @@ class InvoiceItem -end + + def initialize(data) + @id = data[:id] + @item_id = data[:merchant_id] + @invoice_id = data[:invoice_id] + @quantity = data[:quantity] + @unit_price = data[:unit_price] + @created_at = data[:created_at] + @updated_at = data[:updated_at] + + end +end diff --git a/spec/invoice_item_spec.rb b/spec/invoice_item_spec.rb index eb4c6ec537..85029c90dd 100644 --- a/spec/invoice_item_spec.rb +++ b/spec/invoice_item_spec.rb @@ -1,10 +1,31 @@ require "./lib/invoice_item" +require "bigdecimal" require "Rspec" RSpec.describe InvoiceItem do it 'exists' do - invoiceitem = InvoiceItem.new + data = ({:id => 1, + :item_id => 263519844, + :invoice_id => 1, + :quantity => 5, + :unit_price => 13635, + :created_at => Time.now, + :updated_at => Time.now}) + + invoiceitem = InvoiceItem.new(data) expect(invoiceitem).to be_an_instance_of(InvoiceItem) end + + it "can return the details of an invoice id" do + data = ({:id => 1, + :item_id => 263519844, + :invoice_id => 1, + :quantity => 5, + :unit_price => 13635, + :created_at => Time.now, + :updated_at => Time.now}) + + invoiceitem = InvoiceItem.new(data) + end end From e1e3aa94182b424f8be67876d5b1503a241c537d Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 20:53:09 -0400 Subject: [PATCH 113/131] Create customer class and spec file --- lib/customer.rb | 10 ++++++++++ spec/customer_spec.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/customer.rb create mode 100644 spec/customer_spec.rb diff --git a/lib/customer.rb b/lib/customer.rb new file mode 100644 index 0000000000..3f1566f244 --- /dev/null +++ b/lib/customer.rb @@ -0,0 +1,10 @@ +class Customer + attr_reader :id, :first_name, :last_name, :created_at, :updated_at + def initialize(data) + @id = data[:id] + @first_name = data[:first_name] + @last_name = data[:last_name] + @created_at = data[:created_at] + @updated_at = data[:updated_at] + end +end diff --git a/spec/customer_spec.rb b/spec/customer_spec.rb new file mode 100644 index 0000000000..f58fb0e471 --- /dev/null +++ b/spec/customer_spec.rb @@ -0,0 +1,15 @@ +require './lib/customer' +require 'time' + +RSpec.describe Customer do + + it 'exists' do + c = Customer.new({ + :id => 6, + :first_name => "Joan", + :last_name => "Clarke", + :created_at => Time.now, + :updated_at => Time.now +}) + end +end From 55c98aa5d9c8f540b81d8ff9d2d7f479870c2b67 Mon Sep 17 00:00:00 2001 From: Justin Ramirez Date: Mon, 6 Jun 2022 21:04:57 -0400 Subject: [PATCH 114/131] Add tests to confirm accessibility to instance variables --- spec/customer_spec.rb | 76 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/spec/customer_spec.rb b/spec/customer_spec.rb index f58fb0e471..50689b4f71 100644 --- a/spec/customer_spec.rb +++ b/spec/customer_spec.rb @@ -5,11 +5,75 @@ it 'exists' do c = Customer.new({ - :id => 6, - :first_name => "Joan", - :last_name => "Clarke", - :created_at => Time.now, - :updated_at => Time.now -}) + :id => 6, + :first_name => "Joan", + :last_name => "Clarke", + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(c).to be_an_instance_of Customer + end + + it 'can return the customer id' do + c = Customer.new({ + :id => 6, + :first_name => "Joan", + :last_name => "Clarke", + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(c.id).to eq(6) + + end + + it 'can return the customers first name' do + c = Customer.new({ + :id => 6, + :first_name => "Joan", + :last_name => "Clarke", + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(c.first_name).to eq("Joan") + end + + it 'can return the customers last name' do + c = Customer.new({ + :id => 6, + :first_name => "Joan", + :last_name => "Clarke", + :created_at => Time.now, + :updated_at => Time.now + }) + + expect(c.last_name).to eq("Clarke") + + end + + it 'can return the time the customers profile was created' do + c = Customer.new({ + :id => 6, + :first_name => "Joan", + :last_name => "Clarke", + :created_at => Time.now.round, + :updated_at => Time.now.round + }) + + expect(c.created_at).to eq(Time.now.round) + end + + it 'can return the time the customers profile was updated' do + c = Customer.new({ + :id => 6, + :first_name => "Joan", + :last_name => "Clarke", + :created_at => Time.now.round, + :updated_at => Time.now.round + }) + + expect(c.updated_at).to eq(Time.now.round) end end From 7ab85e7157b54b500329dc972200987d96016b67 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Mon, 6 Jun 2022 19:12:22 -0600 Subject: [PATCH 115/131] Test: add ability to return unit price as float Co-authored-by: Thiago Co-authored-by: Kevin --- lib/invoice_item.rb | 14 ++++++++++++-- spec/invoice_item_spec.rb | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/invoice_item.rb b/lib/invoice_item.rb index 8369991260..285eaed7f0 100644 --- a/lib/invoice_item.rb +++ b/lib/invoice_item.rb @@ -1,13 +1,23 @@ class InvoiceItem +attr_reader :id, + :item_id, + :invoice_id, + :quantity, + :unit_price, + :created_at, + :unit_price_to_dollars, + :updated_at def initialize(data) @id = data[:id] - @item_id = data[:merchant_id] + @item_id = data[:item_id] @invoice_id = data[:invoice_id] @quantity = data[:quantity] @unit_price = data[:unit_price] @created_at = data[:created_at] @updated_at = data[:updated_at] - + @unit_price_to_dollars = @unit_price.to_f end + + end diff --git a/spec/invoice_item_spec.rb b/spec/invoice_item_spec.rb index 85029c90dd..754143af5c 100644 --- a/spec/invoice_item_spec.rb +++ b/spec/invoice_item_spec.rb @@ -4,6 +4,7 @@ RSpec.describe InvoiceItem do + it 'exists' do data = ({:id => 1, :item_id => 263519844, @@ -18,6 +19,23 @@ end it "can return the details of an invoice id" do + data = ({:id => 1, + :item_id => 263519844, + :invoice_id => 1, + :quantity => 5, + :unit_price => 13635, + :created_at => Time.now.round, + :updated_at => Time.now.round}) + + invoiceitem = InvoiceItem.new(data) + expect(invoiceitem.id).to eq(1) + expect(invoiceitem.item_id).to eq(263519844) + expect(invoiceitem.quantity).to eq(5) + expect(invoiceitem.created_at).to eq(Time.now.round) + expect(invoiceitem.updated_at).to eq(Time.now.round) + end + + it "can return the unit price as a float" do data = ({:id => 1, :item_id => 263519844, :invoice_id => 1, @@ -27,5 +45,6 @@ :updated_at => Time.now}) invoiceitem = InvoiceItem.new(data) + expect(invoiceitem.unit_price_to_dollars).to eq(13635.0) end end From 266bc30a2faea12a61dd512e855ac33ee54e5464 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 19:18:58 -0600 Subject: [PATCH 116/131] Save progress before branch switch --- lib/sales_analyst.rb | 26 ++------------------------ spec/invoice_item_spec.rb | 4 ++-- spec/sales_analyst_spec.rb | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/lib/sales_analyst.rb b/lib/sales_analyst.rb index acc141c6ce..d9ea9e5ba2 100644 --- a/lib/sales_analyst.rb +++ b/lib/sales_analyst.rb @@ -69,29 +69,6 @@ def standard_deviation(values, mean) end def golden_items -<<<<<<< HEAD - require "pry"; binding.pry - average_item_price_per_merchant_standard_deviation - - # standard_deviation = average_items_per_merchant_standard_deviation - # golden_item_standard = standard_deviation + average_average_price_per_merchant - # merchants_with_high_sales = [] - # items_by_merchant.each_pair do |merchant, items| - # merchants_with_high_sales << merchant if items > mean_and_standard_dev - # end - # return merchants_with_high_sales - end - - def average_item_price_per_merchant_standard_deviation - # array_of_all_prices = @items.all.map {|item| item.unit_price.to_i} - # set = array_of_all_prices - # mean = array_of_all_prices.sum / array_of_all_prices.size - # sums = set.sum { |num| (num - mean)**2 } - # std_dev = Math.sqrt(sums / (set.length - 1).to_f) - # std_dev.round(2) - - -======= array_of_all_prices = @items.all.map {|item| item.unit_price.to_i} set = array_of_all_prices mean = array_of_all_prices.sum / array_of_all_prices.size @@ -197,7 +174,8 @@ def weekday_z_score(invoice_count) std_dev = average_invoices_per_day_standard_deviation z_score = (invoice_count - mean) / std_dev return z_score.round(2) ->>>>>>> e97359dcf98ace7f5b3ebfd248d94c4b39af61a9 end + + end end diff --git a/spec/invoice_item_spec.rb b/spec/invoice_item_spec.rb index 774b0da2b1..2d83008f3f 100644 --- a/spec/invoice_item_spec.rb +++ b/spec/invoice_item_spec.rb @@ -5,7 +5,7 @@ it 'exists' do ii = InvoiceItem.new({ - :id => 6, + :id => 263519844, :item_id => 7, :invoice_id => 8, :quantity => 1, @@ -128,4 +128,4 @@ expect(ii.unit_price_to_dollars).to eq(10.99) end -end +end diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb index e8ac8298ea..dd8eb29682 100644 --- a/spec/sales_analyst_spec.rb +++ b/spec/sales_analyst_spec.rb @@ -225,10 +225,23 @@ :invoices => "./data/invoices.csv" }) sales_analyst = sales_engine.analyst - + expect(sales_analyst.weekday_by_zscore.keys.include?("Saturday")).to eq(true) expect(sales_analyst.weekday_by_zscore.values[0].class).to eq(Float) end + it 'can return the percentage of invoices by satus' do + sales_engine = SalesEngine.from_csv({ + :items => "./data/items.csv", + :merchants => "./data/merchants.csv", + :invoices => "./data/invoices.csv" + }) + sales_analyst = sales_engine.analyst + + expect(sales_analyst.invoice_status(:pending)).to eq(29.55) + expect(sales_analyst.invoice_status(:shipped)) + expect(sales_analyst.invoice_status(:returned)).to eq(13.5) + end + end From 92d5784c22400d10963082a48c15e659927a3dad Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 19:54:21 -0600 Subject: [PATCH 117/131] Test: invoice_item_repo exists, returns as array, return amount of invoice_item_objects Co-authored-by: Thiago Co-authored-by: Nick Co-authored-by: Justin ' --- lib/invoice_item_repository.rb | 14 ++ ...ory.rb => invoice_item_repository_spec.rb} | 29 +--- spec/invoice_item_spec.rb | 132 ------------------ 3 files changed, 21 insertions(+), 154 deletions(-) create mode 100644 lib/invoice_item_repository.rb rename spec/{invoice_item_repository.rb => invoice_item_repository_spec.rb} (54%) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb new file mode 100644 index 0000000000..201c5d2e44 --- /dev/null +++ b/lib/invoice_item_repository.rb @@ -0,0 +1,14 @@ +require 'CSV' +require 'BigDecimal' +require_relative './invoice_item.rb' + +class InvoiceItemRepository + attr_reader :all + def initialize(invoice_item_path) + @invoice_item_path = invoice_item_path + @all = [] + end + + + +end diff --git a/spec/invoice_item_repository.rb b/spec/invoice_item_repository_spec.rb similarity index 54% rename from spec/invoice_item_repository.rb rename to spec/invoice_item_repository_spec.rb index aaab5db80a..f9ea3fc864 100644 --- a/spec/invoice_item_repository.rb +++ b/spec/invoice_item_repository_spec.rb @@ -1,8 +1,9 @@ require './lib/invoice_item_repository' require 'BigDecimal' -require CSV +require 'CSV' -Rspec.describe InvoiceItemRepository do + +RSpec.describe InvoiceItemRepository do it 'exists' do invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) @@ -13,34 +14,18 @@ invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) expect(ii_repo.all).to be_a(Array) + end - it '' do - invoice_items = './data/invoice_items.csv' - ii_repo = InvoiceItemRepository.new(invoice_items) - end - - it '' do - invoice_items = './data/invoice_items.csv' - ii_repo = InvoiceItemRepository.new(invoice_items) - end - - it '' do - invoice_items = './data/invoice_items.csv' - ii_repo = InvoiceItemRepository.new(invoice_items) - end - - it '' do + it 'return the amount of all known invoice_items instances' do invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) + expect(ii_repo.all.count).to eq(21830) end it '' do invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) + expect() end - it '' do - invoice_items = './data/invoice_items.csv' - ii_repo = InvoiceItemRepository.new(invoice_items) - end end diff --git a/spec/invoice_item_spec.rb b/spec/invoice_item_spec.rb index d90a0c73c0..754143af5c 100644 --- a/spec/invoice_item_spec.rb +++ b/spec/invoice_item_spec.rb @@ -1,134 +1,3 @@ -<<<<<<< HEAD -require './lib/invoice_item' -require 'BigDecimal' - -RSpec.describe InvoiceItem do - - it 'exists' do - ii = InvoiceItem.new({ - :id => 263519844, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.new).to be_a(InvoiceItem) - end - - it 'returns the integer id' - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.id).to eq(6) - end - - it 'returns the item id' do - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.item_id).to eq(8) - end - - it 'returns the invoice id' do - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.invoice_id).to eq(8) - end - - it 'returns the quantity' do - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.quantity).to eq(1) - end - - it 'returns the unit price' do - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.unit_price).to eq(BigDecimal(10.99, 4)) - end - - it 'returns a Time instance for the date when invoice item was created' do - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.created_at).to eq(Time.now.round) - end - - it 'returns a Time instance for the date when invoice item was updated' do - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.updated_at).to eq(Time.now.round) - end - - it 'returns the price of the invoice item in dollars formated as a float' do - ii = InvoiceItem.new({ - :id => 6, - :item_id => 7, - :invoice_id => 8, - :quantity => 1, - :unit_price => BigDecimal(10.99, 4), - :created_at => Time.now, - :updated_at => Time.now - }) - - expect(ii.unit_price_to_dollars).to eq(10.99) -======= require "./lib/invoice_item" require "bigdecimal" require "Rspec" @@ -177,6 +46,5 @@ invoiceitem = InvoiceItem.new(data) expect(invoiceitem.unit_price_to_dollars).to eq(13635.0) ->>>>>>> af42e2a0c22e9a8ac8fc8faaa6957846608d9c4d end end From ac59d082a0872f788cd42393f6a3372d96b2b237 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 20:11:37 -0600 Subject: [PATCH 118/131] Feat: invoice_item_repository returns data Co-authored-by: Nick Co-authored-by: Thiago Co-authored-by: Justin --- lib/invoice_item_repository.rb | 15 +++++++++++++++ spec/invoice_item_repository_spec.rb | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index 201c5d2e44..77b55b3867 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -7,6 +7,21 @@ class InvoiceItemRepository def initialize(invoice_item_path) @invoice_item_path = invoice_item_path @all = [] + + CSV.foreach(@invoice_item_path, headers: true, header_converters: :symbol) do |row| + @all << InvoiceItem.new({ + :id => row[:id], + :item_id => row[:item_id], + :invoice_id => row[:invoice_id], + :quantity => row[:quantity], + :unit_price => row[:unit_price], + :created_at => row[:created_at], + :updated_at => row[:updated_at], + :unit_price => row[:unit_price] + }) + end + require 'pry';binding.pry + end diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index f9ea3fc864..0fd185e572 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -22,7 +22,7 @@ expect(ii_repo.all.count).to eq(21830) end - it '' do + xit '' do invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) expect() From f8353333d1a53cba40e22b00ec97c4f1580bf7a1 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 20:19:10 -0600 Subject: [PATCH 119/131] Test: invoice_item_repository find by id Co-authored-by: Justin Co-authored-by: Thiago Co-authored-by: Nick --- lib/invoice_item_repository.rb | 2 +- spec/invoice_item_repository_spec.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index 77b55b3867..d498ff2175 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -20,10 +20,10 @@ def initialize(invoice_item_path) :unit_price => row[:unit_price] }) end - require 'pry';binding.pry end + end diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index 0fd185e572..eac9df9a75 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -22,10 +22,13 @@ expect(ii_repo.all.count).to eq(21830) end - xit '' do + xit 'can find all by id' do invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) - expect() + + expect(ii_repo.find_by_id(1)).to be_an_instance_of(InvoiceItem) + expect(ii_repo.find_by_id(999991)).to eq(nil) end + end From 2eaf3ad800a8a9fe2ffd15f669f95f071efe36f5 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 20:23:38 -0600 Subject: [PATCH 120/131] Feat: invoice_item_repository, find_by_id Co-authored-by: Nick Co-authored-by: Thiago Co-authored-by: Justin --- lib/invoice_item_repository.rb | 8 ++++++++ spec/invoice_item_repository_spec.rb | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index d498ff2175..fe5269e0d4 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -23,6 +23,14 @@ def initialize(invoice_item_path) end + def find_by_id(id) + @all.find do |invoice_item| + invoice_item.id.to_i == id + end + end + + + diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index eac9df9a75..90dbe2bdca 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -22,13 +22,13 @@ expect(ii_repo.all.count).to eq(21830) end - xit 'can find all by id' do + it 'can find all by id' do invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) expect(ii_repo.find_by_id(1)).to be_an_instance_of(InvoiceItem) expect(ii_repo.find_by_id(999991)).to eq(nil) end - + end From 1e164ec85b3ab2b1423de3f21227a465562e1b77 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 20:40:44 -0600 Subject: [PATCH 121/131] Test: find_all_by_item_id Co-authored-by: Thiago Co-authored-by: Nick Co-authored-by: Justin --- spec/invoice_item_repository_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index 90dbe2bdca..52f6974e9d 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -30,5 +30,13 @@ expect(ii_repo.find_by_id(999991)).to eq(nil) end + it 'can find all by item_id' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + + expect(ii_repo.find_all_by_item_id(263519844)).to be_an_instance_of(Array) + expect(ii_repo.find_all_by_item_id(999991)).to eq([]) + end + end From 7b0aec02c20d59d800a8c34f0787e83f1f33f3c4 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 20:53:05 -0600 Subject: [PATCH 122/131] Feat: invoice_item_repository / find_all_by_item id Co-authored-by: Justin Co-authored-by: Thiago --- lib/invoice_item_repository.rb | 8 +++++++- spec/invoice_item_repository_spec.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index fe5269e0d4..7c490139c2 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -29,7 +29,13 @@ def find_by_id(id) end end - + def find_all_by_item_id(item_id) + @all.find_all do |invoice_item| + invoice_item.item_id == item_id + end + end + + diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index 52f6974e9d..5f525b279f 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -39,4 +39,5 @@ end + end From 4cdc904b6acf71ae8c14ff10882864ca01e3acd9 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 21:04:19 -0600 Subject: [PATCH 123/131] Feat: find_all_by_invoice_id Co-authored-by: Thiago Co-authored-by: Justin Co-authored-by: Nick --- lib/invoice_item_repository.rb | 6 ++++++ spec/invoice_item_repository_spec.rb | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index 7c490139c2..673e9594c2 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -35,6 +35,12 @@ def find_all_by_item_id(item_id) end end + def find_all_by_invoice_id(invoice_id) + @all.find_all do |invoice_item| + invoice_item.invoice_id.to_i == invoice_id + end + end + diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index 5f525b279f..7bf51bf067 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -38,6 +38,13 @@ expect(ii_repo.find_all_by_item_id(999991)).to eq([]) end - + it 'can find all by invoice_id' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + + expect(ii_repo.find_all_by_invoice_id(1)).to be_instance_of(Array) + expect(ii_repo.find_all_by_invoice_id(999991)).to eq([]) + expect(ii_repo.find_all_by_invoice_id(1).size).to eq(8) + end end From f3d7771bb4f780c60b6640011118ebf925953ee5 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 21:42:18 -0600 Subject: [PATCH 124/131] Test: create new_item with attributes Co-authored-by: Thiago Co-authored-by: Nick --- spec/invoice_item_repository_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index 7bf51bf067..f99c0ddf9e 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -47,4 +47,21 @@ expect(ii_repo.find_all_by_invoice_id(1).size).to eq(8) end + it 'can create attributes' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + new_item_attributes = {:item_id => "2635999123", :invoice_id => "4986", + :unit_price => "99999",:quantity => 9} + + new_item = (ii_repo.create(new_item_attributes)) + + expect(new_item.id).to eq("21831") + expect(new_item.item_id).to eq("2635999123") + expect(new_item.invoice_id).to eq("4986") + expect(new_item.unit_price).to eq("99999") + expect(new_item.created_at).to be_an_instance_of(Time) + expect(new_item.find_by_id("21831")).to be_an_instance_of(InvoiceItem) + end + + end From 31562231b8499730d4b4d41d9d4857f7eed78fb5 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 22:00:53 -0600 Subject: [PATCH 125/131] Feat: create new item and attributes Co-authored-by: Thiago Co-authored-by: Nick --- lib/invoice_item_repository.rb | 7 +++++++ spec/invoice_item_repository_spec.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index 673e9594c2..e3a5d46df0 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -41,7 +41,14 @@ def find_all_by_invoice_id(invoice_id) end end + def create(new_invoice_attributes) + new_id = @all.last.id.to_i + 1 + new_attribute = new_invoice_attributes + @all << InvoiceItem.new(:id => new_id.to_s, :item_id => new_attribute[:item_id], :invoice_id => + new_attribute[:invoice_id], :unit_price => new_attribute[:unit_price], :created_at => Time.now, :updated_at => Time.now) + return @all.last + end diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index f99c0ddf9e..9023c29ef8 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -60,7 +60,7 @@ expect(new_item.invoice_id).to eq("4986") expect(new_item.unit_price).to eq("99999") expect(new_item.created_at).to be_an_instance_of(Time) - expect(new_item.find_by_id("21831")).to be_an_instance_of(InvoiceItem) + expect(ii_repo.find_by_id(21831)).to be_an_instance_of(InvoiceItem) end From 77d122ec830824f14527f394970e2f09cc873e3e Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 22:37:09 -0600 Subject: [PATCH 126/131] Test: update invoice item attributes Co-authored-by: Thiago Co-authored-by: Nick --- lib/invoice_item_repository.rb | 2 +- spec/invoice_item_repository_spec.rb | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index e3a5d46df0..5c403fe85d 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -45,7 +45,7 @@ def create(new_invoice_attributes) new_id = @all.last.id.to_i + 1 new_attribute = new_invoice_attributes @all << InvoiceItem.new(:id => new_id.to_s, :item_id => new_attribute[:item_id], :invoice_id => - new_attribute[:invoice_id], :unit_price => new_attribute[:unit_price], :created_at => Time.now, :updated_at => Time.now) + new_attribute[:invoice_id], :unit_price => new_attribute[:unit_price], :quantity => new_attribute[:quantity], :created_at => Time.now, :updated_at => Time.now) return @all.last end diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index 9023c29ef8..ed977521ec 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -51,7 +51,7 @@ invoice_items = './data/invoice_items.csv' ii_repo = InvoiceItemRepository.new(invoice_items) new_item_attributes = {:item_id => "2635999123", :invoice_id => "4986", - :unit_price => "99999",:quantity => 9} + :unit_price => "99999",:quantity => "9"} new_item = (ii_repo.create(new_item_attributes)) @@ -59,9 +59,27 @@ expect(new_item.item_id).to eq("2635999123") expect(new_item.invoice_id).to eq("4986") expect(new_item.unit_price).to eq("99999") + expect(new_item.quantity).to eq("9") expect(new_item.created_at).to be_an_instance_of(Time) expect(ii_repo.find_by_id(21831)).to be_an_instance_of(InvoiceItem) end + it 'can update Invoice items with attributes' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + + expect(ii_repo.find_by_id(10).quantity).to eq("4") + expect(ii_repo.find_by_id(10).unit_price).to eq("1859") + + new_test_attributes = {:quantity => "99", :unit_price => "2000", :updated_at => "1"} + ii_repo.update(10, new_test_attributes) + + expect(ii_repo.find_by_id(10).quantity).to eq("99") + expect(ii_repo.find_by_id(10).unit_price).to eq("2000") + expect(ii_repo.find_by_id(10).updated_at).to be_an_instance_of(Time) + + end + + end From 04d6f406e6433e507dc99a35f1f37ba2455a4f89 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 22:47:30 -0600 Subject: [PATCH 127/131] Feat: update method for invoice item repository Co-authored-by: Thiago Co-authored-by: Nick --- lib/invoice_item.rb | 9 +++++---- lib/invoice_item_repository.rb | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/invoice_item.rb b/lib/invoice_item.rb index 285eaed7f0..f0979cba7b 100644 --- a/lib/invoice_item.rb +++ b/lib/invoice_item.rb @@ -2,11 +2,12 @@ class InvoiceItem attr_reader :id, :item_id, :invoice_id, - :quantity, - :unit_price, :created_at, - :unit_price_to_dollars, - :updated_at + :unit_price_to_dollars + +attr_accessor :quantity, + :unit_price, + :updated_at def initialize(data) @id = data[:id] diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index 5c403fe85d..f9a8a9a185 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -50,6 +50,13 @@ def create(new_invoice_attributes) end + def update(id, attributes) + updated_item = find_by_id(id) + updated_item.quantity = attributes[:quantity] + updated_item.unit_price = attributes[:unit_price] + updated_item.updated_at = Time.now + end + From 703a37a5f42f3e4382e10deb677d6ae454ffa523 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 22:56:13 -0600 Subject: [PATCH 128/131] Test: delete invoice item instance Co-authored-by: Thiago Co-authored-by: Nick --- spec/invoice_item_repository_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index ed977521ec..0c716fdb66 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -80,6 +80,13 @@ end + it 'can delete the InvoiceItem instance with the corresponding id' do + invoice_items = './data/invoice_items.csv' + ii_repo = InvoiceItemRepository.new(invoice_items) + expect(ii_repo.find_by_id(10)).to be_a(InvoiceItem) + item_repo.delete(10) + expect(ii_repo.find_by_id(10)).to eq(nil) + end end From 1ce2185f7a3b669562b3d3bd162792a55bd9d648 Mon Sep 17 00:00:00 2001 From: Kevin Ta Date: Mon, 6 Jun 2022 23:00:11 -0600 Subject: [PATCH 129/131] Feat: delete invoice item repo Co-authored-by: Thiago Co-authored-by: Nick --- lib/invoice_item_repository.rb | 5 ++++- spec/invoice_item_repository_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/invoice_item_repository.rb b/lib/invoice_item_repository.rb index f9a8a9a185..17ad9a5df0 100644 --- a/lib/invoice_item_repository.rb +++ b/lib/invoice_item_repository.rb @@ -57,7 +57,10 @@ def update(id, attributes) updated_item.updated_at = Time.now end - + def delete(id) + removed_item = find_by_id(id) + @all.delete(removed_item) + end end diff --git a/spec/invoice_item_repository_spec.rb b/spec/invoice_item_repository_spec.rb index 0c716fdb66..22471d300e 100644 --- a/spec/invoice_item_repository_spec.rb +++ b/spec/invoice_item_repository_spec.rb @@ -85,7 +85,7 @@ ii_repo = InvoiceItemRepository.new(invoice_items) expect(ii_repo.find_by_id(10)).to be_a(InvoiceItem) - item_repo.delete(10) + ii_repo.delete(10) expect(ii_repo.find_by_id(10)).to eq(nil) end From 735d059ac079c5fc5895825fe75f4c11064ee605 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Mon, 6 Jun 2022 23:14:05 -0600 Subject: [PATCH 130/131] Delete item_spec.rb Delete the deletions. --- spec/item_spec.rb | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 spec/item_spec.rb diff --git a/spec/item_spec.rb b/spec/item_spec.rb deleted file mode 100644 index b0cb7f1124..0000000000 --- a/spec/item_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ - -require './lib/item.rb' -require 'BigDecimal' -RSpec.describe Item do - - i = Item.new({ - :id => 1, - :name => "Pencil", - :description => "You can use it to write things", - :unit_price => BigDecimal(10.99,4), - :created_at => Time.now, - :updated_at => Time.now, - :merchant_id => 2 - }) - - it 'exists' do - expect(i).to be_a(Item) - end - - it 'item has attributes' do - time = Time.new - expect(i.id).to eq(1) - expect(i.name).to eq("Pencil") - expect(i.description).to eq("You can use it to write things") - expect(i.unit_price).to eq(BigDecimal(10.99,4)) - expect(i.created_at).to eq(time) - expect(i.updated_at).to eq(time) - expect(i.merchant_id).to eq(2) - end - it 'returns the price of the item in dollars' do - expect(i.unit_price_to_dollars).to eq(10.99) - end - - - - -end From 6a7cccaef4202b018e31cb98fdb2b434935b7343 Mon Sep 17 00:00:00 2001 From: Thiago Silveira Date: Mon, 6 Jun 2022 23:18:49 -0600 Subject: [PATCH 131/131] Delete sales_analyst_spec.rb Deleting misc changes. --- spec/sales_analyst_spec.rb | 260 ------------------------------------- 1 file changed, 260 deletions(-) delete mode 100644 spec/sales_analyst_spec.rb diff --git a/spec/sales_analyst_spec.rb b/spec/sales_analyst_spec.rb deleted file mode 100644 index 70952d2ca2..0000000000 --- a/spec/sales_analyst_spec.rb +++ /dev/null @@ -1,260 +0,0 @@ -require "./lib/sales_engine" -require "./lib/item_repository" -require "./lib/merchant_repository" -require "./lib/invoice_repository" -require "./lib/sales_analyst" - -RSpec.describe SalesAnalyst do - it 'exists' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst).to be_an_instance_of(SalesAnalyst) - end - - it 'can return the average items per merchant' do - #total items divided by total merchants - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_items_per_merchant).to eq(2.88) - end - - it 'can return the standard deviation of average items per merchant' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_items_per_merchant_standard_deviation).to eq(3.26) - end - - it 'can display the merchants who have the most items for sale' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.merchants_with_high_item_count).to be_a(Array) - # 52 was the length of our merchants_with_high_sales array - expect(sales_analyst.merchants_with_high_item_count.count).to eq(52) - end - - it 'can return average price of a merchants items' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_item_price_for_merchant(12334159)).to be_a(BigDecimal) - expect(sales_analyst.average_item_price_for_merchant(12334159)).to eq(3150.0) - end - - it 'can return average of the average price per merchant' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_average_price_per_merchant).to be_a(BigDecimal) - expect(sales_analyst.average_average_price_per_merchant).to eq(0.251e5) #(25108.91441111924) - end - - it "can return a standard deviation" do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - expect(sales_analyst.standard_deviation([1, 2 ,3], 2)).to eq(1) - end - - it 'can return the golden items' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.golden_items).to be_a(Array) - end - - it 'can average invoices per merchant' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_invoices_per_merchant).to eq(10.49) - end - - it 'can return standard deviation of average invoices per merchant' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_invoices_per_merchant_standard_deviation).to eq(3.29) - end - - it 'can calculate zscore for a merchant' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.merchant_z_score(4)).to eq(-1.97) - end - - it 'can create a hash of merchants by zscore' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.merchants_by_zscore.keys.include?("12334753")).to eq(true) - expect(sales_analyst.merchants_by_zscore.values.include?(1.37)).to eq(true) - expect(sales_analyst.merchants_by_zscore["12334753"]).to eq(1.37) - end - - it 'can return the top performing merchants by invoice count' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.top_merchants_by_invoice_count.length).to eq(12) - end - - it 'can return the bottom performing merchants by invoice count' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.bottom_merchants_by_invoice_count.length).to eq(463) -end - - it 'can return the days of the week that see the most sales' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.top_days_by_invoice_count).to eq(["Wednesday"]) - end - - it 'can return the day of the week' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - expect(sales_analyst.date_to_day("2009-02-07")).to eq("Saturday") - end - - it 'can return the invoices by day of the week' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.invoices_by_day.values.count).to eq(7) - end - - it 'can return the average invoices per day' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_invoices_per_day).to eq(712) - end - - it 'can return the average invoices per day standard deviation' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - expect(sales_analyst.average_invoices_per_day_standard_deviation).to eq(18.07) - end - - it 'can calculate z score for a day of the week' do - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - - - expect(sales_analyst.weekday_by_zscore.keys.include?("Saturday")).to eq(true) - expect(sales_analyst.weekday_by_zscore.values[0].class).to eq(Float) - end - -<<<<<<< HEAD - it 'can return the percentage of invoices by satus' do -======= - it 'can return the percentage of invoices by status' do ->>>>>>> af42e2a0c22e9a8ac8fc8faaa6957846608d9c4d - sales_engine = SalesEngine.from_csv({ - :items => "./data/items.csv", - :merchants => "./data/merchants.csv", - :invoices => "./data/invoices.csv" - }) - sales_analyst = sales_engine.analyst - -<<<<<<< HEAD - expect(sales_analyst.invoice_status(:pending)).to eq(29.55) - expect(sales_analyst.invoice_status(:shipped)) - expect(sales_analyst.invoice_status(:returned)).to eq(13.5) - end -======= - expect(sales_analyst.invoice_status(:pending)).to eq(29.55) - expect(sales_analyst.invoice_status(:shipped)).to eq(56.95) - expect(sales_analyst.invoice_status(:returned)).to eq(13.5) - end - ->>>>>>> af42e2a0c22e9a8ac8fc8faaa6957846608d9c4d - -end