From 006606da283b39198745e8a9fbab05618a0c86d9 Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 22 Mar 2021 00:37:27 +0900 Subject: [PATCH 01/10] =?UTF-8?q?RSpec=E7=92=B0=E5=A2=83=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challengeA/yoshifumi_sawada/.rspec | 1 + challengeA/yoshifumi_sawada/Gemfile | 8 ++ challengeA/yoshifumi_sawada/Gemfile.lock | 26 +++++ challengeA/yoshifumi_sawada/lib/simulator.rb | 0 .../yoshifumi_sawada/spec/simulator_spec.rb | 5 + .../yoshifumi_sawada/spec/spec_helper.rb | 100 ++++++++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 challengeA/yoshifumi_sawada/.rspec create mode 100644 challengeA/yoshifumi_sawada/Gemfile create mode 100644 challengeA/yoshifumi_sawada/Gemfile.lock create mode 100644 challengeA/yoshifumi_sawada/lib/simulator.rb create mode 100644 challengeA/yoshifumi_sawada/spec/simulator_spec.rb create mode 100644 challengeA/yoshifumi_sawada/spec/spec_helper.rb diff --git a/challengeA/yoshifumi_sawada/.rspec b/challengeA/yoshifumi_sawada/.rspec new file mode 100644 index 000000000..c99d2e739 --- /dev/null +++ b/challengeA/yoshifumi_sawada/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/challengeA/yoshifumi_sawada/Gemfile b/challengeA/yoshifumi_sawada/Gemfile new file mode 100644 index 000000000..559c8d79c --- /dev/null +++ b/challengeA/yoshifumi_sawada/Gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +# gem "rails" +gem "rspec", ">= 3.0.0" \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/Gemfile.lock b/challengeA/yoshifumi_sawada/Gemfile.lock new file mode 100644 index 000000000..2a76d548a --- /dev/null +++ b/challengeA/yoshifumi_sawada/Gemfile.lock @@ -0,0 +1,26 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.4.4) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + +PLATFORMS + ruby + +DEPENDENCIES + rspec (>= 3.0.0) + +BUNDLED WITH + 2.1.4 diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb new file mode 100644 index 000000000..e69de29bb diff --git a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb new file mode 100644 index 000000000..5ef12f333 --- /dev/null +++ b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb @@ -0,0 +1,5 @@ +describe '掛け算' do + it '3 * 3 は 9 になること' do + expect(3 * 3).to eq 9 + end +end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/spec/spec_helper.rb b/challengeA/yoshifumi_sawada/spec/spec_helper.rb new file mode 100644 index 000000000..251aa5106 --- /dev/null +++ b/challengeA/yoshifumi_sawada/spec/spec_helper.rb @@ -0,0 +1,100 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From c6c3f13b2075195541cbf02903f0bc7bec3556e7 Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 22 Mar 2021 00:43:44 +0900 Subject: [PATCH 02/10] =?UTF-8?q?pry(gem)=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challengeA/yoshifumi_sawada/Gemfile | 3 ++- challengeA/yoshifumi_sawada/Gemfile.lock | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/challengeA/yoshifumi_sawada/Gemfile b/challengeA/yoshifumi_sawada/Gemfile index 559c8d79c..75b60910c 100644 --- a/challengeA/yoshifumi_sawada/Gemfile +++ b/challengeA/yoshifumi_sawada/Gemfile @@ -5,4 +5,5 @@ source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } # gem "rails" -gem "rspec", ">= 3.0.0" \ No newline at end of file +gem "rspec", ">= 3.0.0" +gem 'pry', '~> 0.13.1' \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/Gemfile.lock b/challengeA/yoshifumi_sawada/Gemfile.lock index 2a76d548a..224b6b9d3 100644 --- a/challengeA/yoshifumi_sawada/Gemfile.lock +++ b/challengeA/yoshifumi_sawada/Gemfile.lock @@ -1,7 +1,12 @@ GEM remote: https://rubygems.org/ specs: + coderay (1.1.3) diff-lcs (1.4.4) + method_source (1.0.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -20,6 +25,7 @@ PLATFORMS ruby DEPENDENCIES + pry (~> 0.13.1) rspec (>= 3.0.0) BUNDLED WITH From 65332fe433657969e118ee7b301906c78ced2e7a Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 22 Mar 2021 00:55:24 +0900 Subject: [PATCH 03/10] =?UTF-8?q?CSV=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv | 8 ++++++++ challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv | 2 ++ challengeA/yoshifumi_sawada/csv/plans.csv | 4 ++++ .../csv/tokyo_energy_partner/basic_charge.csv | 8 ++++++++ .../csv/tokyo_energy_partner/usage_charge.csv | 4 ++++ challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv | 5 +++++ challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv | 4 ++++ 7 files changed, 35 insertions(+) create mode 100644 challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv create mode 100644 challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv create mode 100644 challengeA/yoshifumi_sawada/csv/plans.csv create mode 100644 challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/basic_charge.csv create mode 100644 challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv create mode 100644 challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv create mode 100644 challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv diff --git a/challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv new file mode 100644 index 000000000..76d887d02 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv @@ -0,0 +1,8 @@ +amp,basic_charge +10,0 +15,0 +20,0 +30,0 +40,0 +50,0 +60,0 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv new file mode 100644 index 000000000..bb518b91a --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv @@ -0,0 +1,2 @@ +kwh,unit_price +0,26.4 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/plans.csv b/challengeA/yoshifumi_sawada/csv/plans.csv new file mode 100644 index 000000000..3e09d4f64 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/plans.csv @@ -0,0 +1,4 @@ +provider_name,plan_name +東京電力エナジーパートナー,従量電灯B +Looopでんき,おうちプラン +東京ガス,ずっとも電気1 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/basic_charge.csv new file mode 100644 index 000000000..7794806e8 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/basic_charge.csv @@ -0,0 +1,8 @@ +amp,basic_charge +10,286 +15,429 +20,572 +30,858 +40,1144 +50,1430 +60,1716 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv new file mode 100644 index 000000000..9cf2d0f47 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv @@ -0,0 +1,4 @@ +kwh,unit_price +120,19.88 +300,26.48 +301,30.57 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv new file mode 100644 index 000000000..35092f505 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv @@ -0,0 +1,5 @@ +amp,basic_charge +30,858 +40,1144 +50,1430 +60,1716 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv new file mode 100644 index 000000000..4c4178f43 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv @@ -0,0 +1,4 @@ +kwh,unit_price +140,23.67 +350,23.88 +351,26.41 \ No newline at end of file From 37298c6aea636db63aced56186f8038262ad5180 Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 22 Mar 2021 01:04:38 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yoshifumi_sawada/lib/basic_charge.rb | 33 ++++ challengeA/yoshifumi_sawada/lib/plan.rb | 14 ++ challengeA/yoshifumi_sawada/lib/simulator.rb | 153 ++++++++++++++++++ .../yoshifumi_sawada/lib/usage_charge.rb | 35 ++++ 4 files changed, 235 insertions(+) create mode 100644 challengeA/yoshifumi_sawada/lib/basic_charge.rb create mode 100644 challengeA/yoshifumi_sawada/lib/plan.rb create mode 100644 challengeA/yoshifumi_sawada/lib/usage_charge.rb diff --git a/challengeA/yoshifumi_sawada/lib/basic_charge.rb b/challengeA/yoshifumi_sawada/lib/basic_charge.rb new file mode 100644 index 000000000..523d49528 --- /dev/null +++ b/challengeA/yoshifumi_sawada/lib/basic_charge.rb @@ -0,0 +1,33 @@ +require "csv" +require "pry" + +class Basic_charge + def self.import(path) + #全てを読込、配列を作成 + CSV.read("csv/tokyo_energy_partner/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"], + basic_charge: row["basic_charge"] + } + end + end + + # 以下、共通化すること + def self.import2(path) + CSV.read("csv/tokyogas/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"], + basic_charge: row["basic_charge"] + } + end + end + + def self.import3(path) + CSV.read("csv/loop/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"], + basic_charge: row["basic_charge"] + } + end + end +end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/plan.rb b/challengeA/yoshifumi_sawada/lib/plan.rb new file mode 100644 index 000000000..ef85a3851 --- /dev/null +++ b/challengeA/yoshifumi_sawada/lib/plan.rb @@ -0,0 +1,14 @@ +require "csv" +require "pry" + +class Plan + def self.import(path) + #全てを読込、配列を作成 + CSV.read("csv/plans.csv", headers: true).map do |row| + { + provider_name: row["provider_name"], + plan_name: row["plan_name"] + } + end + end +end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb index e69de29bb..88081d767 100644 --- a/challengeA/yoshifumi_sawada/lib/simulator.rb +++ b/challengeA/yoshifumi_sawada/lib/simulator.rb @@ -0,0 +1,153 @@ +require "pry" +require_relative "plan" +require_relative "basic_charge" +require_relative "usage_charge" + +class Simulator + + def initialize(amp,usage_per_week) + @amp = amp + @usage_per_week = usage_per_week + end + + def simulate + # プロバイダと料金プランのCSVデータをインポート + csv_data = Plan.import(path: "csv/plans.csv") + # 該当プランに計算結果(メソッドの返り値)のハッシュを追加・全プラン表示 + plan_list = csv_data.each do |data| + case + when data[:provider_name] == "東京電力エナジーパートナー" + data[:price]= "#{self.calc_planA(@amp,@usage_per_week)}" + when data[:provider_name] == "Looopでんき" + data[:price]= "#{self.calc_planB(@amp,@usage_per_week)}" + when data[:provider_name] == "東京ガス" && [30,40,50,60].include?(@amp) + data[:price] = "#{self.calc_planC(@amp,@usage_per_week)}" + end + end + # priceにデータが入ってるプランのみに絞り込み + p output_array = plan_list.select{|plan| plan.has_key?(:price)} + end + + #各プランごとに計算メソッドを定義 + private + + #東京電力エナジーパートナーの従量電灯Bの計算メソッド + + def calc_planA(amp,usage_per_week) + + #基本料金テーブルのCSVデータをインポート + basic_charge_table = Basic_charge.import(path: "../csv/tokyo_energy_partner/basic_charge.csv") + + #入力値を含む料金データを取得 + charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } + #データから値を取得 + basic_charge = charge_data[:basic_charge].to_i + + #電気量料金テーブルのCSVデータをインポート + usage_charge_table = Usage_charge.import(path: "../csv/tokyo_energy_partner/usage_charge.csv") + #計算で使用する単価を取得 + usage_charge_data1 = usage_charge_table.find { |data| data[:kwh] == "120" } + usage_charge1 = usage_charge_data1[:unit_price].to_f + + usage_charge_data2 = usage_charge_table.find { |data| data[:kwh] == "300" } + usage_charge2 = usage_charge_data2[:unit_price].to_f + + usage_charge_data3 = usage_charge_table.find { |data| data[:kwh] == "301" } + usage_charge3 = usage_charge_data3[:unit_price].to_f + + usage_charge = + if usage_per_week <= 120 then usage_charge1*usage_per_week + elsif usage_per_week <= 300 then usage_charge1*120 + usage_charge2*(usage_per_week-120) + elsif usage_per_week > 300 then usage_charge1*120 + usage_charge2*180 + usage_charge3*(usage_per_week-300) + else '???' + end + + ## 最後の評価式 + total_charge = (basic_charge + usage_charge).floor + end + + # Looopでんきのおうちプランの計算メソッド + def calc_planB(amp,usage_per_week) + + #基本料金テーブルのCSVデータをインポート + basic_charge_table = Basic_charge.import3(path: "../csv/loop/basic_charge.csv") + #入力値を含む料金データを取得 + charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } + #データから値を取得 + basic_charge = charge_data[:basic_charge].to_i + + #電気量料金テーブルのCSVデータをインポート + usage_charge_table = Usage_charge.import2(path: "../csv/loop/usage_charge.csv") + + #計算で使用する単価を取得 + usage_charge_data = usage_charge_table.find { |data| data[:kwh] == "0" } + unit_price = usage_charge_data[:unit_price].to_f + + usage_charge = usage_per_week*unit_price + + # 最後の評価式 + total_charge = (basic_charge + usage_charge).floor + end + + # 東京ガスのずっとも電気1の計算メソッド + def calc_planC(amp,usage_per_week) + + #料金テーブルのCSVデータをインポート + basic_charge_table = Basic_charge.import2(path: "../csv/tokyogas/basic_charge.csv") + + #入力値を含む料金データを取得 + charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } + + #データから値を取得 + basic_charge = charge_data[:basic_charge].to_i + + #電気量料金テーブルのCSVデータをインポート + usage_charge_table = Usage_charge.import3(path: "../csv/tokyogas/usage_charge.csv") + + #計算で使用する単価を取得 + usage_charge_data1 = usage_charge_table.find { |data| data[:kwh] == "140" } + + unit_price1 = usage_charge_data1[:unit_price].to_f + + usage_charge_data2 = usage_charge_table.find { |data| data[:kwh] == "350" } + unit_price2 = usage_charge_data2[:unit_price].to_f + + usage_charge_data3 = usage_charge_table.find { |data| data[:kwh] == "351" } + unit_price3 = usage_charge_data3[:unit_price].to_f + + usage_charge = + if usage_per_week <= 140 then unit_price1*usage_per_week + elsif usage_per_week <= 350 then unit_price1*140 + unit_price2*(usage_per_week-140) + elsif usage_per_week > 350 then unit_price1*140 + unit_price2*210 + unit_price3*(usage_per_week-350) + else '???' + end + + # 最後の評価式 + total_charge = (basic_charge + usage_charge).floor + end +end + + +# #****************実行部分*************************************************************** + + +## 契約アンペアを入力 +while true +print "契約アンペアを入力して下さい > " + amp = gets.to_i + break if [10,15,20,30,40,50,60].include?(amp) + puts "10,15,20,30,40,50,60のいずれかを入力して下さい" +end + +## 1ヶ月あたりの使用量を入力 +while true +print "1ヶ月あたりの使用量を入力して下さい > " + usage_per_week = gets.to_i + break if usage_per_week >= 0 + puts "0以上の値を入力して下さい" +end + +# 入力値を引数にSimulatorクラスのインスタンスを生成 +simulator = Simulator.new(amp,usage_per_week) +# インスタンスに対してsimulateメソッド(計算メソッド)を実行して出力結果を表示する +simulator.simulate \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/usage_charge.rb b/challengeA/yoshifumi_sawada/lib/usage_charge.rb new file mode 100644 index 000000000..3087428a5 --- /dev/null +++ b/challengeA/yoshifumi_sawada/lib/usage_charge.rb @@ -0,0 +1,35 @@ +require "csv" +require "pry" + +class Usage_charge + def self.import(path) + #全てを読込、配列を作成 + CSV.read("csv/tokyo_energy_partner/usage_charge.csv", headers: true).map do |row| + { + kwh: row["kwh"], + unit_price: row["unit_price"] + } + end + end + + def self.import2(path) + #全てを読込、配列を作成 + CSV.read("csv/loop/usage_charge.csv", headers: true).map do |row| + { + kwh: row["kwh"], + unit_price: row["unit_price"] + } + end + end + + def self.import3(path) + #全てを読込、配列を作成 + CSV.read("csv/tokyogas/usage_charge.csv", headers: true).map do |row| + { + kwh: row["kwh"], + unit_price: row["unit_price"] + } + end + end + +end \ No newline at end of file From 6fdb5ae00adb196c55abf59884175ee4fda8aa9a Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 22 Mar 2021 01:08:02 +0900 Subject: [PATCH 05/10] =?UTF-8?q?RSpec=E3=82=B9=E3=83=9A=E3=83=83=E3=82=AF?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yoshifumi_sawada/spec/simulator_spec.rb | 130 +++++++++++++++++- 1 file changed, 127 insertions(+), 3 deletions(-) diff --git a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb index 5ef12f333..4de9edc68 100644 --- a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb +++ b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb @@ -1,5 +1,129 @@ -describe '掛け算' do - it '3 * 3 は 9 になること' do - expect(3 * 3).to eq 9 +require_relative '../lib/simulator.rb' + +RSpec.describe Simulator do + describe "プラン名と料金を含む配列数と段階別の計算結果" do + context "10Aの場合" do + it "10A/120kWhの場合、配列数2つ" do + simulator = Simulator.new(10, 120) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"2671"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"} + ) + end + it "10A/140kWhの場合、配列数2つ" do + simulator = Simulator.new(10, 140) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3201"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"} + ) + end + it "10A/300kWhの場合、配列数2つ" do + simulator = Simulator.new(10, 300) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"7438"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"} + ) + end + it "10A/350kWhの場合、配列数2つ" do + simulator = Simulator.new(10, 350) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8966"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"} + ) + end + it "10A/400kWhの場合、配列数2つ" do + simulator = Simulator.new(10, 400) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"10495"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"} + ) + end + end + + context "30Aの場合" do + it "30A/120kWhの場合、配列数3つ" do + simulator = Simulator.new(30, 120) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3243"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3698"} + ) + end + it "30A/140kWhの場合、配列数3つ" do + simulator = Simulator.new(30, 140) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3773"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4171"} + ) + end + it "30A/300kWhの場合、配列数3つ" do + simulator = Simulator.new(30, 300) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8010"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"7992"} + ) + end + it "30A/350kWhの場合、配列数3つ" do + simulator = Simulator.new(30, 350) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9538"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9186"} + ) + end + it "30A/400kWhの場合、配列数3つ" do + simulator = Simulator.new(30, 400) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"11067"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10507"} + ) + end + end + + context "40Aの場合" do + it "40A/120kWhの場合、配列数3つ" do + simulator = Simulator.new(40, 120) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3529"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3984"} + ) + end + it "40A/140kWhの場合、配列数3つ" do + simulator = Simulator.new(40, 140) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"4059"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4457"} + ) + end + it "40A/300kWhの場合、配列数3つ" do + simulator = Simulator.new(40, 300) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8296"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8278"} + ) + end + it "40A/350kWhの場合、配列数3つ" do + simulator = Simulator.new(40, 350) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9824"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9472"} + ) + end + it "40A/400kWhの場合、配列数3つ" do + simulator = Simulator.new(40, 400) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"11353"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10793"} + ) + end + end end end \ No newline at end of file From 1ef61b645ed443593891d77d64c7a8f3b33211b4 Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 22 Mar 2021 11:09:11 +0900 Subject: [PATCH 06/10] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yoshifumi_sawada/lib/basic_charge.rb | 2 +- challengeA/yoshifumi_sawada/lib/plan.rb | 2 +- challengeA/yoshifumi_sawada/lib/simulator.rb | 70 ++++++++++--------- .../yoshifumi_sawada/lib/usage_charge.rb | 4 +- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/challengeA/yoshifumi_sawada/lib/basic_charge.rb b/challengeA/yoshifumi_sawada/lib/basic_charge.rb index 523d49528..6685d5c09 100644 --- a/challengeA/yoshifumi_sawada/lib/basic_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/basic_charge.rb @@ -3,7 +3,7 @@ class Basic_charge def self.import(path) - #全てを読込、配列を作成 + # 全てを読込、配列を作成 CSV.read("csv/tokyo_energy_partner/basic_charge.csv", headers: true).map do |row| { amp: row["amp"], diff --git a/challengeA/yoshifumi_sawada/lib/plan.rb b/challengeA/yoshifumi_sawada/lib/plan.rb index ef85a3851..6e8b58f49 100644 --- a/challengeA/yoshifumi_sawada/lib/plan.rb +++ b/challengeA/yoshifumi_sawada/lib/plan.rb @@ -3,7 +3,7 @@ class Plan def self.import(path) - #全てを読込、配列を作成 + # 全てを読込、配列を作成 CSV.read("csv/plans.csv", headers: true).map do |row| { provider_name: row["provider_name"], diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb index 88081d767..2084ed8cc 100644 --- a/challengeA/yoshifumi_sawada/lib/simulator.rb +++ b/challengeA/yoshifumi_sawada/lib/simulator.rb @@ -11,9 +11,9 @@ def initialize(amp,usage_per_week) end def simulate - # プロバイダと料金プランのCSVデータをインポート + # プロバイダと料金プラン名のCSVデータをインポート csv_data = Plan.import(path: "csv/plans.csv") - # 該当プランに計算結果(メソッドの返り値)のハッシュを追加・全プラン表示 + # 該当プランに計算結果(メソッドの返り値)のハッシュを追加 plan_list = csv_data.each do |data| case when data[:provider_name] == "東京電力エナジーパートナー" @@ -24,89 +24,90 @@ def simulate data[:price] = "#{self.calc_planC(@amp,@usage_per_week)}" end end - # priceにデータが入ってるプランのみに絞り込み + # priceキーに値が入ってるプランのみを表示 p output_array = plan_list.select{|plan| plan.has_key?(:price)} end - #各プランごとに計算メソッドを定義 - private - #東京電力エナジーパートナーの従量電灯Bの計算メソッド + private + # 東京電力エナジーパートナーの従量電灯Bの計算メソッド def calc_planA(amp,usage_per_week) - #基本料金テーブルのCSVデータをインポート + # 基本料金テーブルのCSVデータをインポート basic_charge_table = Basic_charge.import(path: "../csv/tokyo_energy_partner/basic_charge.csv") - #入力値を含む料金データを取得 + # 入力アンペアに対応する基本料金データ行を取得 charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } - #データから値を取得 + + # データ行から基本料金を取得 basic_charge = charge_data[:basic_charge].to_i - #電気量料金テーブルのCSVデータをインポート + # 電気量料金テーブルのCSVデータをインポート usage_charge_table = Usage_charge.import(path: "../csv/tokyo_energy_partner/usage_charge.csv") - #計算で使用する単価を取得 + + # 計算で使用する単価を取得 usage_charge_data1 = usage_charge_table.find { |data| data[:kwh] == "120" } - usage_charge1 = usage_charge_data1[:unit_price].to_f + unit_price1 = usage_charge_data1[:unit_price].to_f usage_charge_data2 = usage_charge_table.find { |data| data[:kwh] == "300" } - usage_charge2 = usage_charge_data2[:unit_price].to_f + unit_price2 = usage_charge_data2[:unit_price].to_f usage_charge_data3 = usage_charge_table.find { |data| data[:kwh] == "301" } - usage_charge3 = usage_charge_data3[:unit_price].to_f + unit_price3 = usage_charge_data3[:unit_price].to_f + # 料金計算部分 usage_charge = - if usage_per_week <= 120 then usage_charge1*usage_per_week - elsif usage_per_week <= 300 then usage_charge1*120 + usage_charge2*(usage_per_week-120) - elsif usage_per_week > 300 then usage_charge1*120 + usage_charge2*180 + usage_charge3*(usage_per_week-300) + if usage_per_week <= 120 then unit_price1*usage_per_week + elsif usage_per_week <= 300 then unit_price1*120 + unit_price2*(usage_per_week-120) + elsif usage_per_week > 300 then unit_price1*120 + unit_price2*180 + unit_price3*(usage_per_week-300) else '???' end - ## 最後の評価式 total_charge = (basic_charge + usage_charge).floor end # Looopでんきのおうちプランの計算メソッド def calc_planB(amp,usage_per_week) - #基本料金テーブルのCSVデータをインポート + # 基本料金テーブルのCSVデータをインポート basic_charge_table = Basic_charge.import3(path: "../csv/loop/basic_charge.csv") - #入力値を含む料金データを取得 + + # 入力アンペアに対応する基本料金データ行を取得 charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } - #データから値を取得 + + # データ行から基本料金を取得 basic_charge = charge_data[:basic_charge].to_i - #電気量料金テーブルのCSVデータをインポート + # 電気量料金テーブルのCSVデータをインポート usage_charge_table = Usage_charge.import2(path: "../csv/loop/usage_charge.csv") - #計算で使用する単価を取得 + # 計算で使用する単価を取得 usage_charge_data = usage_charge_table.find { |data| data[:kwh] == "0" } unit_price = usage_charge_data[:unit_price].to_f usage_charge = usage_per_week*unit_price - # 最後の評価式 total_charge = (basic_charge + usage_charge).floor end - # 東京ガスのずっとも電気1の計算メソッド + # 東京ガスのずっとも電気1の計算メソッド def calc_planC(amp,usage_per_week) - #料金テーブルのCSVデータをインポート + # 基本料金テーブルのCSVデータをインポート basic_charge_table = Basic_charge.import2(path: "../csv/tokyogas/basic_charge.csv") - #入力値を含む料金データを取得 + # 入力アンペアに対応する基本料金データ行を取得 charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } - #データから値を取得 + # データ行から基本料金を取得 basic_charge = charge_data[:basic_charge].to_i - #電気量料金テーブルのCSVデータをインポート + # 電気量料金テーブルのCSVデータをインポート usage_charge_table = Usage_charge.import3(path: "../csv/tokyogas/usage_charge.csv") - #計算で使用する単価を取得 + # 計算で使用する単価を取得 usage_charge_data1 = usage_charge_table.find { |data| data[:kwh] == "140" } - unit_price1 = usage_charge_data1[:unit_price].to_f usage_charge_data2 = usage_charge_table.find { |data| data[:kwh] == "350" } @@ -131,7 +132,7 @@ def calc_planC(amp,usage_per_week) # #****************実行部分*************************************************************** -## 契約アンペアを入力 +# 契約アンペアを入力して頂く while true print "契約アンペアを入力して下さい > " amp = gets.to_i @@ -139,7 +140,7 @@ def calc_planC(amp,usage_per_week) puts "10,15,20,30,40,50,60のいずれかを入力して下さい" end -## 1ヶ月あたりの使用量を入力 +# 1ヶ月あたりの使用量を入力して頂く while true print "1ヶ月あたりの使用量を入力して下さい > " usage_per_week = gets.to_i @@ -149,5 +150,6 @@ def calc_planC(amp,usage_per_week) # 入力値を引数にSimulatorクラスのインスタンスを生成 simulator = Simulator.new(amp,usage_per_week) -# インスタンスに対してsimulateメソッド(計算メソッド)を実行して出力結果を表示する + +# インスタンスに対してsimulateメソッド(計算メソッド)を実行して出力結果を表示 simulator.simulate \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/usage_charge.rb b/challengeA/yoshifumi_sawada/lib/usage_charge.rb index 3087428a5..c089383cc 100644 --- a/challengeA/yoshifumi_sawada/lib/usage_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/usage_charge.rb @@ -13,7 +13,7 @@ def self.import(path) end def self.import2(path) - #全てを読込、配列を作成 + # 全てを読込、配列を作成 CSV.read("csv/loop/usage_charge.csv", headers: true).map do |row| { kwh: row["kwh"], @@ -23,7 +23,7 @@ def self.import2(path) end def self.import3(path) - #全てを読込、配列を作成 + # 全てを読込、配列を作成 CSV.read("csv/tokyogas/usage_charge.csv", headers: true).map do |row| { kwh: row["kwh"], From e6e85e9a22560b58f3508496d02d541acd703f01 Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 22 Mar 2021 11:10:45 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E8=A1=8C=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challengeA/yoshifumi_sawada/lib/simulator.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb index 2084ed8cc..886f55ed7 100644 --- a/challengeA/yoshifumi_sawada/lib/simulator.rb +++ b/challengeA/yoshifumi_sawada/lib/simulator.rb @@ -13,6 +13,7 @@ def initialize(amp,usage_per_week) def simulate # プロバイダと料金プラン名のCSVデータをインポート csv_data = Plan.import(path: "csv/plans.csv") + # 該当プランに計算結果(メソッドの返り値)のハッシュを追加 plan_list = csv_data.each do |data| case @@ -24,6 +25,7 @@ def simulate data[:price] = "#{self.calc_planC(@amp,@usage_per_week)}" end end + # priceキーに値が入ってるプランのみを表示 p output_array = plan_list.select{|plan| plan.has_key?(:price)} end From 1b7d3f8e465777a78929eaedb0f7dfb2cb89f7ef Mon Sep 17 00:00:00 2001 From: zenfumi Date: Thu, 25 Mar 2021 23:02:13 +0900 Subject: [PATCH 08/10] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csv/tokyo_energy_partner/usage_charge.csv | 8 +- .../csv/tokyogas/usage_charge.csv | 8 +- .../yoshifumi_sawada/lib/basic_charge.rb | 6 +- challengeA/yoshifumi_sawada/lib/simulator.rb | 153 ++++++------------ .../yoshifumi_sawada/lib/usage_charge.rb | 10 +- 5 files changed, 64 insertions(+), 121 deletions(-) diff --git a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv index 9cf2d0f47..c5b4ea3c8 100644 --- a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv +++ b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv @@ -1,4 +1,4 @@ -kwh,unit_price -120,19.88 -300,26.48 -301,30.57 \ No newline at end of file +kwh_from,kwh_to,unit_price +0,120,19.88 +120,300,26.48 +300,10000,30.57 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv index 4c4178f43..89ac5f02d 100644 --- a/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv +++ b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv @@ -1,4 +1,4 @@ -kwh,unit_price -140,23.67 -350,23.88 -351,26.41 \ No newline at end of file +kwh_from,kwh_to,unit_price +0,140,23.67 +140,350,23.88 +350,10000,26.41 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/basic_charge.rb b/challengeA/yoshifumi_sawada/lib/basic_charge.rb index 6685d5c09..27c34a0ae 100644 --- a/challengeA/yoshifumi_sawada/lib/basic_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/basic_charge.rb @@ -3,7 +3,7 @@ class Basic_charge def self.import(path) - # 全てを読込、配列を作成 + #全てを読込、配列を作成 CSV.read("csv/tokyo_energy_partner/basic_charge.csv", headers: true).map do |row| { amp: row["amp"], @@ -14,7 +14,7 @@ def self.import(path) # 以下、共通化すること def self.import2(path) - CSV.read("csv/tokyogas/basic_charge.csv", headers: true).map do |row| + CSV.read("csv/loop/basic_charge.csv", headers: true).map do |row| { amp: row["amp"], basic_charge: row["basic_charge"] @@ -23,7 +23,7 @@ def self.import2(path) end def self.import3(path) - CSV.read("csv/loop/basic_charge.csv", headers: true).map do |row| + CSV.read("csv/tokyogas/basic_charge.csv", headers: true).map do |row| { amp: row["amp"], basic_charge: row["basic_charge"] diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb index 886f55ed7..a05309f29 100644 --- a/challengeA/yoshifumi_sawada/lib/simulator.rb +++ b/challengeA/yoshifumi_sawada/lib/simulator.rb @@ -5,24 +5,50 @@ class Simulator - def initialize(amp,usage_per_week) + def initialize(amp,usage_per_month) @amp = amp - @usage_per_week = usage_per_week + @usage_per_month = usage_per_month end def simulate + # 東京電力エナジーパートナー従量電灯Bの電気量料金のCSVデータをインポート + usage_datas = Usage_charge.import(path: "../csv/tokyo_energy_partner/usage_charge.csv") + # 東京電力エナジーパートナーの従量電灯Bの電気量料金 + usage_charge1 = calculate(usage_datas) + # 東京ガスのずっとも電気1の電気量料金の電気量料金テーブルのCSVデータをインポート + usage_datas3 = Usage_charge.import3(path: "../csv/tokyogas/usage_charge.csv") + # 東京ガスのずっとも電気1の電気量料金 + usage_charge3 = calculate(usage_datas3) + # Looopでんきのおうちプランの電気量料金テーブルのCSVデータをインポート + usage_datas2 = Usage_charge.import2(path: "../csv/loop/usage_charge.csv") + # Looopでんきのおうちプランの電気量料金の単価 + usage_charge_data2 = usage_datas2.find { |data| data[:kwh] == "0" } + unit_price2 = usage_charge_data2[:unit_price].to_f + + + # 基本料金テーブルのCSVデータをインポート + basic_charge_table = Basic_charge.import(path: "../csv/tokyo_energy_partner/basic_charge.csv") + basic_charge_table2 = Basic_charge.import2(path: "../csv/loop/basic_charge.csv") + basic_charge_table3 = Basic_charge.import3(path: "../csv/tokyogas/basic_charge.csv") + + # プロバイダと料金プラン名のCSVデータをインポート - csv_data = Plan.import(path: "csv/plans.csv") + plan_datas = Plan.import(path: "csv/plans.csv") - # 該当プランに計算結果(メソッドの返り値)のハッシュを追加 - plan_list = csv_data.each do |data| + # 該当プランに価格の計算結果のハッシュを追加 + plan_list = plan_datas.each do |data| case when data[:provider_name] == "東京電力エナジーパートナー" - data[:price]= "#{self.calc_planA(@amp,@usage_per_week)}" + charge_data = basic_charge_table.find { |data| data[:amp] == "#{@amp}" } + data[:price]= (charge_data[:basic_charge].to_i + usage_charge1).floor.to_s + when data[:provider_name] == "Looopでんき" - data[:price]= "#{self.calc_planB(@amp,@usage_per_week)}" + charge_data2 = basic_charge_table2.find { |data| data[:amp] == "#{@amp}" } + data[:price]= (charge_data2[:basic_charge].to_i + @usage_per_month * unit_price2).floor.to_s + when data[:provider_name] == "東京ガス" && [30,40,50,60].include?(@amp) - data[:price] = "#{self.calc_planC(@amp,@usage_per_week)}" + charge_data3 = basic_charge_table3.find { |data| data[:amp] == "#{@amp}" } + data[:price]= (charge_data3[:basic_charge].to_i + usage_charge3).floor.to_s end end @@ -30,107 +56,22 @@ def simulate p output_array = plan_list.select{|plan| plan.has_key?(:price)} end - private - # 東京電力エナジーパートナーの従量電灯Bの計算メソッド - def calc_planA(amp,usage_per_week) - - # 基本料金テーブルのCSVデータをインポート - basic_charge_table = Basic_charge.import(path: "../csv/tokyo_energy_partner/basic_charge.csv") - - # 入力アンペアに対応する基本料金データ行を取得 - charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } - - # データ行から基本料金を取得 - basic_charge = charge_data[:basic_charge].to_i - - # 電気量料金テーブルのCSVデータをインポート - usage_charge_table = Usage_charge.import(path: "../csv/tokyo_energy_partner/usage_charge.csv") - - # 計算で使用する単価を取得 - usage_charge_data1 = usage_charge_table.find { |data| data[:kwh] == "120" } - unit_price1 = usage_charge_data1[:unit_price].to_f - - usage_charge_data2 = usage_charge_table.find { |data| data[:kwh] == "300" } - unit_price2 = usage_charge_data2[:unit_price].to_f - - usage_charge_data3 = usage_charge_table.find { |data| data[:kwh] == "301" } - unit_price3 = usage_charge_data3[:unit_price].to_f - - # 料金計算部分 - usage_charge = - if usage_per_week <= 120 then unit_price1*usage_per_week - elsif usage_per_week <= 300 then unit_price1*120 + unit_price2*(usage_per_week-120) - elsif usage_per_week > 300 then unit_price1*120 + unit_price2*180 + unit_price3*(usage_per_week-300) - else '???' - end - - total_charge = (basic_charge + usage_charge).floor - end - - # Looopでんきのおうちプランの計算メソッド - def calc_planB(amp,usage_per_week) - - # 基本料金テーブルのCSVデータをインポート - basic_charge_table = Basic_charge.import3(path: "../csv/loop/basic_charge.csv") - - # 入力アンペアに対応する基本料金データ行を取得 - charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } - - # データ行から基本料金を取得 - basic_charge = charge_data[:basic_charge].to_i - - # 電気量料金テーブルのCSVデータをインポート - usage_charge_table = Usage_charge.import2(path: "../csv/loop/usage_charge.csv") - - # 計算で使用する単価を取得 - usage_charge_data = usage_charge_table.find { |data| data[:kwh] == "0" } - unit_price = usage_charge_data[:unit_price].to_f - - usage_charge = usage_per_week*unit_price - - total_charge = (basic_charge + usage_charge).floor - end - - # 東京ガスのずっとも電気1の計算メソッド - def calc_planC(amp,usage_per_week) - - # 基本料金テーブルのCSVデータをインポート - basic_charge_table = Basic_charge.import2(path: "../csv/tokyogas/basic_charge.csv") - - # 入力アンペアに対応する基本料金データ行を取得 - charge_data = basic_charge_table.find { |data| data[:amp] == "#{amp}" } - - # データ行から基本料金を取得 - basic_charge = charge_data[:basic_charge].to_i - - # 電気量料金テーブルのCSVデータをインポート - usage_charge_table = Usage_charge.import3(path: "../csv/tokyogas/usage_charge.csv") - - # 計算で使用する単価を取得 - usage_charge_data1 = usage_charge_table.find { |data| data[:kwh] == "140" } - unit_price1 = usage_charge_data1[:unit_price].to_f - - usage_charge_data2 = usage_charge_table.find { |data| data[:kwh] == "350" } - unit_price2 = usage_charge_data2[:unit_price].to_f - - usage_charge_data3 = usage_charge_table.find { |data| data[:kwh] == "351" } - unit_price3 = usage_charge_data3[:unit_price].to_f - - usage_charge = - if usage_per_week <= 140 then unit_price1*usage_per_week - elsif usage_per_week <= 350 then unit_price1*140 + unit_price2*(usage_per_week-140) - elsif usage_per_week > 350 then unit_price1*140 + unit_price2*210 + unit_price3*(usage_per_week-350) - else '???' + # 段階別料金プランの計算 + def calculate(usage_datas) + usage_charge = 0 + usage_datas.each do |usage_data| + if usage_data[:kwh_from].to_i < @usage_per_month && @usage_per_month <= usage_data[:kwh_to].to_i + usage_charge = usage_charge + usage_data[:unit_price].to_f * (@usage_per_month - usage_data[:kwh_from].to_i) + elsif usage_data[:kwh_to].to_i < @usage_per_month + usage_charge = usage_charge + usage_data[:unit_price].to_f * (usage_data[:kwh_to].to_i - usage_data[:kwh_from].to_i) end - - # 最後の評価式 - total_charge = (basic_charge + usage_charge).floor + end + return usage_charge end end - # #****************実行部分*************************************************************** @@ -145,13 +86,13 @@ def calc_planC(amp,usage_per_week) # 1ヶ月あたりの使用量を入力して頂く while true print "1ヶ月あたりの使用量を入力して下さい > " - usage_per_week = gets.to_i - break if usage_per_week >= 0 + usage_per_month = gets.to_i + break if usage_per_month >= 0 puts "0以上の値を入力して下さい" end # 入力値を引数にSimulatorクラスのインスタンスを生成 -simulator = Simulator.new(amp,usage_per_week) +simulator = Simulator.new(amp,usage_per_month) # インスタンスに対してsimulateメソッド(計算メソッド)を実行して出力結果を表示 simulator.simulate \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/usage_charge.rb b/challengeA/yoshifumi_sawada/lib/usage_charge.rb index c089383cc..67ebb1ce1 100644 --- a/challengeA/yoshifumi_sawada/lib/usage_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/usage_charge.rb @@ -6,14 +6,15 @@ def self.import(path) #全てを読込、配列を作成 CSV.read("csv/tokyo_energy_partner/usage_charge.csv", headers: true).map do |row| { - kwh: row["kwh"], + kwh_from: row["kwh_from"], + kwh_to: row["kwh_to"], unit_price: row["unit_price"] } end end def self.import2(path) - # 全てを読込、配列を作成 + #全てを読込、配列を作成 CSV.read("csv/loop/usage_charge.csv", headers: true).map do |row| { kwh: row["kwh"], @@ -23,10 +24,11 @@ def self.import2(path) end def self.import3(path) - # 全てを読込、配列を作成 + #全てを読込、配列を作成 CSV.read("csv/tokyogas/usage_charge.csv", headers: true).map do |row| { - kwh: row["kwh"], + kwh_from: row["kwh_from"], + kwh_to: row["kwh_to"], unit_price: row["unit_price"] } end From 3c481389e0b1934d67e6cef895325befdfc4a4bd Mon Sep 17 00:00:00 2001 From: zenfumi Date: Thu, 25 Mar 2021 23:42:25 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=E3=83=97=E3=83=A9=E3=83=B3=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csv/jxtg/basic_charge.csv | 5 ++ .../csv/jxtg/usage_charge.csv | 5 ++ challengeA/yoshifumi_sawada/csv/plans.csv | 3 +- .../yoshifumi_sawada/lib/basic_charge.rb | 9 ++++ challengeA/yoshifumi_sawada/lib/simulator.rb | 11 ++++ .../yoshifumi_sawada/lib/usage_charge.rb | 10 ++++ .../yoshifumi_sawada/spec/simulator_spec.rb | 50 +++++++++++-------- 7 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 challengeA/yoshifumi_sawada/csv/jxtg/basic_charge.csv create mode 100644 challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv diff --git a/challengeA/yoshifumi_sawada/csv/jxtg/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/jxtg/basic_charge.csv new file mode 100644 index 000000000..35092f505 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/jxtg/basic_charge.csv @@ -0,0 +1,5 @@ +amp,basic_charge +30,858 +40,1144 +50,1430 +60,1716 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv new file mode 100644 index 000000000..8194cc7c9 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv @@ -0,0 +1,5 @@ +kwh_from,kwh_to,unit_price +0,120,19.88 +120,300,26.48 +300,600,25.08 +600,10000,26.15 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/plans.csv b/challengeA/yoshifumi_sawada/csv/plans.csv index 3e09d4f64..43c837c53 100644 --- a/challengeA/yoshifumi_sawada/csv/plans.csv +++ b/challengeA/yoshifumi_sawada/csv/plans.csv @@ -1,4 +1,5 @@ provider_name,plan_name 東京電力エナジーパートナー,従量電灯B Looopでんき,おうちプラン -東京ガス,ずっとも電気1 \ No newline at end of file +東京ガス,ずっとも電気1 +JXTGでんき,従量電灯B たっぷりプラン \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/basic_charge.rb b/challengeA/yoshifumi_sawada/lib/basic_charge.rb index 27c34a0ae..8f83882f5 100644 --- a/challengeA/yoshifumi_sawada/lib/basic_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/basic_charge.rb @@ -30,4 +30,13 @@ def self.import3(path) } end end + + def self.import4(path) + CSV.read("csv/jxtg/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"], + basic_charge: row["basic_charge"] + } + end + end end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb index a05309f29..c9fe5c6fb 100644 --- a/challengeA/yoshifumi_sawada/lib/simulator.rb +++ b/challengeA/yoshifumi_sawada/lib/simulator.rb @@ -19,6 +19,12 @@ def simulate usage_datas3 = Usage_charge.import3(path: "../csv/tokyogas/usage_charge.csv") # 東京ガスのずっとも電気1の電気量料金 usage_charge3 = calculate(usage_datas3) + + # JXTGでんき 従量電灯B たっぷりプランの電気量料金の電気量料金テーブルのCSVデータをインポート + usage_datas4 = Usage_charge.import4(path: "../csv/jxtg/usage_charge.csv") + # 東京ガスのずっとも電気1の電気量料金 + usage_charge4 = calculate(usage_datas4) + # Looopでんきのおうちプランの電気量料金テーブルのCSVデータをインポート usage_datas2 = Usage_charge.import2(path: "../csv/loop/usage_charge.csv") # Looopでんきのおうちプランの電気量料金の単価 @@ -30,6 +36,7 @@ def simulate basic_charge_table = Basic_charge.import(path: "../csv/tokyo_energy_partner/basic_charge.csv") basic_charge_table2 = Basic_charge.import2(path: "../csv/loop/basic_charge.csv") basic_charge_table3 = Basic_charge.import3(path: "../csv/tokyogas/basic_charge.csv") + basic_charge_table4 = Basic_charge.import4(path: "../csv/jxtg/basic_charge.csv") # プロバイダと料金プラン名のCSVデータをインポート @@ -49,6 +56,10 @@ def simulate when data[:provider_name] == "東京ガス" && [30,40,50,60].include?(@amp) charge_data3 = basic_charge_table3.find { |data| data[:amp] == "#{@amp}" } data[:price]= (charge_data3[:basic_charge].to_i + usage_charge3).floor.to_s + + when data[:provider_name] == "JXTGでんき" && [30,40,50,60].include?(@amp) + charge_data4 = basic_charge_table4.find { |data| data[:amp] == "#{@amp}" } + data[:price]= (charge_data4[:basic_charge].to_i + usage_charge4).floor.to_s end end diff --git a/challengeA/yoshifumi_sawada/lib/usage_charge.rb b/challengeA/yoshifumi_sawada/lib/usage_charge.rb index 67ebb1ce1..42b93bdbf 100644 --- a/challengeA/yoshifumi_sawada/lib/usage_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/usage_charge.rb @@ -34,4 +34,14 @@ def self.import3(path) end end + def self.import4(path) + #全てを読込、配列を作成 + CSV.read("csv/jxtg/usage_charge.csv", headers: true).map do |row| + { + kwh_from: row["kwh_from"], + kwh_to: row["kwh_to"], + unit_price: row["unit_price"] + } + end + end end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb index 4de9edc68..8fdf5fa95 100644 --- a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb +++ b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb @@ -41,87 +41,97 @@ end context "30Aの場合" do - it "30A/120kWhの場合、配列数3つ" do + it "30A/120kWhの場合、配列数4つ" do simulator = Simulator.new(30, 120) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3243"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3698"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3698"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3243"} ) end - it "30A/140kWhの場合、配列数3つ" do + it "30A/140kWhの場合、配列数4つ" do simulator = Simulator.new(30, 140) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3773"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4171"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4171"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3773"} ) end - it "30A/300kWhの場合、配列数3つ" do + it "30A/300kWhの場合、配列数4つ" do simulator = Simulator.new(30, 300) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8010"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"7992"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"7992"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8010"} ) end - it "30A/350kWhの場合、配列数3つ" do + it "30A/350kWhの場合、配列数4つ" do simulator = Simulator.new(30, 350) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9538"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9186"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9186"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9264"} ) end - it "30A/400kWhの場合、配列数3つ" do + it "30A/400kWhの場合、配列数4つ" do simulator = Simulator.new(30, 400) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"11067"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10507"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10507"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"10518"} ) end end context "40Aの場合" do - it "40A/120kWhの場合、配列数3つ" do + it "40A/120kWhの場合、配列数4つ" do simulator = Simulator.new(40, 120) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3529"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3984"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3984"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3529"} ) end - it "40A/140kWhの場合、配列数3つ" do + it "40A/140kWhの場合、配列数4つ" do simulator = Simulator.new(40, 140) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"4059"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4457"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4457"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"4059"} ) end - it "40A/300kWhの場合、配列数3つ" do + it "40A/300kWhの場合、配列数4つ" do simulator = Simulator.new(40, 300) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8296"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8278"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8278"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8296"} ) end - it "40A/350kWhの場合、配列数3つ" do + it "40A/350kWhの場合、配列数4つ" do simulator = Simulator.new(40, 350) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9824"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9472"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9472"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9550"} ) end - it "40A/400kWhの場合、配列数3つ" do + it "40A/400kWhの場合、配列数4つ" do simulator = Simulator.new(40, 400) expect(simulator.simulate).to contain_exactly( {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"11353"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10793"} + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10793"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"10804"} ) end end From 65b34f6d650fe90afc205e2e05176c349096f284 Mon Sep 17 00:00:00 2001 From: zenfumi Date: Mon, 29 Mar 2021 16:17:57 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=E5=8D=98=E4=BD=8D=E9=96=A2=E9=80=A3(?= =?UTF-8?q?=E4=B8=8A=E9=99=90=E5=80=A4,=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E5=9E=8B)=E8=AA=BF=E6=95=B4,=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csv/jxtg/usage_charge.csv | 2 +- .../csv/tokyo_energy_partner/usage_charge.csv | 2 +- .../csv/tokyogas/usage_charge.csv | 2 +- .../yoshifumi_sawada/lib/basic_charge.rb | 29 ++-- challengeA/yoshifumi_sawada/lib/simulator.rb | 40 ++--- .../yoshifumi_sawada/lib/usage_charge.rb | 81 ++++++---- .../yoshifumi_sawada/spec/simulator_spec.rb | 151 ++++++++++++------ 7 files changed, 183 insertions(+), 124 deletions(-) diff --git a/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv index 8194cc7c9..77bea28a8 100644 --- a/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv +++ b/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv @@ -2,4 +2,4 @@ kwh_from,kwh_to,unit_price 0,120,19.88 120,300,26.48 300,600,25.08 -600,10000,26.15 \ No newline at end of file +600,Float::INFINITY,26.15 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv index c5b4ea3c8..0a2ef5685 100644 --- a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv +++ b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv @@ -1,4 +1,4 @@ kwh_from,kwh_to,unit_price 0,120,19.88 120,300,26.48 -300,10000,30.57 \ No newline at end of file +300,Float::INFINITY,30.57 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv index 89ac5f02d..d7d2ea290 100644 --- a/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv +++ b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv @@ -1,4 +1,4 @@ kwh_from,kwh_to,unit_price 0,140,23.67 140,350,23.88 -350,10000,26.41 \ No newline at end of file +350,Float::INFINITY,26.41 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/basic_charge.rb b/challengeA/yoshifumi_sawada/lib/basic_charge.rb index 8f83882f5..6b4a21843 100644 --- a/challengeA/yoshifumi_sawada/lib/basic_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/basic_charge.rb @@ -3,40 +3,37 @@ class Basic_charge def self.import(path) - #全てを読込、配列を作成 + if path[:path].include?("tokyo_energy_partner") CSV.read("csv/tokyo_energy_partner/basic_charge.csv", headers: true).map do |row| { - amp: row["amp"], - basic_charge: row["basic_charge"] + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i } end - end - # 以下、共通化すること - def self.import2(path) + elsif path[:path].include?("loop") CSV.read("csv/loop/basic_charge.csv", headers: true).map do |row| { - amp: row["amp"], - basic_charge: row["basic_charge"] + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i } end - end - def self.import3(path) + elsif path[:path].include?("tokyogas") CSV.read("csv/tokyogas/basic_charge.csv", headers: true).map do |row| { - amp: row["amp"], - basic_charge: row["basic_charge"] + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i } end - end - def self.import4(path) + elsif path[:path].include?("jxtg") CSV.read("csv/jxtg/basic_charge.csv", headers: true).map do |row| { - amp: row["amp"], - basic_charge: row["basic_charge"] + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i } end end +end end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb index c9fe5c6fb..a3bbcd65d 100644 --- a/challengeA/yoshifumi_sawada/lib/simulator.rb +++ b/challengeA/yoshifumi_sawada/lib/simulator.rb @@ -16,27 +16,27 @@ def simulate # 東京電力エナジーパートナーの従量電灯Bの電気量料金 usage_charge1 = calculate(usage_datas) # 東京ガスのずっとも電気1の電気量料金の電気量料金テーブルのCSVデータをインポート - usage_datas3 = Usage_charge.import3(path: "../csv/tokyogas/usage_charge.csv") + usage_datas3 = Usage_charge.import(path: "../csv/tokyogas/usage_charge.csv") # 東京ガスのずっとも電気1の電気量料金 usage_charge3 = calculate(usage_datas3) # JXTGでんき 従量電灯B たっぷりプランの電気量料金の電気量料金テーブルのCSVデータをインポート - usage_datas4 = Usage_charge.import4(path: "../csv/jxtg/usage_charge.csv") + usage_datas4 = Usage_charge.import(path: "../csv/jxtg/usage_charge.csv") # 東京ガスのずっとも電気1の電気量料金 usage_charge4 = calculate(usage_datas4) # Looopでんきのおうちプランの電気量料金テーブルのCSVデータをインポート - usage_datas2 = Usage_charge.import2(path: "../csv/loop/usage_charge.csv") + usage_datas2 = Usage_charge.import(path: "../csv/loop/usage_charge.csv") # Looopでんきのおうちプランの電気量料金の単価 - usage_charge_data2 = usage_datas2.find { |data| data[:kwh] == "0" } - unit_price2 = usage_charge_data2[:unit_price].to_f + usage_charge_data2 = usage_datas2.find { |data| data['kwh'] == 0.0 } + unit_price2 = usage_charge_data2["unit_price"] # 基本料金テーブルのCSVデータをインポート basic_charge_table = Basic_charge.import(path: "../csv/tokyo_energy_partner/basic_charge.csv") - basic_charge_table2 = Basic_charge.import2(path: "../csv/loop/basic_charge.csv") - basic_charge_table3 = Basic_charge.import3(path: "../csv/tokyogas/basic_charge.csv") - basic_charge_table4 = Basic_charge.import4(path: "../csv/jxtg/basic_charge.csv") + basic_charge_table2 = Basic_charge.import(path: "../csv/loop/basic_charge.csv") + basic_charge_table3 = Basic_charge.import(path: "../csv/tokyogas/basic_charge.csv") + basic_charge_table4 = Basic_charge.import(path: "../csv/jxtg/basic_charge.csv") # プロバイダと料金プラン名のCSVデータをインポート @@ -46,20 +46,20 @@ def simulate plan_list = plan_datas.each do |data| case when data[:provider_name] == "東京電力エナジーパートナー" - charge_data = basic_charge_table.find { |data| data[:amp] == "#{@amp}" } - data[:price]= (charge_data[:basic_charge].to_i + usage_charge1).floor.to_s + charge_data = basic_charge_table.find { |data| data[:amp] == @amp } + data[:price]= (charge_data[:basic_charge] + usage_charge1).floor.to_s when data[:provider_name] == "Looopでんき" - charge_data2 = basic_charge_table2.find { |data| data[:amp] == "#{@amp}" } - data[:price]= (charge_data2[:basic_charge].to_i + @usage_per_month * unit_price2).floor.to_s + charge_data2 = basic_charge_table2.find { |data| data[:amp] == @amp } + data[:price]= (charge_data2[:basic_charge] + @usage_per_month * unit_price2).floor.to_s when data[:provider_name] == "東京ガス" && [30,40,50,60].include?(@amp) - charge_data3 = basic_charge_table3.find { |data| data[:amp] == "#{@amp}" } - data[:price]= (charge_data3[:basic_charge].to_i + usage_charge3).floor.to_s + charge_data3 = basic_charge_table3.find { |data| data[:amp] == @amp } + data[:price]= (charge_data3[:basic_charge] + usage_charge3).floor.to_s when data[:provider_name] == "JXTGでんき" && [30,40,50,60].include?(@amp) - charge_data4 = basic_charge_table4.find { |data| data[:amp] == "#{@amp}" } - data[:price]= (charge_data4[:basic_charge].to_i + usage_charge4).floor.to_s + charge_data4 = basic_charge_table4.find { |data| data[:amp] == @amp } + data[:price]= (charge_data4[:basic_charge] + usage_charge4).floor.to_s end end @@ -73,10 +73,10 @@ def simulate def calculate(usage_datas) usage_charge = 0 usage_datas.each do |usage_data| - if usage_data[:kwh_from].to_i < @usage_per_month && @usage_per_month <= usage_data[:kwh_to].to_i - usage_charge = usage_charge + usage_data[:unit_price].to_f * (@usage_per_month - usage_data[:kwh_from].to_i) - elsif usage_data[:kwh_to].to_i < @usage_per_month - usage_charge = usage_charge + usage_data[:unit_price].to_f * (usage_data[:kwh_to].to_i - usage_data[:kwh_from].to_i) + if usage_data['kwh_from'] < @usage_per_month && @usage_per_month <= usage_data['kwh_to'] + usage_charge = usage_charge + usage_data['unit_price'] * (@usage_per_month - usage_data['kwh_from']) + elsif usage_data['kwh_to'] < @usage_per_month + usage_charge = usage_charge + usage_data['unit_price'] * (usage_data['kwh_to'] - usage_data['kwh_from']) end end return usage_charge diff --git a/challengeA/yoshifumi_sawada/lib/usage_charge.rb b/challengeA/yoshifumi_sawada/lib/usage_charge.rb index 42b93bdbf..3648bc68a 100644 --- a/challengeA/yoshifumi_sawada/lib/usage_charge.rb +++ b/challengeA/yoshifumi_sawada/lib/usage_charge.rb @@ -1,47 +1,62 @@ require "csv" require "pry" - class Usage_charge def self.import(path) - #全てを読込、配列を作成 - CSV.read("csv/tokyo_energy_partner/usage_charge.csv", headers: true).map do |row| - { - kwh_from: row["kwh_from"], - kwh_to: row["kwh_to"], - unit_price: row["unit_price"] - } + if path[:path].include?("tokyo_energy_partner") + list = [] + CSV.foreach("csv/tokyo_energy_partner/usage_charge.csv", headers: true) do |row| + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } end - end + return list - def self.import2(path) - #全てを読込、配列を作成 - CSV.read("csv/loop/usage_charge.csv", headers: true).map do |row| - { - kwh: row["kwh"], - unit_price: row["unit_price"] - } + elsif path[:path].include?("loop") + list = [] + CSV.foreach("csv/loop/usage_charge.csv", headers: true) do |row| + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } end - end + return list - def self.import3(path) - #全てを読込、配列を作成 - CSV.read("csv/tokyogas/usage_charge.csv", headers: true).map do |row| - { - kwh_from: row["kwh_from"], - kwh_to: row["kwh_to"], - unit_price: row["unit_price"] - } + elsif path[:path].include?("tokyogas") + list = [] + CSV.foreach("csv/tokyogas/usage_charge.csv", headers: true) do |row| + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } end - end + return list - def self.import4(path) - #全てを読込、配列を作成 + elsif path[:path].include?("jxtg") + list = [] CSV.read("csv/jxtg/usage_charge.csv", headers: true).map do |row| - { - kwh_from: row["kwh_from"], - kwh_to: row["kwh_to"], - unit_price: row["unit_price"] - } + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } end + return list + end end end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb index 8fdf5fa95..7890fecfb 100644 --- a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb +++ b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb @@ -2,54 +2,38 @@ RSpec.describe Simulator do describe "プラン名と料金を含む配列数と段階別の計算結果" do - context "10Aの場合" do - it "10A/120kWhの場合、配列数2つ" do - simulator = Simulator.new(10, 120) + context "20Aの場合" do + it "20A/120kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 120) expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"2671"}, + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"2957"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"} ) end - it "10A/140kWhの場合、配列数2つ" do - simulator = Simulator.new(10, 140) + it "20A/121kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 121) expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3201"}, - {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"} + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"2984"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3194"} ) end - it "10A/300kWhの場合、配列数2つ" do - simulator = Simulator.new(10, 300) + it "20A/300kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 300) expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"7438"}, + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"7724"}, {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"} ) end - it "10A/350kWhの場合、配列数2つ" do - simulator = Simulator.new(10, 350) + it "20A/301kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 301) expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8966"}, - {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"} - ) - end - it "10A/400kWhの場合、配列数2つ" do - simulator = Simulator.new(10, 400) - expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"10495"}, - {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"} + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"7754"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7946"} ) end end context "30Aの場合" do - it "30A/120kWhの場合、配列数4つ" do - simulator = Simulator.new(30, 120) - expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3243"}, - {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3698"}, - {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3243"} - ) - end it "30A/140kWhの場合、配列数4つ" do simulator = Simulator.new(30, 140) expect(simulator.simulate).to contain_exactly( @@ -59,6 +43,15 @@ {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3773"} ) end + it "30A/141kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 141) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3799"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3722"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4195"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3799"} + ) + end it "30A/300kWhの場合、配列数4つ" do simulator = Simulator.new(30, 300) expect(simulator.simulate).to contain_exactly( @@ -68,6 +61,15 @@ {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8010"} ) end + it "30A/301kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 301) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8040"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7946"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8016"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8035"} + ) + end it "30A/350kWhの場合、配列数4つ" do simulator = Simulator.new(30, 350) expect(simulator.simulate).to contain_exactly( @@ -77,27 +79,36 @@ {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9264"} ) end - it "30A/400kWhの場合、配列数4つ" do - simulator = Simulator.new(30, 400) + it "30A/351kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 351) expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"11067"}, - {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10507"}, - {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"10518"} + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9569"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9266"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9213"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9289"} ) end - end - - context "40Aの場合" do - it "40A/120kWhの場合、配列数4つ" do - simulator = Simulator.new(40, 120) + it "30A/600kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 600) expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3529"}, - {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"3984"}, - {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3529"} + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17181"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15840"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"15789"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15534"} ) end + it "30A/601kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 601) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17211"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15866"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"15815"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15560"} + ) + end + end + + context "40Aの場合" do it "40A/140kWhの場合、配列数4つ" do simulator = Simulator.new(40, 140) expect(simulator.simulate).to contain_exactly( @@ -107,6 +118,15 @@ {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"4059"} ) end + it "40A/141kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 141) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"4085"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3722"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4481"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"4085"} + ) + end it "40A/300kWhの場合、配列数4つ" do simulator = Simulator.new(40, 300) expect(simulator.simulate).to contain_exactly( @@ -116,6 +136,15 @@ {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8296"} ) end + it "40A/301kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 301) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8326"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7946"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8302"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8321"} + ) + end it "40A/350kWhの場合、配列数4つ" do simulator = Simulator.new(40, 350) expect(simulator.simulate).to contain_exactly( @@ -125,13 +154,31 @@ {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9550"} ) end - it "40A/400kWhの場合、配列数4つ" do - simulator = Simulator.new(40, 400) + it "40A/351kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 351) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9855"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9266"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9499"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9575"} + ) + end + it "40A/600kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 600) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17467"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15840"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"16075"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15820"} + ) + end + it "40A/601kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 601) expect(simulator.simulate).to contain_exactly( - {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"11353"}, - {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"10560"}, - {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"10793"}, - {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"10804"} + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17497"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15866"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"16101"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15846"} ) end end