Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
65a2804
Challenge Started
fjavier Oct 4, 2015
fe18a79
Project Rails Created.
fjavier Oct 4, 2015
83d8cdc
Creating static pages welcome and about.
fjavier Oct 4, 2015
9e075a5
configure root, now appoint at the welcome action.
fjavier Oct 4, 2015
677c8f9
adding gem rxjs : Reactive Extension for Javascript
fjavier Oct 4, 2015
165f707
Adding the Rx.all library
fjavier Oct 4, 2015
73f1d92
Making some great stuff in the index view:
fjavier Oct 4, 2015
fe61394
Making some great stuff in the index view:
fjavier Oct 4, 2015
63a3b61
Getting price and Show in View
fjavier Oct 4, 2015
949ce24
Created a function to calculate the rolling average from the last fiv…
fjavier Oct 4, 2015
815ca5d
Validate the array length, i need 5 prices or more to calculate the R…
fjavier Oct 5, 2015
eb09cb6
Adding Bootstrap Gem to the project :)
fjavier Oct 5, 2015
75ce557
Just call the function to change the text
fjavier Oct 5, 2015
c7b7c5e
Adding some Styles at the Home Page
fjavier Oct 5, 2015
f5810b7
Aplying CSS styles.
fjavier Oct 5, 2015
0081365
Refactoring function calculateRollingAverage
fjavier Oct 5, 2015
24ed404
Updating history data in table.
fjavier Oct 5, 2015
2832bea
Show the time left to update the Current Price.
fjavier Oct 5, 2015
504a7e7
Adding stylesheet.
fjavier Oct 5, 2015
65cb654
Enable Gemfile.lock
fjavier Oct 5, 2015
c6f1dee
Gemfile.lock added
fjavier Oct 5, 2015
8816535
Removing sqlite3, not supported by heroku
fjavier Oct 5, 2015
cb1ee2f
--amend
fjavier Oct 5, 2015
fb4bf09
Adding Postgresql gem, required by heroku
fjavier Oct 5, 2015
5047350
Adding security port HTTPS, to get data.
fjavier Oct 5, 2015
2d40e6b
Removing console.log
fjavier Oct 5, 2015
70372b0
Challenge Complete
fjavier Oct 5, 2015
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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp
48 changes: 48 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'rxjs-rails' #Reactive Extension for Javascript
gem "twitter-bootstrap-rails"

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'

# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

163 changes: 163 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.1)
actionpack (= 4.2.1)
actionview (= 4.2.1)
activejob (= 4.2.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.1)
actionview (= 4.2.1)
activesupport (= 4.2.1)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.1)
activesupport (= 4.2.1)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.1)
activesupport (= 4.2.1)
globalid (>= 0.3.0)
activemodel (4.2.1)
activesupport (= 4.2.1)
builder (~> 3.1)
activerecord (4.2.1)
activemodel (= 4.2.1)
activesupport (= 4.2.1)
arel (~> 6.0)
activesupport (4.2.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
byebug (6.0.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
debug_inspector (0.0.2)
erubis (2.7.0)
execjs (2.6.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
jbuilder (2.3.2)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (4.0.5)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.6.2)
mini_portile (0.6.2)
minitest (5.8.1)
multi_json (1.11.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
pg (0.18.3)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.1)
actionmailer (= 4.2.1)
actionpack (= 4.2.1)
actionview (= 4.2.1)
activejob (= 4.2.1)
activemodel (= 4.2.1)
activerecord (= 4.2.1)
activesupport (= 4.2.1)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.1)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
railties (4.2.1)
actionpack (= 4.2.1)
activesupport (= 4.2.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
json (~> 1.4)
rxjs-rails (3.1.0)
railties (>= 3.0, < 5.0)
sass (3.4.18)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
spring (1.4.0)
sprockets (3.3.5)
rack (> 1, < 3)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
turbolinks (2.5.3)
coffee-rails
twitter-bootstrap-rails (3.2.0)
actionpack (~> 4.1)
execjs (~> 2.2)
rails (~> 4.1)
railties (~> 4.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
web-console (2.2.1)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)

PLATFORMS
ruby

DEPENDENCIES
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
pg
rails (= 4.2.1)
rxjs-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
turbolinks
twitter-bootstrap-rails
uglifier (>= 1.3.0)
web-console (~> 2.0)
28 changes: 28 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
== README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...


Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks
Empty file added app/assets/images/.keep
Empty file.
127 changes: 127 additions & 0 deletions app/assets/javascripts/app_challenge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
$(document).ready(function(){
//store the BPI Object
var bpiList = [];
var currentPriceEl = document.getElementById("current_price");
var rollingAverageEl =document.getElementById("rolling_average") ;

var oneMinAgoEl = document.getElementById("oneMinAgo");
var twoMinAgoEl = document.getElementById("twoMinAgo");
var threeMinAgoEl = document.getElementById("threeMinAgo");
var fourMinAgoEl = document.getElementById("fourMinAgo");
var fiveMinAgoEl = document.getElementById("fiveMinAgo");

var timeLeftEl = document.getElementById("timeLeft");

//Stream Observable, get from the url(API coindesk)
var requestStream = Rx.Observable.just("https://api.coindesk.com/v1/bpi/currentprice.json");

//Stream Observable, making plain object from the promise of Response
var responseStream = requestStream.flatMap(function(requestUrl){
return Rx.Observable.fromPromise($.getJSON(requestUrl));
});

//this stream will be execute each minute, starting when the page is loaded
var streamByMinute = Rx.Observable.interval(60000).startWith("startup");

//subscription
streamByMinute.subscribe(function(interval){
actionResponse();
});

//Actions when getting the response
function actionResponse(){
//Subscription for responseStream, update the value in current price.
//and calculate rolling_average, and update table of last five values
responseStream.subscribe(function(objectBpi){
streamBySecond();

var price = objectBpi.bpi.USD.rate;
//store the attr rate
bpiList.push(price);

//Update Text with the Current Value
updateContent(currentPriceEl, price + "$");

//Stream from array with the last Five Value
var streamLastFiveValue = Rx.Observable.fromArray(bpiList);
var mappedList = getStreamMappedToFloat(streamLastFiveValue);

//Validate if the length of array is greater than 5 then
updateHistoryPriceList(streamLastFiveValue);
if(bpiList.length >= 5){
calculateRollingAverage(mappedList);
}


});

}

function getStreamMappedToFloat(streamListValue){
return streamListValue.map(function(value){
return parseFloat(value);
});
}

function calculateRollingAverage(streamListValue){
subscriptionAverage = streamListValue.average().subscribe(function(value){
updateContent(rollingAverageEl, value.toFixed(4) + "$");
//shift the first element, dont need the value anymore.
bpiList.shift();
});
//don't need the subscription anymore
subscriptionAverage.dispose();
}

function updateHistoryPriceList(streamListValue){
stream = streamListValue.select(function(value, idx, obs){
return {index: idx, valor: value};
}).subscribe(function(value){
udpateDataTableHistory(value.index, value.valor);

});

stream.dispose();
}

function udpateDataTableHistory(idx, value){
rateHistoricText = value + "$";
switch(idx){
case 0:
oneMinAgoEl.textContent = rateHistoricText;
break;
case 1:
twoMinAgoEl.textContent = rateHistoricText;
break;
case 2:
threeMinAgoEl.textContent = rateHistoricText;
break;
case 3:
fourMinAgoEl.textContent = rateHistoricText;
break;
case 4:
fiveMinAgoEl.textContent = rateHistoricText;
break;
default:
console.log("default");
break;
}
}

function streamBySecond(){
Rx.Observable.interval(1000).map(
function(x){
time = 60 - x;
return time;
}).take(60).subscribe(
function(timeLeft){
updateContent(timeLeftEl,"Updating Price in "+ timeLeft + " Seg.")
});

}

function updateContent(element, text){
element.textContent = text;
}
}
);
Loading