From 8982ef7fa5484324359fdd5cf89f1a1ccd90df9a Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Wed, 5 Jul 2017 23:25:30 +0000 Subject: [PATCH 1/9] I think I solved the first part --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 0df2d0f..d087423 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -11,7 +11,7 @@ def word_count # ================================================================================ - @word_count = "Replace this string with your answer." + @word_count = @text.split.count @character_count_with_spaces = "Replace this string with your answer." From 5372a0538e139e6b4e55797e167424a0fea25496 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Wed, 5 Jul 2017 23:41:42 +0000 Subject: [PATCH 2/9] Solved count with spaces --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index d087423..c6cdaa4 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -13,7 +13,7 @@ def word_count @word_count = @text.split.count - @character_count_with_spaces = "Replace this string with your answer." + @character_count_with_spaces = @text.length @character_count_without_spaces = "Replace this string with your answer." From eead4e8cde0e87b976c9ecfd590e8b5432b5d745 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Thu, 6 Jul 2017 00:06:45 +0000 Subject: [PATCH 3/9] Solved count without spaces --- app/controllers/calculations_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index c6cdaa4..499c8fb 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -15,9 +15,9 @@ def word_count @character_count_with_spaces = @text.length - @character_count_without_spaces = "Replace this string with your answer." + @character_count_without_spaces = @text.gsub(/\s+/, "").length - @occurrences = "Replace this string with your answer." + @occurrences = @text.count(@special_word) # ================================================================================ # Your code goes above. From 319ab48051e2cf16fb9ed58c77794406eed44541 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Thu, 6 Jul 2017 00:22:01 +0000 Subject: [PATCH 4/9] Solved occurrences --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 499c8fb..b865e1b 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -17,7 +17,7 @@ def word_count @character_count_without_spaces = @text.gsub(/\s+/, "").length - @occurrences = @text.count(@special_word) + @occurrences = @special_word.split.count # ================================================================================ # Your code goes above. From 1df4697799724545b8e1bee8daad933ea5c78d46 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Thu, 6 Jul 2017 00:26:29 +0000 Subject: [PATCH 5/9] Solved occurrences v2 --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index b865e1b..8bc8c45 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -17,7 +17,7 @@ def word_count @character_count_without_spaces = @text.gsub(/\s+/, "").length - @occurrences = @special_word.split.count + @occurrences = @text.split.count(@special_word) # ================================================================================ # Your code goes above. From ff086cfff269f0a5bd6ff49ae28cc62df0d3ca71 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Sat, 8 Jul 2017 17:06:11 +0000 Subject: [PATCH 6/9] Solved Loan Payment --- Gemfile | 4 +++- Gemfile.lock | 8 ++++++++ app/assets/javascripts/application.js | 7 +++++++ app/controllers/calculations_controller.rb | 8 +++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index b625ba3..97bf45a 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,9 @@ git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end - +gem 'momentjs-rails' +gem 'bootstrap3-datetimepicker-rails' +gem 'chronic' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.2' # Use sqlite3 as the database for Active Record diff --git a/Gemfile.lock b/Gemfile.lock index a4b753b..d911ad9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,8 @@ GEM bootstrap (4.0.0.alpha6) autoprefixer-rails (>= 6.0.3) sass (>= 3.4.19) + bootstrap3-datetimepicker-rails (4.17.47) + momentjs-rails (>= 2.8.1) builder (3.2.3) byebug (9.0.6) callsite (0.0.11) @@ -85,6 +87,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + chronic (0.10.2) coderay (1.1.1) concurrent-ruby (1.0.5) crack (0.4.3) @@ -140,6 +143,8 @@ GEM mime-types-data (3.2016.0521) mini_portile2 (2.2.0) minitest (5.10.2) + momentjs-rails (2.17.1) + railties (>= 3.1) multi_json (1.12.1) nio4r (2.1.0) nokogiri (1.8.0) @@ -262,8 +267,10 @@ DEPENDENCIES better_errors binding_of_caller bootstrap (~> 4.0.0.alpha6) + bootstrap3-datetimepicker-rails byebug capybara + chronic dotenv-rails factory_girl_rails firstdraft_generators @@ -274,6 +281,7 @@ DEPENDENCIES letter_opener listen (>= 3.0.5, < 3.2) meta_request + momentjs-rails pry-rails puma (~> 3.7) rails (~> 5.1.2) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 739c2fe..da0725c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,3 +14,10 @@ //= require bootstrap //= require turbolinks //= require_tree . +//= require jquery +//= require moment +//= require bootstrap-datetimepicker + +$(function () { + $('.datetimepicker').datetimepicker(); +}); \ No newline at end of file diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 8bc8c45..58c155e 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -38,7 +38,13 @@ def loan_payment # The principal value the user input is in the decimal @principal. # ================================================================================ - @monthly_payment = "Replace this string with your answer." + term_months = @years * 12 + new_apr = @apr * 1/100 + principal_month = @principal / term_months + interest_term = @principal * new_apr + interest_month = interest_term / term_months + + @monthly_payment = principal_month + interest_month # ================================================================================ # Your code goes above. From 6e3ad37e5f61425c773f9abe09289cf7705a8355 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Sat, 8 Jul 2017 17:48:21 +0000 Subject: [PATCH 7/9] Solved Date Duration --- app/controllers/calculations_controller.rb | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 58c155e..75d0736 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -66,12 +66,35 @@ def time_between # number of seconds as a result. # ================================================================================ - @seconds = "Replace this string with your answer." - @minutes = "Replace this string with your answer." - @hours = "Replace this string with your answer." - @days = "Replace this string with your answer." - @weeks = "Replace this string with your answer." - @years = "Replace this string with your answer." + @seconds = @ending - @starting + + startt = @starting.to_i + endt = @ending.to_i + + start_min=startt * 1/60 + end_min=endt * 1/60 + + @minutes = end_min - start_min + + start_hr=startt * 1/3600 + end_hr=endt * 1/3600 + + @hours = end_hr - start_hr + + start_day=start_hr * 1/24 + end_day=end_hr * 1/24 + + @days = end_day - start_day + + start_week=start_day * 1/7 + end_week=end_day * 1/7 + + @weeks = end_week - start_week + + start_year=start_week * 1/52 + end_year=end_week * 1/52 + + @years = end_year - start_year # ================================================================================ # Your code goes above. From fc8847287de42625e9aa6f57ff75b3cd41a4eb00 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Sat, 8 Jul 2017 18:11:31 +0000 Subject: [PATCH 8/9] Almost done with DS --- app/controllers/calculations_controller.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 75d0736..12a9e1c 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -111,22 +111,28 @@ def descriptive_statistics # The numbers the user input are in the array @numbers. # ================================================================================ - @sorted_numbers = "Replace this string with your answer." + @sorted_numbers = @numbers.sort - @count = "Replace this string with your answer." + @count = @numbers.count - @minimum = "Replace this string with your answer." + @minimum = @numbers.min - @maximum = "Replace this string with your answer." + @maximum = @numbers.max - @range = "Replace this string with your answer." + @range = @maximum - @minimum - @median = "Replace this string with your answer." + sorted = @numbers.sort + len = sorted.length + + @median = (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0 - @sum = "Replace this string with your answer." + @sum = @numbers.sum - @mean = "Replace this string with your answer." + sum_calc = @sum.to_f + count_calc = @count.to_f + @mean = sum_calc / count_calc + @variance = "Replace this string with your answer." @standard_deviation = "Replace this string with your answer." From 38ed5fe58de01435b75f4ec8c4b8aa415575a473 Mon Sep 17 00:00:00 2001 From: Kent Richard Date: Sat, 8 Jul 2017 19:53:36 +0000 Subject: [PATCH 9/9] Finished First Draft --- app/controllers/calculations_controller.rb | 39 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 12a9e1c..8569249 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -68,8 +68,8 @@ def time_between @seconds = @ending - @starting - startt = @starting.to_i - endt = @ending.to_i + startt = @starting.to_f + endt = @ending.to_f start_min=startt * 1/60 end_min=endt * 1/60 @@ -133,11 +133,38 @@ def descriptive_statistics @mean = sum_calc / count_calc - @variance = "Replace this string with your answer." + sample = @numbers + xbar = @mean + variance_differential = [] + + sample.each do |num1| + number_less_xbar = num1 - xbar + variance_differential.push(number_less_xbar) + end + + squared_results = [] + + variance_differential.each do |num2| + square = num2 * num2 + squared_results.push(square) + end + + results_sum = squared_results.sum + + sample_size = @count - 1 + + @variance = results_sum / sample_size - @standard_deviation = "Replace this string with your answer." + @standard_deviation = Math.sqrt(@variance) - @mode = "Replace this string with your answer." + hash = Hash.new(0) + @numbers.each do |i| + hash[i]+=1 + end + + mode_max = hash.max + + @mode = mode_max # ================================================================================ # Your code goes above. @@ -146,3 +173,5 @@ def descriptive_statistics render("descriptive_statistics.html.erb") end end + + \ No newline at end of file