diff --git a/Gemfile.lock b/Gemfile.lock index 9fb5fb6..869c6ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -208,7 +208,11 @@ GEM rspec-support (3.6.0) ruby_dep (1.5.0) safe_yaml (1.0.4) - sass (3.4.25) + sass (3.5.1) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) sass-rails (5.0.6) railties (>= 4.0.0, < 6) sass (~> 3.1) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb new file mode 100644 index 0000000..6fe8641 --- /dev/null +++ b/app/controllers/calculations_controller.rb @@ -0,0 +1,292 @@ +class CalculationsController < ApplicationController + def flex_square + # The incoming parameters for this action look like {"a_number"=>"5"} + # Rails stores that hash in a variable called params + + @user_number_flex = params["a_number_flex"].to_i + @squared_number_flex = @user_number_flex**2 + + render("calculations/flexible_square_template.html.erb") + end + + + def flex_square_root + + @user_square_root_flex = params["a_number_flex"].to_i + @square_root_flex = Math.sqrt(@user_square_root_flex) + + render("calculations/flexible_square_root_template.html.erb") + end + + + def flex_payment + + @monthly_interest_basispoints_flex = params["basis_points"].to_f + @number_of_years_flex = params["number_of_years"].to_i + @present_value_flex = params["present_value"].to_i + + @monthly_interest_percentage_flex = @monthly_interest_basispoints_flex/10000 + @monthly_interest_per_period_flex = @monthly_interest_percentage_flex/12 + + @number_of_monthly_payments_flex = @number_of_years_flex*-12 + + @one_plus_rate_per_period = (1 + @monthly_interest_per_period_flex)**@number_of_monthly_payments_flex + + @denomonator_step_one = (1 - @one_plus_rate_per_period) + + @numerator = (@monthly_interest_per_period_flex*@present_value_flex) + @denomonator = (@denomonator_step_one) + + @monthly_payment_flex = @numerator/(1-(1+@monthly_interest_per_period_flex)**(@number_of_monthly_payments_flex)) + + + + render("calculations/flexible_payment_template.html.erb") + end + + + def flex_random_number + + @random_number_flex = params["random_number_flex"].to_i + @random_number_output_flex = rand(50...100) + + # random number between 50 & 100 + + render("calculations/flexible_random_number_template.html.erb") + end + + + + + + + + def square_form + + @user_number = params["the_user_number"].to_i + @squared_number = @user_number**2 + + render("calculations/square_form_template.html.erb") + end + + + def square_root_form + + @user_number_square_root = params["number_input_square_root"].to_i + @squared_root = Math.sqrt(@user_number_square_root) + + render("calculations/square_root_form_template.html.erb") + end + + + def payment_form + + @monthly_interest = params["the_user_interest"].to_f + @number_of_years = params["the_user_payment_years"].to_i + @present_value = params["the_user_principal"].to_i + + @monthly_interest_percentage = @monthly_interest/100 + @monthly_interest_per_period = @monthly_interest_percentage/12 + + @number_of_monthly_payments = @number_of_years*-12 + + @one_plus_rate_per_period = (1 + @monthly_interest_per_period)**@number_of_monthly_payments + + @denomonator_step_one = (1 - @one_plus_rate_per_period) + + @numerator = (@monthly_interest_per_period*@present_value) + @denomonator = (@denomonator_step_one) + + @monthly_payment = (@numerator/@denomonator) + + # @monthly_payment = (@monthly_interest_per_period*@present_value)/(1-(1+@monthly_interest_per_period)**(@number_of_monthly_payments)) + + render("calculations/payment_form_template.html.erb") + end + + + def random_number_form + + @minimum = params["minimum"].to_f + @maximum = params["maximum"].to_f + @random_number_output = rand(@minimum...@maximum) + + render("calculations/random_number_form_template.html.erb") + end + + + def word_count_form + + @text = params["user_text"].to_s + @special_word = params["special_word"].to_s + + @word_count = (@text.split(" ").length) + + @character_count_with_spaces = @text.length + + @character_count_without_spaces = @text.length-@text.count(" ") + + # punctuation = @text.sub(".", "").to_s + + # downcased_words = punctuation.downcase.split(" ").to_s + + # downcased_special = (@special_word.downcase).to_s + + @occurrences = (@text.sub(".", "").downcase.split(" ").count(@special_word.downcase)).to_s + + # downcased_words.count(downcased_special).to_i + + + render("calculations/word_count_form_template.html.erb") + end + + + def stats_form + + @numbers_raw = params["stats_numbers"].to_s + @numbers = @numbers_raw.gsub(',' , '').split.map(&:to_f) + + @sorted = @numbers.sort + + @count = @numbers.count + + @minimum = @numbers.minimum + + @maximum = @numbers.max + + @range = @maximum-@minimum + + @median = @sorted[(@count/2)] + + @sum = @numbers.sum + + @mean = @sum/@count + + @demeaned=@numbers.map { |i| i - @mean} + @squared = @demeaned.map { |i| i**2} + @variance = @squared.sum / @count + + @variance = @squared.sum / @count + + @standard_deviation = Math.sqrt(@variance) + + @mode_count = @numbers.map { |i| @numbers.count(i)} + @mode = @numbers[@mode_count.index(@mode_count.sort[@mode_count.count - 1])] + + render("calculations/stats_form_template.html.erb") + end + + + + + def process_square_form + + # The incoming parameters for this action look like {"the_user_number"} => "5" + # Rails stores that hash in a variable called params + + @user_number = params["the_user_number"].to_param + @squared_number = @user_number**2 + + render("calculations/process_square_form_template.html.erb") + end + + def process_square_root_form + + @user_number_root = params["the_user_number_square_root"].to_f + @squared_root = Math.sqrt(@user_number_root) + + render("calculations/process_square_root_form_template.html.erb") + end + + + def process_payment_form + + @monthly_interest = params["the_user_interest"].to_f + @number_of_years = params["the_user_payment_years"].to_i + @present_value = params["the_user_principal"].to_i + + @monthly_interest_percentage = @monthly_interest/100 + @monthly_interest_per_period = @monthly_interest_percentage/12 + + @number_of_monthly_payments = @number_of_years*-12 + + @one_plus_rate_per_period = (1 + @monthly_interest_per_period)**@number_of_monthly_payments + + @denomonator_step_one = (1 - @one_plus_rate_per_period) + + @numerator = (@monthly_interest_per_period*@present_value) + @denomonator = (@denomonator_step_one) + + @monthly_payment = (@numerator/@denomonator) + + # @monthly_payment = (@monthly_interest_per_period*@present_value)/(1-(1+@monthly_interest_per_period)**(@number_of_monthly_payments)) + + render("calculations/process_payment_form_template.html.erb") + end + + + def process_random_number_form + + @minimum = params["minimum"].to_f + @maximum = params["maximum"].to_f + @random_number_output = rand(@minimum...@maximum) + + render("calculations/process_random_number_form_template.html.erb") + end + + + def process_word_count_form + + @text = params["user_text"].to_s + @special_word = params["special_word"].to_s + + @word_count = (@text.split(" ").length) + + @character_count_with_spaces = @text.length + + @character_count_without_spaces = @text.length-@text.count(" ") + + @occurrences = (@text.sub(".", "").downcase.split(" ").count(@special_word.downcase)).to_s + + render("calculations/process_word_count_form_template.html.erb") + end + + + def process_stats_form + + @numbers_raw = params["stats_numbers"].to_s + @numbers = @numbers_raw.gsub(',' , '').split.map(&:to_f) + + @sorted = @numbers.sort + + @count = @numbers.count + + @minimum = @numbers.min + + @maximum = @numbers.max + + @range = @maximum-@minimum + + @median = @sorted[(@count/2)] + + @sum = @numbers.sum + + @mean = @sum/@count + + @demeaned=@numbers.map { |i| i - @mean} + @squared = @demeaned.map { |i| i**2} + @variance = @squared.sum / @count + + @variance = @squared.sum / @count + + @standard_deviation = Math.sqrt(@variance) + + @mode_count = @numbers.map { |i| @numbers.count(i)} + @mode = @numbers[@mode_count.index(@mode_count.sort[@mode_count.count - 1])] + + render("calculations/process_stats_form_template.html.erb") + end + + +end + diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb new file mode 100644 index 0000000..05b66a7 --- /dev/null +++ b/app/controllers/homepage_controller.rb @@ -0,0 +1,85 @@ +class CalculationsController < ApplicationController + def homepage + + + + div class="container"> +
+
+ Part I Targets +
+ +
+ Flexible Square Example +
+ +
+ Flexible Square Root Example +
+ +
+ Flexible Payment Example +
+ +
+ Flexible Random Example +
+ +
+
+
+ Part II Targets +
+ +
+ Square Form +
+ +
+ Square Root Form +
+ +
+ Payment Form +
+ +
+ Random Number Form +
+ + +
+
+
+ Part III Targets +
+ +
+ Word Count Form +
+ +
+ Stats Form +
+ + +
+
+
+ + +
+
+ +
+ + + + + + + render("calculations/homepage_template.html.erb") + end + + +end \ No newline at end of file diff --git a/app/views/calculations/flexible_payment_template.html.erb b/app/views/calculations/flexible_payment_template.html.erb new file mode 100644 index 0000000..8a8f8a1 --- /dev/null +++ b/app/views/calculations/flexible_payment_template.html.erb @@ -0,0 +1,3 @@ +

Flexible Payment

+ +

A <%= @number_of_years_flex %> year loan of <%= number_to_currency(@present_value_flex) %>, with an interest rate of is <%= number_to_percentage(@monthly_interest_basispoints_flex/100) %>, requires a monthly payment of <%= number_to_currency(@monthly_payment_flex) %>

\ No newline at end of file diff --git a/app/views/calculations/flexible_random_number_template.html.erb b/app/views/calculations/flexible_random_number_template.html.erb new file mode 100644 index 0000000..e4fbfbd --- /dev/null +++ b/app/views/calculations/flexible_random_number_template.html.erb @@ -0,0 +1,3 @@ +

Flexible Random Number

+ +

A random number between 50 and 100 is <%= @random_number_output_flex %>.

\ No newline at end of file diff --git a/app/views/calculations/flexible_square_root_template.html.erb b/app/views/calculations/flexible_square_root_template.html.erb new file mode 100644 index 0000000..356851c --- /dev/null +++ b/app/views/calculations/flexible_square_root_template.html.erb @@ -0,0 +1,3 @@ +

Flexible Square Root

+ +

The square root of <%= @user_square_root_flex %> is <%= @square_root_flex %>.

\ No newline at end of file diff --git a/app/views/calculations/flexible_square_template.html.erb b/app/views/calculations/flexible_square_template.html.erb new file mode 100644 index 0000000..9945e97 --- /dev/null +++ b/app/views/calculations/flexible_square_template.html.erb @@ -0,0 +1,7 @@ +

Flexible Square

+ +

The square of <%= @user_number_flex %> is <%= @squared_number_flex %>.

+ + + + \ No newline at end of file diff --git a/app/views/calculations/homepage_template.html.erb b/app/views/calculations/homepage_template.html.erb new file mode 100644 index 0000000..8496925 --- /dev/null +++ b/app/views/calculations/homepage_template.html.erb @@ -0,0 +1,103 @@ + + + + Target Omnicalc Params + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Part I Targets + + Flexible Square Example + + Flexible Square Root Example + + Flexible Payment Example + + Flexible Random Example +
+ Part II Targets + + Square Form + + Square Root Form + + Payment Form + + Random Number Form +
+ Part III Targets + + Word Count Form + + Stats Form +
+ +

+ Square Calculation +

+ +
+
+ + + +
+ + +
+ + +
+
+
+ + \ No newline at end of file diff --git a/app/views/calculations/payment_form_template.html.erb b/app/views/calculations/payment_form_template.html.erb new file mode 100644 index 0000000..439171d --- /dev/null +++ b/app/views/calculations/payment_form_template.html.erb @@ -0,0 +1,34 @@ +

Payment Calculation

+ +
+ +
+ + +
+
+ +
+ + +
+
+ +
+ + +
+
+ + + + + +
+ diff --git a/app/views/calculations/process_payment_form_template.html.erb b/app/views/calculations/process_payment_form_template.html.erb new file mode 100644 index 0000000..8225b6a --- /dev/null +++ b/app/views/calculations/process_payment_form_template.html.erb @@ -0,0 +1,18 @@ +

Payment Results

+ +
+
APR
+
<%= number_to_percentage(@monthly_interest) %>
+ +
Number of years
+
<%= @number_of_years %>
+ +
Principal
+
<%= number_to_currency(@present_value) %>
+ +
Payment
+
<%= number_to_currency(@monthly_payment) %>
+ +
+ + Calculate another payment \ No newline at end of file diff --git a/app/views/calculations/process_random_number_form_template.html.erb b/app/views/calculations/process_random_number_form_template.html.erb new file mode 100644 index 0000000..75d9abd --- /dev/null +++ b/app/views/calculations/process_random_number_form_template.html.erb @@ -0,0 +1,15 @@ +

Random Results

+ +
+
Minimum
+
<%= @minimum %>
+ +
Maximum
+
<%= @maximum %>
+ +
Random Number
+
<%= @random_number_output %>
+ +
+ + Pick another random number \ No newline at end of file diff --git a/app/views/calculations/process_square_form_template.html.erb b/app/views/calculations/process_square_form_template.html.erb new file mode 100644 index 0000000..115d33c --- /dev/null +++ b/app/views/calculations/process_square_form_template.html.erb @@ -0,0 +1,12 @@ +

Square Results

+ +
+
Number
+
<%= @user_number %>
+ +
Square
+
<%= @squared_number %>
+ +
+ + Calculate another square \ No newline at end of file diff --git a/app/views/calculations/process_square_root_form_template.html.erb b/app/views/calculations/process_square_root_form_template.html.erb new file mode 100644 index 0000000..1c762e7 --- /dev/null +++ b/app/views/calculations/process_square_root_form_template.html.erb @@ -0,0 +1,12 @@ +

Square Root Results

+ +
+
Number
+
<%= @user_number_root %>
+ +
Square Root
+
<%= @squared_root %>
+ +
+ + Calculate another square root \ No newline at end of file diff --git a/app/views/calculations/process_stats_form_template.html.erb b/app/views/calculations/process_stats_form_template.html.erb new file mode 100644 index 0000000..50d9b96 --- /dev/null +++ b/app/views/calculations/process_stats_form_template.html.erb @@ -0,0 +1,43 @@ +

Payment Results

+ +
+
Numbers Entered
+
<%= @numbers %>
+ +
Sorted Numbers
+
<%= @sorted %>
+ +
Count
+
<%= @count %>
+ +
Minimum
+
<%= @minimum %>
+ +
Maximum
+
<%= @maximum %>
+ +
Range
+
<%= @range %>
+ +
Median
+
<%= @median %>
+ +
Sum
+
<%= @sum %>
+ +
Mean
+
<%= @mean %>
+ +
Variance
+
<%= @variance %>
+ +
Standard Deviation
+
<%= @standard_deviation %>
+ +
Mode
+
<%= @mode %>
+ +
+ + + Calculate another Descriptive Stats \ No newline at end of file diff --git a/app/views/calculations/process_word_count_form_template.html.erb b/app/views/calculations/process_word_count_form_template.html.erb new file mode 100644 index 0000000..79d3ee5 --- /dev/null +++ b/app/views/calculations/process_word_count_form_template.html.erb @@ -0,0 +1,23 @@ +

Word Count Results

+ +
+
Text
+
<%= @text %>
+ +
Word Count
+
<%= @word_count %>
+ +
Character Count (with spaces)
+
<%= @character_count_with_spaces %>
+ +
Character Count (without spaces)
+
<%= @character_count_without_spaces %>
+ +
Occurances of <%= @special_word %>
+
<%= @occurrences %>
+ +
+ + + + Process more text \ No newline at end of file diff --git a/app/views/calculations/random_number_form_template.html.erb b/app/views/calculations/random_number_form_template.html.erb new file mode 100644 index 0000000..5e0cd8d --- /dev/null +++ b/app/views/calculations/random_number_form_template.html.erb @@ -0,0 +1,24 @@ +

Random Calculation

+ +
+
+ + + +
+ +
+ + + +
+ + +
+ diff --git a/app/views/calculations/square_form_template.html.erb b/app/views/calculations/square_form_template.html.erb new file mode 100644 index 0000000..2ccc9c0 --- /dev/null +++ b/app/views/calculations/square_form_template.html.erb @@ -0,0 +1,19 @@ +

Square Calculation

+ +
+
+ + + +
+ + +
+ + + + \ No newline at end of file diff --git a/app/views/calculations/square_root_form_template.html.erb b/app/views/calculations/square_root_form_template.html.erb new file mode 100644 index 0000000..9610af8 --- /dev/null +++ b/app/views/calculations/square_root_form_template.html.erb @@ -0,0 +1,17 @@ +

Square Root Calculation

+ +
+
+ + + +
+ + +
+ + diff --git a/app/views/calculations/stats_form_template.html.erb b/app/views/calculations/stats_form_template.html.erb new file mode 100644 index 0000000..1137a37 --- /dev/null +++ b/app/views/calculations/stats_form_template.html.erb @@ -0,0 +1,15 @@ +

Stats Calculation

+ +
+
+ + + +
+ + + +
+ diff --git a/app/views/calculations/word_count_form_template.html.erb b/app/views/calculations/word_count_form_template.html.erb new file mode 100644 index 0000000..376596f --- /dev/null +++ b/app/views/calculations/word_count_form_template.html.erb @@ -0,0 +1,23 @@ +

Word Count Calculation

+ +
+
+ + + +
+ +
+ + + +
+ + + +
+ diff --git a/config/routes.rb b/config/routes.rb index 8015e08..55374d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,51 @@ Rails.application.routes.draw do + + get("/homepage", { :controller => "calclations", :action => "homepage" }) + + + + get("/flexible/square/:a_number_flex", { :controller => "calculations", :action => "flex_square" }) + + get("/flexible/square_root/:a_number_flex", { :controller => "calculations", :action => "flex_square_root"}) + + get("/flexible/payment/:basis_points/:number_of_years/:present_value", {:controller => "calculations", :action => "flex_payment"}) + + get("/flexible/random/:random_number_flex", {:controller => "calculations", :action => "flex_random_number" }) + + + get("/square/new", { :controller => "calculations", :action => "square_form"}) + + get("/square_root/new", { :controller => "calculations", :action => "square_root_form"}) + + get("/payment/new", { :controller => "calculations", :action => "payment_form"}) + + get("/random/new", { :controller => "calculations", :action => "random_number_form"}) + + + get("/word_count/new", {:controller => "calculations", :action => "word_count_form"}) + + get("/descriptive_stats/new", {:controller => "calculations", :action => "stats_form"}) + + + + get("/square/results", { :controller => "calculations", :action => "process_square_form"}) + + get("/square_root/results", { :controller => "calculations", :action => "process_square_root_form"}) + + get("/payment/results", { :controller => "calculations", :action => "process_payment_form"}) + + get("/random/results", { :controller => "calculations", :action => "process_random_number_form"}) + + + get("/word_count/results", {:controller => "calculations", :action => "process_word_count_form"}) + + get("/descriptive_stats/results", {:controller => "calculations", :action => "process_stats_form"}) + + + + + + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html mount WebGit::Engine, at: "/rails/git" end diff --git a/public/homepage.html b/public/homepage.html new file mode 100644 index 0000000..8496925 --- /dev/null +++ b/public/homepage.html @@ -0,0 +1,103 @@ + + + + Target Omnicalc Params + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Part I Targets + + Flexible Square Example + + Flexible Square Root Example + + Flexible Payment Example + + Flexible Random Example +
+ Part II Targets + + Square Form + + Square Root Form + + Payment Form + + Random Number Form +
+ Part III Targets + + Word Count Form + + Stats Form +
+ +

+ Square Calculation +

+ +
+
+ + + +
+ + +
+ + +
+
+
+ + \ No newline at end of file diff --git a/public/omnicalc_params_homepage.html b/public/omnicalc_params_homepage.html new file mode 100644 index 0000000..2709a12 --- /dev/null +++ b/public/omnicalc_params_homepage.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Part I Targets

+
+ Flexible Square Example + + Flexible Square Example + + Flexible Square Example + + Flexible Square Example +
+

Part II Targets

+
+ Square Form + + Square Root Form + + Payment Form + + Random Number Form +
+

Part III Targets

+
+ Word Count Form + + Stats Form + + + + +
+

The function goes here

+
+ +