Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8a6658f
Square Calculation form & button
emklick Jul 13, 2017
5f1826e
setup and forms/templates
emklick Jul 17, 2017
bfbf802
forms and results
emklick Jul 17, 2017
c8aec2d
forms and results templates
emklick Jul 17, 2017
6571715
all forms and results templates are complete
emklick Jul 17, 2017
7a77463
gets and forms complete
emklick Jul 17, 2017
1edc8d9
linking everything together
emklick Jul 17, 2017
18a6e5a
random section updated
emklick Jul 17, 2017
d44e76c
homepage
emklick Jul 17, 2017
9a14c02
connections
emklick Jul 17, 2017
ad031a8
qwerty
emklick Jul 18, 2017
2eb9375
qwertyy
emklick Jul 18, 2017
9d207c2
testing
emklick Jul 18, 2017
71c9b62
square root calculation
emklick Jul 18, 2017
27751eb
payment
emklick Jul 18, 2017
683e744
square
emklick Jul 18, 2017
ec8ced6
random number - getting there
emklick Jul 18, 2017
0f18ecb
word_count
emklick Jul 18, 2017
618064a
descriptive stats
emklick Jul 18, 2017
8e3b84b
forms
emklick Jul 18, 2017
65f3445
grade run
emklick Jul 18, 2017
ec9cdcc
square
emklick Jul 18, 2017
252088e
square root form fixed
emklick Jul 18, 2017
c780217
Adjustments
emklick Jul 18, 2017
d158209
payment
emklick Jul 18, 2017
4ee8a1d
payment - not working
emklick Jul 18, 2017
b3cf60c
qwrwesytu
emklick Jul 18, 2017
b18e032
getting there on monthly
emklick Jul 18, 2017
617e5a7
payment calculation complete
emklick Jul 18, 2017
2938b61
connecting forms
emklick Jul 18, 2017
9aed510
getting forms and results pages linked
emklick Jul 18, 2017
6b4fcf3
connections
emklick Jul 18, 2017
cea203c
all connected - word count needs fixing
emklick Jul 18, 2017
3e8ae05
wordcount done
emklick Jul 18, 2017
56c94bc
stats
emklick Jul 18, 2017
c7daa26
ase
emklick Jul 18, 2017
61a1dd8
sdgfg
emklick Jul 18, 2017
5f70fd7
ertyjnbv
emklick Jul 18, 2017
8b6fe5a
wertgol,
emklick Jul 18, 2017
adea568
the
emklick Jul 18, 2017
77177a9
payment
emklick Jul 18, 2017
4d19f37
payment figured out
emklick Jul 19, 2017
0819692
descriptive stats - getting there
emklick Jul 19, 2017
f692b20
minimum
emklick Jul 19, 2017
fb4de83
stats - done
emklick Jul 19, 2017
928523e
complete
emklick Jul 19, 2017
b24aea8
Merge pull request #2 from emklick/done
emklick Jul 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
292 changes: 292 additions & 0 deletions app/controllers/calculations_controller.rb
Original file line number Diff line number Diff line change
@@ -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 = @[email protected](" ")

# 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

@[email protected] { |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 = @[email protected](" ")

@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

@[email protected] { |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

85 changes: 85 additions & 0 deletions app/controllers/homepage_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class CalculationsController < ApplicationController
def homepage

<table class="table table-hover">

div class="container">
<div class="row">
<div class="col-sm-5">
Part I Targets
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/flexible/square/new"> Flexible Square Example </a>
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/flexible/square_root/new"> Flexible Square Root Example </a>
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/flexible/payment/new"> Flexible Payment Example </a>
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/flexible/random/new"> Flexible Random Example </a>
</div>

</div>
<div class="row">
<div class="col-sm-5">
Part II Targets
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/square/new"> Square Form </a>
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/square_root/new"> Square Root Form </a>
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/payment/new"> Payment Form </a>
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/random/new"> Random Number Form </a>
</div>


</div>
<div class="row">
<div class="col-sm-5">
Part III Targets
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/word_count/new"> Word Count Form </a>
</div>

<div class="col-sm-5">
<a href = "https://omnicalc-params-emklick.c9users.io/descriptive_stats/new"> Stats Form </a>
</div>


</div>
<div class="row">
<div class="col-md-1">


</div>
</div>
</div>
</table>






render("calculations/homepage_template.html.erb")
end


end
3 changes: 3 additions & 0 deletions app/views/calculations/flexible_payment_template.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Flexible Payment</h1>

<p> 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) %> </p>
Loading