├── log
└── .keep
├── storage
└── .keep
├── tmp
└── .keep
├── vendor
└── .keep
├── lib
├── assets
│ └── .keep
└── tasks
│ ├── .keep
│ ├── stocks.rake
│ └── athletes.rake
├── public
├── favicon.ico
├── apple-touch-icon.png
├── apple-touch-icon-precomposed.png
├── robots.txt
├── 500.html
├── 422.html
└── 404.html
├── test
├── helpers
│ └── .keep
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ ├── order_test.rb
│ ├── stock_test.rb
│ ├── tweet_test.rb
│ ├── user_test.rb
│ ├── athlete_test.rb
│ ├── watchlist_item_test.rb
│ ├── user_port_snapshot_test.rb
│ ├── tweet_score_snapshot_test.rb
│ └── athlete_price_snapshot_test.rb
├── system
│ └── .keep
├── controllers
│ └── .keep
├── fixtures
│ ├── .keep
│ ├── files
│ │ └── .keep
│ ├── watchlist_items.yml
│ ├── athlete_price_snapshots.yml
│ ├── user_port_snapshots.yml
│ ├── tweets.yml
│ ├── stocks.yml
│ ├── users.yml
│ ├── tweet_score_snapshots.yml
│ ├── orders.yml
│ └── athletes.yml
├── integration
│ └── .keep
├── application_system_test_case.rb
└── test_helper.rb
├── .ruby-version
├── app
├── assets
│ ├── images
│ │ ├── .keep
│ │ └── trade_testimony_2.png
│ ├── javascripts
│ │ ├── channels
│ │ │ └── .keep
│ │ ├── cable.js
│ │ └── application.js
│ ├── config
│ │ └── manifest.js
│ └── stylesheets
│ │ ├── application.css
│ │ ├── home_chart.css
│ │ ├── not_found.css
│ │ ├── reset.css
│ │ ├── top_movers.css
│ │ ├── tweet.css
│ │ ├── news_articles.css
│ │ ├── athlete_stats.css
│ │ ├── account_menu.css
│ │ ├── login.css
│ │ ├── search.css
│ │ ├── signup.css
│ │ ├── home.css
│ │ ├── athlete_show.css
│ │ ├── user_stocks_card.css
│ │ ├── buy_sell.css
│ │ ├── loader.css
│ │ └── greeting.css
├── models
│ ├── concerns
│ │ └── .keep
│ ├── watchlist_item.rb
│ ├── user_port_snapshot.rb
│ ├── tweet_score_snapshot.rb
│ ├── athlete_price_snapshot.rb
│ ├── application_record.rb
│ ├── order.rb
│ ├── athlete.rb
│ ├── user.rb
│ ├── stock.rb
│ └── tweet.rb
├── controllers
│ ├── concerns
│ │ └── .keep
│ ├── static_pages_controller.rb
│ ├── api
│ │ ├── tweet_score_snapshots_controller.rb
│ │ ├── stocks_controller.rb
│ │ ├── athletes_controller.rb
│ │ ├── tweets_controller.rb
│ │ ├── athlete_price_snapshots_controller.rb
│ │ ├── sessions_controller.rb
│ │ ├── users_port_snapshots_controller.rb
│ │ ├── users_controller.rb
│ │ ├── watchlist_items_controller.rb
│ │ └── orders_controller.rb
│ └── application_controller.rb
├── views
│ ├── layouts
│ │ ├── mailer.text.erb
│ │ ├── mailer.html.erb
│ │ └── application.html.erb
│ ├── api
│ │ ├── users
│ │ │ ├── show.json.jbuilder
│ │ │ ├── _user.json.jbuilder
│ │ │ └── index.json.jbuilder
│ │ ├── watchlist_items
│ │ │ ├── show.json.jbuilder
│ │ │ └── index.json.jbuilder
│ │ ├── stocks
│ │ │ ├── show.json.jbuilder
│ │ │ └── index.json.jbuilder
│ │ ├── orders
│ │ │ ├── show.json.jbuilder
│ │ │ ├── show_order.json.jbuilder
│ │ │ └── index.json.jbuilder
│ │ ├── users_port_snapshots
│ │ │ ├── show.json.jbuilder
│ │ │ └── index.json.jbuilder
│ │ ├── athlete_price_snapshots
│ │ │ └── index.json.jbuilder
│ │ ├── tweets
│ │ │ └── index.json.jbuilder
│ │ ├── tweet_score_snapshots
│ │ │ └── index.json.jbuilder
│ │ └── athletes
│ │ │ ├── show.json.jbuilder
│ │ │ └── index.json.jbuilder
│ └── static_pages
│ │ └── root.html.erb
├── helpers
│ └── application_helper.rb
├── jobs
│ └── application_job.rb
├── channels
│ └── application_cable
│ │ ├── channel.rb
│ │ └── connection.rb
└── mailers
│ └── application_mailer.rb
├── frontend
├── actions
│ ├── tweet_actions.js
│ ├── athlete_actions.js
│ ├── stock_actions.js
│ ├── order_actions.js
│ ├── watchlist_actions.js
│ └── session_actions.js
├── components
│ ├── leaderboard
│ │ ├── leaderboard.jsx
│ │ └── leaderboard_container.js
│ ├── home
│ │ ├── news_articles
│ │ │ ├── news_articles_container.js
│ │ │ ├── news_articles_index.jsx
│ │ │ └── news_articles_index_item.jsx
│ │ ├── home_chart
│ │ │ ├── home_chart_container.js
│ │ │ └── home_chart.jsx
│ │ ├── user_stocks
│ │ │ ├── user_stocks_container.jsx
│ │ │ ├── user_stocks_item.jsx
│ │ │ └── user_stocks_index.jsx
│ │ ├── buy_sell
│ │ │ └── buy_sell_container.js
│ │ ├── top_movers
│ │ │ ├── top_movers_container.js
│ │ │ ├── top_movers_index_item.jsx
│ │ │ └── top_movers_index.jsx
│ │ └── home_container.jsx
│ ├── root.jsx
│ ├── athlete
│ │ ├── tweets
│ │ │ ├── tweets_index.jsx
│ │ │ └── tweets_index_item.jsx
│ │ ├── athlete_chart
│ │ │ └── athlete_chart_container.js
│ │ ├── athlete_fg_percentage.jsx
│ │ ├── athlete_show_container.js
│ │ └── athlete_stats.jsx
│ ├── greeting
│ │ └── greeting_container.js
│ ├── session_form
│ │ ├── login_form_container.jsx
│ │ ├── signup_form_container.jsx
│ │ ├── session_form.jsx
│ │ ├── login_form.jsx
│ │ └── signup_form.jsx
│ ├── free_stock
│ │ ├── free_stock_container.js
│ │ └── free_stock.jsx
│ ├── not_found.jsx
│ ├── App.jsx
│ └── search_bar
│ │ └── search_bar.jsx
├── util
│ ├── user_port_snapshots_api_util.js
│ ├── stock_api_util.js
│ ├── athlete_api_util.js
│ ├── order_api_util.js
│ ├── watchlist_api_util.js
│ ├── session_api_util.js
│ └── route_util.jsx
├── reducers
│ ├── errors_reducer.js
│ ├── root_reducer.js
│ ├── session_errors_reducer.js
│ ├── stocks_reducer.js
│ ├── users_reducer.js
│ ├── athletes_reducer.js
│ ├── entities_reducer.js
│ ├── orders_reducer.js
│ ├── session_reducer.js
│ └── watchlist_reducer.js
├── store
│ └── store.js
└── trade_blitz.jsx
├── config
├── initializers
│ ├── sentimental.rb
│ ├── mime_types.rb
│ ├── filter_parameter_logging.rb
│ ├── application_controller_renderer.rb
│ ├── cookies_serializer.rb
│ ├── backtrace_silencers.rb
│ ├── wrap_parameters.rb
│ ├── assets.rb
│ ├── inflections.rb
│ └── content_security_policy.rb
├── spring.rb
├── environment.rb
├── boot.rb
├── cable.yml
├── credentials.yml.enc
├── schedule.rb
├── application.rb
├── routes.rb
├── locales
│ └── en.yml
├── storage.yml
├── puma.rb
├── environments
│ ├── test.rb
│ ├── development.rb
│ └── production.rb
└── database.yml
├── bin
├── bundle
├── rake
├── rails
├── yarn
├── spring
├── update
└── setup
├── config.ru
├── db
├── migrate
│ ├── 20181012000110_rename_type_column.rb
│ ├── 20181016030209_add_buying_power_to_users.rb
│ ├── 20181015210353_add_info_to_stocks.rb
│ ├── 20181011080044_create_tweets.rb
│ ├── 20181018030032_create_watchlist_items.rb
│ ├── 20181018014434_create_user_port_snapshots.rb
│ ├── 20181018021345_create_tweet_score_snapshots.rb
│ ├── 20181018021757_create_athlete_price_snapshots.rb
│ ├── 20181011063908_create_stocks.rb
│ ├── 20181009185636_create_users.rb
│ ├── 20181011065159_create_orders.rb
│ └── 20181011054839_create_athletes.rb
├── seeds.rb
└── schema.rb
├── Rakefile
├── webpack.config.js
├── .gitignore
├── package.json
├── Gemfile
└── README.md
/log/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/storage/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tmp/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/vendor/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/helpers/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/mailers/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/models/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/system/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 2.5.1
2 |
--------------------------------------------------------------------------------
/app/assets/images/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/controllers/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/fixtures/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/integration/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/models/concerns/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/fixtures/files/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/frontend/actions/tweet_actions.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/assets/javascripts/channels/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/frontend/components/leaderboard/leaderboard.jsx:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.text.erb:
--------------------------------------------------------------------------------
1 | <%= yield %>
2 |
--------------------------------------------------------------------------------
/frontend/components/leaderboard/leaderboard_container.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | class ApplicationJob < ActiveJob::Base
2 | end
3 |
--------------------------------------------------------------------------------
/app/models/watchlist_item.rb:
--------------------------------------------------------------------------------
1 | class WatchlistItem < ApplicationRecord
2 | end
3 |
--------------------------------------------------------------------------------
/app/views/api/users/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.partial! "api/users/user", user: @user
--------------------------------------------------------------------------------
/app/models/user_port_snapshot.rb:
--------------------------------------------------------------------------------
1 | class UserPortSnapshot < ApplicationRecord
2 | end
3 |
--------------------------------------------------------------------------------
/app/models/tweet_score_snapshot.rb:
--------------------------------------------------------------------------------
1 | class TweetScoreSnapshot < ApplicationRecord
2 | end
3 |
--------------------------------------------------------------------------------
/config/initializers/sentimental.rb:
--------------------------------------------------------------------------------
1 | $analyzer = Sentimental.new
2 | $analyzer.load_defaults
--------------------------------------------------------------------------------
/app/models/athlete_price_snapshot.rb:
--------------------------------------------------------------------------------
1 | class AthletePriceSnapshot < ApplicationRecord
2 | end
3 |
--------------------------------------------------------------------------------
/app/views/api/users/_user.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.extract! user, :id, :first_name, :last_name, :email, :buying_power
--------------------------------------------------------------------------------
/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | class ApplicationRecord < ActiveRecord::Base
2 | self.abstract_class = true
3 | end
4 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 |
--------------------------------------------------------------------------------
/app/views/api/watchlist_items/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.set! @item.id do
2 | json.extract! @item, :id, :user_id, :stock_id
3 | end
--------------------------------------------------------------------------------
/app/assets/images/trade_testimony_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirivatd/robinhoops/HEAD/app/assets/images/trade_testimony_2.png
--------------------------------------------------------------------------------
/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Channel < ActionCable::Channel::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | //= link_tree ../images
2 | //= link_directory ../javascripts .js
3 | //= link_directory ../stylesheets .css
4 |
--------------------------------------------------------------------------------
/app/controllers/static_pages_controller.rb:
--------------------------------------------------------------------------------
1 | class StaticPagesController < ApplicationController
2 | def root
3 |
4 | end
5 |
6 | end
--------------------------------------------------------------------------------
/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Connection < ActionCable::Connection::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | class ApplicationMailer < ActionMailer::Base
2 | default from: 'from@example.com'
3 | layout 'mailer'
4 | end
5 |
--------------------------------------------------------------------------------
/app/views/api/stocks/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.set! @stock.id do
2 | json.extract! @stock, :id, :athlete_id, :current_price, :initial_price
3 | end
4 |
--------------------------------------------------------------------------------
/config/spring.rb:
--------------------------------------------------------------------------------
1 | %w[
2 | .ruby-version
3 | .rbenv-vars
4 | tmp/restart.txt
5 | tmp/caching-dev.txt
6 | ].each { |path| Spring.watch(path) }
7 |
--------------------------------------------------------------------------------
/app/views/api/orders/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.set! @order.stock.id do
2 | json.extract! @order.stock, :id, :athlete_id, :current_price, :initial_price
3 | end
--------------------------------------------------------------------------------
/app/views/api/users/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @users.each do |user|
2 | json.set! user.id do
3 | json.partial! "api/users/user", user: user
4 | end
5 | end
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require_relative 'config/environment'
4 |
5 | run Rails.application
6 |
--------------------------------------------------------------------------------
/app/views/api/watchlist_items/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @watchlist_items.each do |item|
2 | json.set! item.id do
3 | json.extract! item, :id, :user_id, :stock_id
4 | end
5 | end
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative 'application'
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/test/models/order_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class OrderTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/models/stock_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class StockTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/models/tweet_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class TweetTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/models/user_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class UserTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/app/views/api/users_port_snapshots/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.set! @user_port_snapshot.id do
2 | json.extract! @user_port_snapshot, :id, :user_id, :port_value, :created_at
3 | end
--------------------------------------------------------------------------------
/test/models/athlete_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class AthleteTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/app/views/api/athlete_price_snapshots/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @snapshots.each do |snapshot|
2 | json.set! snapshot.id do
3 | json.extract! snapshot, :id, :price, :created_at
4 | end
5 | end
--------------------------------------------------------------------------------
/app/views/api/stocks/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @stocks.each do |stock|
2 | json.set! stock.id do
3 | json.extract! stock, :id, :athlete_id, :current_price, :initial_price
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/app/views/api/tweets/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @tweets.each do |tweet|
2 | json.set! @athlete.random_num do
3 | json.extract! tweet, :tweetBody, :tweetUsername, :time_created
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/app/views/api/users_port_snapshots/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @snapshots.each do |snapshot|
2 | json.set! snapshot.id do
3 | json.extract! snapshot, :id, :port_value, :created_at
4 | end
5 |
6 | end
--------------------------------------------------------------------------------
/db/migrate/20181012000110_rename_type_column.rb:
--------------------------------------------------------------------------------
1 | class RenameTypeColumn < ActiveRecord::Migration[5.2]
2 | def change
3 | rename_column :orders, :type, :order_type
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/test/models/watchlist_item_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class WatchlistItemTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/models/user_port_snapshot_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class UserPortSnapshotTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/models/tweet_score_snapshot_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class TweetScoreSnapshotTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/test/models/athlete_price_snapshot_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class AthletePriceSnapshotTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/app/views/api/tweet_score_snapshots/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @scores.each do |score|
2 | json.set! score.id do
3 | json.extract! score, :id, :twitter_sentiment, :athlete_id, :created_at
4 | end
5 | end
--------------------------------------------------------------------------------
/test/application_system_test_case.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 |
3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
5 | end
6 |
--------------------------------------------------------------------------------
/app/models/order.rb:
--------------------------------------------------------------------------------
1 | class Order < ApplicationRecord
2 | belongs_to :stock
3 |
4 | belongs_to :user
5 |
6 | has_one :athlete,
7 | through: :stock,
8 | source: :athlete
9 |
10 | end
11 |
--------------------------------------------------------------------------------
/db/migrate/20181016030209_add_buying_power_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddBuyingPowerToUsers < ActiveRecord::Migration[5.2]
2 | def change
3 | add_column :users, :buying_power, :float, null: false
4 |
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/lib/tasks/stocks.rake:
--------------------------------------------------------------------------------
1 | namespace :stocks do
2 | desc "TODO"
3 | task updatePrice: :environment do
4 | Stock.all.each do |stock|
5 | Stock.update_price(stock)
6 | end
7 | end
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/app/controllers/api/tweet_score_snapshots_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::TweetScoreSnapshotsController < ApplicationController
2 | def index
3 | @scores = TweetScoreSnapshot.where(athlete_id: params[:athlete_id])
4 | end
5 | end
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
5 |
--------------------------------------------------------------------------------
/test/fixtures/watchlist_items.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | user_id: 1
5 | stock_id: 1
6 |
7 | two:
8 | user_id: 1
9 | stock_id: 1
10 |
--------------------------------------------------------------------------------
/app/controllers/api/stocks_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::StocksController < ApplicationController
2 | def index
3 | @stocks = Stock.all
4 | end
5 |
6 | def show
7 | @stock = Stock.find(params[:id])
8 | end
9 | end
--------------------------------------------------------------------------------
/db/migrate/20181015210353_add_info_to_stocks.rb:
--------------------------------------------------------------------------------
1 | class AddInfoToStocks < ActiveRecord::Migration[5.2]
2 | def change
3 | add_column :stocks, :day_end_price, :float
4 | add_column :stocks, :day_start_price, :float
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/test/fixtures/athlete_price_snapshots.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | athlete_id: 1
5 | price: 1.5
6 |
7 | two:
8 | athlete_id: 1
9 | price: 1.5
10 |
--------------------------------------------------------------------------------
/test/fixtures/user_port_snapshots.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | user_id: 1
5 | port_value: 1.5
6 |
7 | two:
8 | user_id: 1
9 | port_value: 1.5
10 |
--------------------------------------------------------------------------------
/app/controllers/api/athletes_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::AthletesController < ApplicationController
2 | def show
3 | @athlete = Athlete.find(params[:id])
4 | end
5 |
6 | def index
7 | @athletes = Athlete.all
8 | end
9 | end
--------------------------------------------------------------------------------
/app/controllers/api/tweets_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::TweetsController < ApplicationController
2 |
3 | def index
4 | @athlete = Athlete.find(params[:athlete_id])
5 | @tweets = Tweet.find_tweets(@athlete.name)
6 | end
7 |
8 | end
--------------------------------------------------------------------------------
/app/views/api/orders/show_order.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.set! @order.id do
2 | json.extract! @order, :id, :order_type, :num_share, :user_id, :stock_id, :purchase_date, :purchase_price, :total_return, :today_return, :equity, :created_at, :updated_at
3 | end
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require_relative 'config/application'
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: async
6 |
7 | production:
8 | adapter: redis
9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10 | channel_prefix: trade-blitz_production
11 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require_relative '../config/boot'
8 | require 'rake'
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/app/controllers/api/athlete_price_snapshots_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::AthletePriceSnapshotsController < ApplicationController
2 | def index
3 | @snapshots = AthletePriceSnapshot.where(athlete_id: params[:athlete_id])
4 |
5 | end
6 |
7 |
8 | end
--------------------------------------------------------------------------------
/app/models/athlete.rb:
--------------------------------------------------------------------------------
1 | class Athlete < ApplicationRecord
2 | has_one :stock
3 | has_many :tweets
4 |
5 | def update_price
6 | print("Updating")
7 | end
8 |
9 | def random_num
10 | return rand(1000-10) + 10
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/frontend/util/user_port_snapshots_api_util.js:
--------------------------------------------------------------------------------
1 | export const createUserPortSnapshot = snapshot => {
2 | return $.ajax({
3 | method: "POST",
4 | url: `/api/users/${snapshot.user_id}/users_port_snapshots`,
5 | data: { snapshot: snapshot }
6 | });
7 | };
8 |
--------------------------------------------------------------------------------
/test/fixtures/tweets.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | body: MyString
5 | score: 1.5
6 | athlete_id: 1
7 |
8 | two:
9 | body: MyString
10 | score: 1.5
11 | athlete_id: 1
12 |
--------------------------------------------------------------------------------
/app/views/api/orders/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @orders.each do |order|
2 | json.set! order.id do
3 | json.extract! order, :id, :order_type, :num_share, :user_id, :stock_id, :purchase_date, :purchase_price, :total_return, :today_return, :equity, :created_at, :updated_at
4 | end
5 | end
6 |
7 |
--------------------------------------------------------------------------------
/frontend/reducers/errors_reducer.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from "redux";
2 |
3 | import sessionErrorsReducer from "./session_errors_reducer";
4 |
5 | const errorsReducer = combineReducers({
6 | session: sessionErrorsReducer
7 | });
8 |
9 | export default errorsReducer;
10 |
--------------------------------------------------------------------------------
/test/fixtures/stocks.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | athlete_id: 1
5 | current_price: 1.5
6 | initial_price: 1.5
7 |
8 | two:
9 | athlete_id: 1
10 | current_price: 1.5
11 | initial_price: 1.5
12 |
--------------------------------------------------------------------------------
/app/views/static_pages/root.html.erb:
--------------------------------------------------------------------------------
1 | <% if logged_in? %>
2 |
8 | <% end %>
9 |
10 |
--------------------------------------------------------------------------------
/config/initializers/application_controller_renderer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # ActiveSupport::Reloader.to_prepare do
4 | # ApplicationController.renderer.defaults.merge!(
5 | # http_host: 'example.org',
6 | # https: false
7 | # )
8 | # end
9 |
--------------------------------------------------------------------------------
/lib/tasks/athletes.rake:
--------------------------------------------------------------------------------
1 | namespace :athletes do
2 | desc "TODO"
3 | task updateAthletes: :environment do
4 | puts "Updating athletes"
5 | Athlete.all.each do |athlete|
6 | athlete.update_price()
7 | end
8 | puts "#{Time.now} - Success!"
9 | end
10 |
11 | end
12 |
--------------------------------------------------------------------------------
/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Specify a serializer for the signed and encrypted cookie jars.
4 | # Valid options are :json, :marshal, and :hybrid.
5 | Rails.application.config.action_dispatch.cookies_serializer = :json
6 |
--------------------------------------------------------------------------------
/frontend/util/stock_api_util.js:
--------------------------------------------------------------------------------
1 | export const fetchStocks = () => {
2 | return $.ajax({
3 | method: "GET",
4 | url: "api/stocks"
5 | });
6 | };
7 |
8 | export const fetchStock = id => {
9 | return $.ajax({
10 | method: "GET",
11 | url: `api/stocks/${id}`
12 | });
13 | };
14 |
--------------------------------------------------------------------------------
/db/migrate/20181011080044_create_tweets.rb:
--------------------------------------------------------------------------------
1 | class CreateTweets < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :tweets do |t|
4 | t.string :body
5 | t.float :score
6 | t.integer :athlete_id, null: false
7 |
8 | t.timestamps
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | APP_PATH = File.expand_path('../config/application', __dir__)
8 | require_relative '../config/boot'
9 | require 'rails/commands'
10 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/db/migrate/20181018030032_create_watchlist_items.rb:
--------------------------------------------------------------------------------
1 | class CreateWatchlistItems < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :watchlist_items do |t|
4 | t.integer :user_id, null: false
5 | t.integer :stock_id, null: false
6 |
7 | t.timestamps
8 | end
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/db/migrate/20181018014434_create_user_port_snapshots.rb:
--------------------------------------------------------------------------------
1 | class CreateUserPortSnapshots < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :user_port_snapshots do |t|
4 | t.integer :user_id, null: false
5 | t.float :port_value, null: false
6 |
7 | t.timestamps
8 | end
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/db/migrate/20181018021345_create_tweet_score_snapshots.rb:
--------------------------------------------------------------------------------
1 | class CreateTweetScoreSnapshots < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :tweet_score_snapshots do |t|
4 | t.integer :athlete_id, null: false
5 | t.float :twitter_sentiment, null: false
6 | t.timestamps
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/db/migrate/20181018021757_create_athlete_price_snapshots.rb:
--------------------------------------------------------------------------------
1 | class CreateAthletePriceSnapshots < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :athlete_price_snapshots do |t|
4 | t.integer :athlete_id, null: false
5 | t.float :price, null: false
6 |
7 | t.timestamps
8 | end
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RAILS_ENV'] ||= 'test'
2 | require_relative '../config/environment'
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7 | fixtures :all
8 |
9 | # Add more helper methods to be used by all tests here...
10 | end
11 |
--------------------------------------------------------------------------------
/bin/yarn:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_ROOT = File.expand_path('..', __dir__)
3 | Dir.chdir(APP_ROOT) do
4 | begin
5 | exec "yarnpkg", *ARGV
6 | rescue Errno::ENOENT
7 | $stderr.puts "Yarn executable was not detected in the system."
8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9 | exit 1
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/frontend/reducers/root_reducer.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from "redux";
2 |
3 | import entities from "./entities_reducer";
4 | import session from "./session_reducer";
5 | import errors from "./errors_reducer";
6 |
7 | const rootReducer = combineReducers({
8 | entities,
9 | session,
10 | errors
11 | });
12 |
13 | export default rootReducer;
14 |
--------------------------------------------------------------------------------
/frontend/components/home/news_articles/news_articles_container.js:
--------------------------------------------------------------------------------
1 | import NewsArticlesIndex from "./news_articles_index";
2 | import { connect } from "react-redux";
3 |
4 | const mSP = (props, ownProps) => {
5 | return {
6 | articles: ownProps.articles
7 | };
8 | };
9 |
10 | export default connect(
11 | mSP,
12 | null
13 | )(NewsArticlesIndex);
14 |
--------------------------------------------------------------------------------
/db/migrate/20181011063908_create_stocks.rb:
--------------------------------------------------------------------------------
1 | class CreateStocks < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :stocks do |t|
4 | t.integer :athlete_id, null: false, unique: true
5 | t.float :current_price
6 | t.float :initial_price
7 |
8 | t.timestamps
9 | end
10 | add_index(:stocks, :athlete_id)
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/frontend/components/root.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Provider } from "react-redux";
3 | import { HashRouter } from "react-router-dom";
4 | import App from "./App";
5 |
6 | const Root = ({ store }) => (
7 |
8 |
9 |
10 |
11 |
12 | );
13 |
14 | export default Root;
15 |
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Robinhoops
5 | <%= csrf_meta_tags %>
6 | <%= csp_meta_tag %>
7 |
8 | <%= stylesheet_link_tag 'application', media: 'all' %>
9 | <%= javascript_include_tag 'application' %>
10 |
11 |
12 |
13 | <%= yield %>
14 |
15 |
16 |
--------------------------------------------------------------------------------
/frontend/store/store.js:
--------------------------------------------------------------------------------
1 | import { createStore, applyMiddleware } from "redux";
2 | import logger from "redux-logger";
3 | import thunk from "redux-thunk";
4 | import rootReducer from "../reducers/root_reducer";
5 |
6 | const configureStore = (preloadedState = {}) =>
7 | createStore(rootReducer, preloadedState, applyMiddleware(thunk, logger));
8 |
9 | export default configureStore;
10 |
--------------------------------------------------------------------------------
/test/fixtures/users.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | email: MyString
5 | password_digest: MyString
6 | first_name: MyString
7 | last_name: MyString
8 | session_token: MyString
9 |
10 | two:
11 | email: MyString
12 | password_digest: MyString
13 | first_name: MyString
14 | last_name: MyString
15 | session_token: MyString
16 |
--------------------------------------------------------------------------------
/test/fixtures/tweet_score_snapshots.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | # This model initially had no columns defined. If you add columns to the
4 | # model remove the '{}' from the fixture names and add the columns immediately
5 | # below each fixture, per the syntax in the comments below
6 | #
7 | one: {}
8 | # column: value
9 | #
10 | two: {}
11 | # column: value
12 |
--------------------------------------------------------------------------------
/app/assets/javascripts/cable.js:
--------------------------------------------------------------------------------
1 | // Action Cable provides the framework to deal with WebSockets in Rails.
2 | // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3 | //
4 | //= require action_cable
5 | //= require_self
6 | //= require_tree ./channels
7 |
8 | (function() {
9 | this.App || (this.App = {});
10 |
11 | App.cable = ActionCable.createConsumer();
12 |
13 | }).call(this);
14 |
--------------------------------------------------------------------------------
/frontend/reducers/session_errors_reducer.js:
--------------------------------------------------------------------------------
1 | import {
2 | RECEIVE_SESSION_ERRORS,
3 | RECEIVE_CURRENT_USER
4 | } from "../actions/session_actions";
5 |
6 | export default (state = [], action) => {
7 | Object.freeze(state);
8 | switch (action.type) {
9 | case RECEIVE_SESSION_ERRORS:
10 | return action.errors;
11 | case RECEIVE_CURRENT_USER:
12 | return [];
13 | default:
14 | return state;
15 | }
16 | };
17 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/credentials.yml.enc:
--------------------------------------------------------------------------------
1 | RQQTLKM+7Xz1Xpa7g3oI0ioY0qj7U5gTL5IjXv9yVbtweZg8RxHLzYGEUW/aZGq5xXUfIzFI6G4QGvgOPJvFrevfN7NdMb2BIYKn4FrsrF2+YoTfzs1pHf3xy/y6uV7ZLM5cg0Y8kD6BqJEsI6POdoQaBch8f2v2SVoODkG4K6/pElawMJtyMwFfYjRoNsKksIqsST3hmeP4ZSN7HkIHkD5ITALXJ52P/CkxnSoLp6E6KndSJvsQT6tBbdOa2sZxF36EcASEn50f4pgVBxvLDSx5Avq2BwiyPv95dF1tPrnlYr60f8YnMRCJFK384ggmJPAxjgB+yShio6DfR6+IRic5kA+DBltpRTxMLfXTUVZ1CftlcsFT8wh3Z2WVqm31F+3DoEb5DdMPcO0oz4fyHgtb3l61KIVgLnk5--gu7v+MOr25gBLjAg--SY+IS9uxuO1zgHS90OAKHA==
--------------------------------------------------------------------------------
/db/migrate/20181009185636_create_users.rb:
--------------------------------------------------------------------------------
1 | class CreateUsers < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :users do |t|
4 | t.string :email, null: false, unique: true
5 | t.string :password_digest, null: false
6 | t.string :first_name, null: false
7 | t.string :last_name, null: false
8 | t.string :session_token, null: false
9 |
10 | t.timestamps
11 | end
12 | add_index :users, :email
13 |
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/frontend/components/athlete/tweets/tweets_index.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import TweetsIndexItem from "./tweets_index_item";
3 |
4 | const TweetsIndex = ({ tweets }) => {
5 | const tweetItems = () =>
6 | tweets
7 | .slice(0, 6)
8 | .map(tweet => (
9 |
10 | ));
11 | return {tweetItems()}
;
12 | };
13 |
14 | export default TweetsIndex;
15 |
--------------------------------------------------------------------------------
/frontend/util/athlete_api_util.js:
--------------------------------------------------------------------------------
1 | export const fetchAthlete = id => {
2 | return $.ajax({
3 | url: `/api/athletes/${id}`,
4 | method: "GET"
5 | });
6 | };
7 |
8 | export const fetchAllAthletes = userId => {
9 | return $.ajax({
10 | url: `api/athletes`,
11 | method: "GET"
12 | });
13 | };
14 |
15 | export const fetchAthleteTweets = athleteId => {
16 | return $.ajax({
17 | url: `api/athletes/${athleteId}/tweets`,
18 | method: "GET"
19 | });
20 | };
21 |
--------------------------------------------------------------------------------
/app/views/api/athletes/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.set! @athlete.id do
2 | json.extract! @athlete, :name, :team_acronym, :team_name, :games_played, :minutes_per_game, :field_goals_attempted_per_game, :field_goal_percentage, :free_throw_percentage, :three_point_percentage, :points_per_game, :offensive_rebounds_per_game, :defensive_rebounds_per_game, :rebounds_per_game, :assists_per_game, :steals_per_game, :blocks_per_game, :turnovers_per_game, :player_efficiency_rating, :twitter_sentiment, :image_url
3 | end
--------------------------------------------------------------------------------
/db/migrate/20181011065159_create_orders.rb:
--------------------------------------------------------------------------------
1 | class CreateOrders < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :orders do |t|
4 | t.string :type
5 | t.integer :num_share
6 | t.string :user_id, null: false
7 | t.string :stock_id, null: false
8 | t.date :purchase_date
9 | t.float :purchase_price
10 | t.float :total_return
11 | t.float :today_return
12 | t.float :equity
13 |
14 | t.timestamps
15 | end
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/app/views/api/athletes/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @athletes.each do |athlete|
2 | json.set! athlete.id do
3 | json.extract! athlete, :id, :name, :team_acronym, :team_name, :games_played, :minutes_per_game, :field_goals_attempted_per_game, :field_goal_percentage, :free_throw_percentage, :three_point_percentage, :points_per_game, :offensive_rebounds_per_game, :defensive_rebounds_per_game, :rebounds_per_game, :assists_per_game, :steals_per_game, :blocks_per_game, :turnovers_per_game, :player_efficiency_rating, :twitter_sentiment, :image_url
4 | end
5 | end
--------------------------------------------------------------------------------
/frontend/components/athlete/athlete_chart/athlete_chart_container.js:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import AthleteChart from "./athlete_chart";
5 |
6 | const mapStateToProps = (props, ownProps) => {
7 | return {
8 | currentUser: ownProps.currentUser,
9 | athleteId: ownProps.athleteId,
10 | graphOption: ownProps.graphOption
11 | };
12 | };
13 |
14 | export default connect(
15 | mapStateToProps,
16 | null
17 | )(AthleteChart);
18 |
--------------------------------------------------------------------------------
/frontend/reducers/stocks_reducer.js:
--------------------------------------------------------------------------------
1 | import merge from "lodash/merge";
2 |
3 | import { RECEIVE_ALL_STOCKS, RECEIVE_A_STOCK } from "../actions/stock_actions";
4 |
5 | const stocksReducer = (state = {}, action) => {
6 | Object.freeze(state);
7 | switch (action.type) {
8 | case RECEIVE_ALL_STOCKS:
9 | return merge({}, state, action.stocks);
10 | case RECEIVE_A_STOCK:
11 | return merge({}, state, action.stock);
12 | default:
13 | return state;
14 | }
15 | };
16 |
17 | export default stocksReducer;
18 |
--------------------------------------------------------------------------------
/frontend/components/greeting/greeting_container.js:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import { logout } from "../../actions/session_actions";
3 | import Greeting from "./greeting";
4 |
5 | const mapStateToProps = ({ session, entities: { users } }, ownProps) => {
6 | return {
7 | currentUser: users[session.id]
8 | };
9 | };
10 |
11 | const mapDispatchToProps = dispatch => ({
12 | logout: () => dispatch(logout())
13 | });
14 |
15 | export default connect(
16 | mapStateToProps,
17 | mapDispatchToProps
18 | )(Greeting);
19 |
--------------------------------------------------------------------------------
/frontend/util/order_api_util.js:
--------------------------------------------------------------------------------
1 | export const createOrder = order => {
2 | return $.ajax({
3 | type: "POST",
4 | url: `api/users/${order.user_id}/orders`,
5 | data: { order }
6 | });
7 | };
8 |
9 | export const updateOrder = (userId, orderId) => {
10 | return $.ajax({
11 | type: "PATCH",
12 | url: `api/users/${userId}/orders/${orderId}`,
13 | data: {}
14 | });
15 | };
16 |
17 | export const fetchAllOrders = id => {
18 | return $.ajax({
19 | type: "GET",
20 | url: `api/users/${id}/orders`
21 | });
22 | };
23 |
--------------------------------------------------------------------------------
/test/fixtures/orders.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | type:
5 | num_share: 1
6 | user_id: MyString
7 | stock_id: MyString
8 | purchase_date: 2018-10-10
9 | purchase_price: 1.5
10 | total_return: 1.5
11 | today_return: 1.5
12 | equity: 1.5
13 |
14 | two:
15 | type:
16 | num_share: 1
17 | user_id: MyString
18 | stock_id: MyString
19 | purchase_date: 2018-10-10
20 | purchase_price: 1.5
21 | total_return: 1.5
22 | today_return: 1.5
23 | equity: 1.5
24 |
--------------------------------------------------------------------------------
/frontend/reducers/users_reducer.js:
--------------------------------------------------------------------------------
1 | import merge from "lodash/merge";
2 |
3 | import {
4 | RECEIVE_CURRENT_USER,
5 | LOGOUT_CURRENT_USER
6 | } from "../actions/session_actions";
7 |
8 | const usersReducer = (state = {}, action) => {
9 | Object.freeze(state);
10 | switch (action.type) {
11 | case RECEIVE_CURRENT_USER:
12 | return merge({}, state, { [action.currentUser.id]: action.currentUser });
13 | case LOGOUT_CURRENT_USER:
14 | return {};
15 | default:
16 | return state;
17 | }
18 | };
19 |
20 | export default usersReducer;
21 |
--------------------------------------------------------------------------------
/frontend/reducers/athletes_reducer.js:
--------------------------------------------------------------------------------
1 | import merge from "lodash/merge";
2 |
3 | import {
4 | RECEIVE_ALL_ATHLETES,
5 | RECEIVE_A_ATHLETE
6 | } from "../actions/athlete_actions";
7 |
8 | const athletesReducer = (state = {}, action) => {
9 | Object.freeze(state);
10 | switch (action.type) {
11 | case RECEIVE_ALL_ATHLETES:
12 | return merge({}, state, action.athletes);
13 | case RECEIVE_A_ATHLETE:
14 | return merge({}, state, action.athlete);
15 | default:
16 | return state;
17 | }
18 | };
19 |
20 | export default athletesReducer;
21 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12 | if spring
13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14 | gem 'spring', spring.version
15 | require 'spring/binstub'
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/frontend/reducers/entities_reducer.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from "redux";
2 | import usersReducer from "./users_reducer";
3 | import stocksReducer from "./stocks_reducer";
4 | import ordersReducer from "./orders_reducer";
5 | import athletesReducer from "./athletes_reducer";
6 | import watchlistItemsReducer from "./watchlist_reducer";
7 |
8 | const entitiesReducer = combineReducers({
9 | users: usersReducer,
10 | stocks: stocksReducer,
11 | orders: ordersReducer,
12 | athletes: athletesReducer,
13 | watchlistItems: watchlistItemsReducer
14 | });
15 |
16 | export default entitiesReducer;
17 |
--------------------------------------------------------------------------------
/frontend/util/watchlist_api_util.js:
--------------------------------------------------------------------------------
1 | export const fetchWatchlistItems = userId => {
2 | return $.ajax({
3 | url: `/api/users/${userId}/watchlist_items`,
4 | method: "GET"
5 | });
6 | };
7 |
8 | export const createWatchlistItem = (userId, item) => {
9 | return $.ajax({
10 | url: `/api/users/${userId}/watchlist_items`,
11 | method: "POST",
12 | data: { watchlist_item: item }
13 | });
14 | };
15 |
16 | export const deleteWatchlistItem = (userId, itemId) => {
17 | return $.ajax({
18 | url: `/api/users/${userId}/watchlist_items/${itemId}`,
19 | method: "DELETE"
20 | });
21 | };
22 |
--------------------------------------------------------------------------------
/frontend/components/athlete/tweets/tweets_index_item.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const TweetsIndexItem = ({ tweet }) => {
4 | return (
5 |
6 |
7 |
{tweet.tweetUsername}
8 |
9 |
{tweet.time_created}
10 |
11 |
12 |
13 |
{tweet.tweetBody}
14 |
15 |
16 | );
17 | };
18 |
19 | export default TweetsIndexItem;
20 |
--------------------------------------------------------------------------------
/frontend/components/home/home_chart/home_chart_container.js:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import HomeChart from "./home_chart";
5 |
6 | const mapStateToProps = (
7 | { session, entities: { athletes, users, orders, stocks } },
8 | ownProps
9 | ) => {
10 | return {
11 | currentUser: users[session.id],
12 | athletes: Object.values(athletes),
13 | orders: Object.values(orders),
14 | stocks: Object.values(stocks)
15 | };
16 | };
17 | export default connect(
18 | mapStateToProps,
19 | null
20 | )(HomeChart);
21 |
--------------------------------------------------------------------------------
/frontend/util/session_api_util.js:
--------------------------------------------------------------------------------
1 | export const login = user =>
2 | $.ajax({
3 | method: "POST",
4 | url: "/api/session",
5 | data: { user }
6 | });
7 |
8 | export const signup = user => {
9 | return $.ajax({
10 | method: "POST",
11 | url: "/api/users",
12 | data: { user }
13 | });
14 | };
15 |
16 | export const logout = () =>
17 | $.ajax({
18 | method: "DELETE",
19 | url: "/api/session"
20 | });
21 |
22 | export const updateUser = (userId, buyingPower) =>
23 | $.ajax({
24 | method: "PATCH",
25 | url: `/api/users/${userId}`,
26 | data: { user: { buying_power: buyingPower } }
27 | });
28 |
--------------------------------------------------------------------------------
/frontend/components/home/user_stocks/user_stocks_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import UsersStockIndex from "./user_stocks_index";
4 |
5 | const mSP = (
6 | { session, entities: { users, stocks, orders, athletes, watchlistItems } },
7 | ownProps
8 | ) => {
9 | return {
10 | stocks: Object.values(stocks),
11 | currentUser: users[session.id],
12 | orders: Object.values(orders),
13 | athletes: Object.values(athletes),
14 | watchlistItems: Object.values(watchlistItems)
15 | };
16 | };
17 |
18 | export default connect(
19 | mSP,
20 | null
21 | )(UsersStockIndex);
22 |
--------------------------------------------------------------------------------
/frontend/reducers/orders_reducer.js:
--------------------------------------------------------------------------------
1 | import merge from "lodash/merge";
2 |
3 | import { RECEIVE_ALL_ORDERS, RECEIVE_A_ORDER } from "../actions/order_actions";
4 | import { LOGOUT_CURRENT_USER } from "../actions/session_actions";
5 |
6 | const ordersReducer = (state = {}, action) => {
7 | Object.freeze(state);
8 | switch (action.type) {
9 | case RECEIVE_ALL_ORDERS:
10 | return merge({}, state, action.orders);
11 | case RECEIVE_A_ORDER:
12 | return merge({}, state, action.order);
13 | case LOGOUT_CURRENT_USER:
14 | return {};
15 | default:
16 | return state;
17 | }
18 | };
19 |
20 | export default ordersReducer;
21 |
--------------------------------------------------------------------------------
/app/controllers/api/sessions_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::SessionsController < ApplicationController
2 | def create
3 | @user = User.find_by_credentials(params[:user][:email], params[:user][:password])
4 | if @user
5 | login(@user)
6 | render "api/users/show"
7 | else
8 | render json: ["Unable to log in with provided credentials."], status: 401
9 | end
10 | end
11 |
12 | def destroy
13 | @user = current_user
14 | if @user
15 | logout
16 | render "api/users/show"
17 | else
18 | render json: ["Nobody signed in"], status: 404
19 | end
20 | end
21 | end
--------------------------------------------------------------------------------
/app/controllers/api/users_port_snapshots_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::UsersPortSnapshotsController < ApplicationController
2 |
3 | def create
4 | @user_port_snapshot = UserPortSnapshot.new(snapshot_params)
5 | if @user_port_snapshot.save
6 | render "api/users_port_snapshots/show"
7 | else
8 | render json: @user_port_snapshot.errors.full_messages, status: 422
9 | end
10 | end
11 |
12 | def index
13 | @snapshots = UserPortSnapshot.where(user_id: params[:user_id])
14 | end
15 |
16 |
17 |
18 | private
19 |
20 | def snapshot_params
21 | params.require(:snapshot).permit(:user_id, :port_value)
22 | end
23 | end
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path.
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 | # Add Yarn node_modules folder to the asset load path.
9 | Rails.application.config.assets.paths << Rails.root.join('node_modules')
10 |
11 | # Precompile additional assets.
12 | # application.js, application.css, and all non-JS/CSS in the app/assets
13 | # folder are already added.
14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css )
15 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 |
3 | module.exports = {
4 | context: __dirname,
5 | entry: "./frontend/trade_blitz.jsx",
6 | output: {
7 | path: path.resolve(__dirname, "app", "assets", "javascripts"),
8 | filename: "bundle.js"
9 | },
10 | resolve: {
11 | extensions: [".js", ".jsx", "*"]
12 | },
13 | module: {
14 | rules: [
15 | {
16 | test: /\.jsx?$/,
17 | exclude: /(node_modules)/,
18 | use: {
19 | loader: "babel-loader",
20 | options: {
21 | presets: ["@babel/preset-env", "@babel/preset-react"]
22 | }
23 | }
24 | }
25 | ]
26 | },
27 | devtool: "source-map"
28 | };
29 |
--------------------------------------------------------------------------------
/config/schedule.rb:
--------------------------------------------------------------------------------
1 | # Use this file to easily define all of your cron jobs.
2 | #
3 | # It's helpful, but not entirely necessary to understand cron before proceeding.
4 | # http://en.wikipedia.org/wiki/Cron
5 |
6 | # Example:
7 | #
8 | # set :output, "/path/to/my/cron_log.log"
9 | #
10 | # every 2.hours do
11 | # command "/usr/bin/some_great_command"
12 | # runner "MyModel.some_method"
13 | # rake "some:great:rake:task"
14 | # end
15 | #
16 | # every 4.days do
17 | # runner "AnotherModel.prune_old_records"
18 | # end
19 |
20 | # Learn more: http://github.com/javan/whenever
21 | # set :environment, "development"
22 | # set :output, 'log/whenever.log'
23 | # every 1.minute do
24 | # rake "stocks:updatePrice"
25 | # end
--------------------------------------------------------------------------------
/frontend/actions/athlete_actions.js:
--------------------------------------------------------------------------------
1 | import * as APIUtil from "../util/athlete_api_util";
2 |
3 | export const RECEIVE_ALL_ATHLETES = "RECEIVE_ALL_ATHLETES";
4 | export const RECEIVE_A_ATHLETE = "RECEIVE_A_ATHLETE";
5 |
6 | export const receiveAllAthletes = athletes => {
7 | return {
8 | type: RECEIVE_ALL_ATHLETES,
9 | athletes: athletes
10 | };
11 | };
12 |
13 | export const receiveAthlete = athlete => {
14 | return {
15 | type: RECEIVE_ALL_ATHLETES,
16 | athlete: athlete
17 | };
18 | };
19 |
20 | // thunk action creators
21 |
22 | export const fetchAllAthletes = () => dispatch => {
23 | return APIUtil.fetchAllAthletes().then(res =>
24 | dispatch(receiveAllAthletes(res))
25 | );
26 | };
27 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative 'boot'
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module TradeBlitz
10 | class Application < Rails::Application
11 | # Initialize configuration defaults for originally generated Rails version.
12 | config.load_defaults 5.2
13 |
14 | # Settings in config/environments/* take precedence over those specified here.
15 | # Application configuration can go into files in config/initializers
16 | # -- all .rb files in that directory are automatically loaded after loading
17 | # the framework and any gems in your application.
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/frontend/components/home/news_articles/news_articles_index.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import NewsArticlesIndexItem from "./news_articles_index_item";
3 |
4 | class NewsArticlesIndex extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | }
8 |
9 | componentDidMount() {}
10 |
11 | render() {
12 | return (
13 |
14 |
Recent News
15 |
16 | {this.props.articles.map(article => {
17 | return (
18 |
19 | );
20 | })}
21 |
22 | );
23 | }
24 | }
25 |
26 | export default NewsArticlesIndex;
27 |
--------------------------------------------------------------------------------
/frontend/actions/stock_actions.js:
--------------------------------------------------------------------------------
1 | import * as APIUtil from "../util/stock_api_util";
2 |
3 | export const RECEIVE_ALL_STOCKS = "RECEIVE_ALL_STOCKS";
4 | export const RECEIVE_A_STOCK = "RECEIVE_A_STOCK";
5 |
6 | export const receiveAllStocks = stocks => {
7 | return {
8 | type: RECEIVE_ALL_STOCKS,
9 | stocks: stocks
10 | };
11 | };
12 |
13 | export const receiveAStock = stock => {
14 | return {
15 | type: RECEIVE_A_STOCK,
16 | stock: stock
17 | };
18 | };
19 |
20 | // thunk action creators
21 |
22 | export const fetchStocks = () => dispatch => {
23 | return APIUtil.fetchStocks().then(res => dispatch(receiveAllStocks(res)));
24 | };
25 |
26 | export const fetchStock = id => dispatch => {
27 | return APIUtil.fetchStock(id).then(stock => dispatch(receiveAStock(stock)));
28 | };
29 |
--------------------------------------------------------------------------------
/frontend/trade_blitz.jsx:
--------------------------------------------------------------------------------
1 | import Root from "./components/root";
2 | import ReactDOM from "react-dom";
3 | import configureStore from "./store/store";
4 | import React from "react";
5 |
6 | document.addEventListener("DOMContentLoaded", () => {
7 | const root = document.getElementById("root");
8 | let store;
9 |
10 | if (window.currentUser) {
11 | const preloadedState = {
12 | entities: {
13 | users: { [window.currentUser.id]: window.currentUser }
14 | },
15 | session: { id: window.currentUser.id }
16 | };
17 | store = configureStore(preloadedState);
18 | delete window.currentUser;
19 | } else {
20 | store = configureStore();
21 | }
22 |
23 | window.store = store;
24 | // Testing
25 |
26 | ReactDOM.render(, root);
27 | });
28 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 |
3 | root "static_pages#root"
4 |
5 | namespace :api, defaults: {format: :json} do
6 | resources :users, only: [:create, :update, :index] do
7 | resources :orders, only: [:create, :index, :show, :update]
8 | resources :athletes, only: [:show]
9 | resources :users_port_snapshots, only: [:index, :create]
10 | resources :watchlist_items, only: [:index, :create, :destroy]
11 | end
12 | resource :session, only: [:create, :destroy, :show]
13 | resources :stocks, only: [:index, :show]
14 | resources :athletes, only: [:show, :index] do
15 | resources :tweets, only: [:index]
16 | resources :tweet_score_snapshots, only: [:index]
17 | resources :athlete_price_snapshots, only: [:index]
18 |
19 | end
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
5 | // vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file. JavaScript code in this file should be added after the last require_* statement.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require rails-ujs
14 | //= require activestorage
15 | //= require jquery
16 | //= require jquery_ujs
17 | //= require_tree .
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore all logfiles and tempfiles.
11 | /log/*
12 | /tmp/*
13 | !/log/.keep
14 | !/tmp/.keep
15 |
16 | # Ignore uploaded files in development
17 | /storage/*
18 | !/storage/.keep
19 |
20 | node_modules/
21 | /node_modules
22 | /yarn-error.log
23 | bundle.js
24 | bundle.js.map
25 | .byebug_history
26 | .DS_Store
27 | npm-debug.log
28 |
29 | /public/assets
30 | .byebug_history
31 |
32 | # Ignore master key for decrypting credentials and more.
33 | /config/master.key
34 |
--------------------------------------------------------------------------------
/frontend/actions/order_actions.js:
--------------------------------------------------------------------------------
1 | import * as APIUtil from "../util/order_api_util";
2 |
3 | export const RECEIVE_ALL_ORDERS = "RECEIVE_ALL_ORDERS";
4 | export const RECEIVE_A_ORDER = "RECEIVE_A_ORDER";
5 |
6 | export const receiveAllOrders = orders => {
7 | return {
8 | type: RECEIVE_ALL_ORDERS,
9 | orders: orders
10 | };
11 | };
12 |
13 | export const receiveOrder = order => {
14 | return {
15 | type: RECEIVE_A_ORDER,
16 | order: order
17 | };
18 | };
19 |
20 | // thunk action creators
21 |
22 | export const fetchAllOrders = id => dispatch => {
23 | return APIUtil.fetchAllOrders(id).then(res =>
24 | dispatch(receiveAllOrders(res))
25 | );
26 | };
27 |
28 | export const createOrder = order => dispatch => {
29 | return APIUtil.createOrder(order).then(res => {
30 | dispatch(receiveOrder(res));
31 | });
32 | };
33 |
--------------------------------------------------------------------------------
/app/controllers/api/users_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::UsersController < ApplicationController
2 | def create
3 | @user = User.new(user_params)
4 |
5 | if @user.save
6 | login(@user)
7 | render "api/users/show"
8 | else
9 | render json: @user.errors.full_messages, status: 422
10 | end
11 | end
12 |
13 | def update
14 |
15 | @user = User.find(params[:id])
16 | if @user.update_attributes(user_params)
17 | render "api/users/show"
18 | else
19 | render ["Error updating user"]
20 | end
21 | end
22 |
23 | def index
24 | @users = User.all
25 | end
26 |
27 | private
28 |
29 | def user_params
30 | params.require(:user).permit(:email, :password, :first_name, :last_name, :buying_power)
31 | end
32 | end
--------------------------------------------------------------------------------
/frontend/components/session_form/login_form_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import { login, receiveErrors } from "../../actions/session_actions";
5 | import LoginForm from "./login_form";
6 |
7 | const mapStateToProps = ({ errors }) => {
8 | return {
9 | errors: errors.session,
10 | formType: "login",
11 | navLink: (
12 |
13 | Don't have an account?
14 |
15 | )
16 | };
17 | };
18 |
19 | const mapDispatchToProps = dispatch => {
20 | return {
21 | processForm: user => dispatch(login(user)),
22 | receiveErrors: errors => dispatch(receiveErrors(errors))
23 | };
24 | };
25 |
26 | export default connect(
27 | mapStateToProps,
28 | mapDispatchToProps
29 | )(LoginForm);
30 |
--------------------------------------------------------------------------------
/frontend/components/free_stock/free_stock_container.js:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import FreeStock from "./free_stock";
5 | import { fetchStocks } from "../../actions/stock_actions";
6 | import { createOrder } from "../../actions/order_actions";
7 | import { removeFirstUser } from "../../actions/session_actions";
8 |
9 | const mSP = ({ session, entities: { user, stocks } }, ownProps) => {
10 | return {
11 | stocks: Object.values(stocks)
12 | };
13 | };
14 |
15 | const mDP = dispatch => ({
16 | logout: () => dispatch(logout()),
17 | fetchStocks: () => dispatch(fetchStocks()),
18 | createOrder: order => dispatch(createOrder(order)),
19 | removeFirstUser: () => dispatch(removeFirstUser())
20 | });
21 |
22 | export default connect(
23 | mSP,
24 | mDP
25 | )(FreeStock);
26 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | helper_method :current_user, :logged_in?
3 |
4 | private
5 |
6 | def current_user
7 | return nil unless session[:session_token]
8 | @current_user ||= User.find_by(session_token: session[:session_token])
9 | end
10 |
11 | def logged_in?
12 | !!current_user
13 | end
14 |
15 | def login(user)
16 | session[:session_token] = user.reset_session_token!
17 | @current_user = user
18 | end
19 |
20 | def logout
21 | current_user.reset_session_token!
22 | session[:session_token] = nil
23 | @current_user = nil
24 | end
25 |
26 | def require_logged_in
27 | unless current_user
28 | render json: {base: ['Invalid credentials']}, status: 401
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/app/controllers/api/watchlist_items_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::WatchlistItemsController < ApplicationController
2 |
3 | def index
4 | @watchlist_items = WatchlistItem.where(user_id: params[:user_id])
5 | end
6 |
7 | def create
8 | @item = WatchlistItem.new(watchlist_item_params)
9 | if @item.save
10 | render "api/watchlist_items/show"
11 | else
12 | render ["Error creating watchlist item"]
13 | end
14 | end
15 |
16 | def destroy
17 | @item = WatchlistItem.find(params[:id])
18 | if @item.delete
19 | render "api/watchlist_items/show"
20 | else
21 | render ["Problem deleting watchlist item"]
22 | end
23 | end
24 |
25 | private
26 |
27 | def watchlist_item_params
28 | params.require(:watchlist_item).permit(:user_id, :stock_id)
29 | end
30 |
31 | end
--------------------------------------------------------------------------------
/frontend/components/home/buy_sell/buy_sell_container.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import BuySell from "./buy_sell";
3 | import { connect } from "react-redux";
4 | import { createOrder, fetchAllOrders } from "./../../../actions/order_actions";
5 | import { receiveCurrentUser } from "./../../../actions/session_actions";
6 |
7 | const mSP = (props, ownProps) => {
8 | return {
9 | stocks: Object.values(ownProps.stocks),
10 | currentUser: ownProps.currentUser,
11 | orders: Object.values(ownProps.orders),
12 | athleteId: ownProps.athleteId
13 | };
14 | };
15 |
16 | const mapDispatchToProps = dispatch => ({
17 | createOrder: order => dispatch(createOrder(order)),
18 | fetchAllOrders: () => dispatch(fetchAllOrders()),
19 | receiveCurrentUser: user => dispatch(receiveCurrentUser(user))
20 | });
21 |
22 | export default connect(
23 | mSP,
24 | mapDispatchToProps
25 | )(BuySell);
26 |
--------------------------------------------------------------------------------
/frontend/components/home/news_articles/news_articles_index_item.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const NewsArticlesIndexItem = ({ article }) => {
4 | return (
5 | (window.location.href = article.url)}
7 | className="news-article-item-section"
8 | >
9 |

10 |
11 |
{article.title}
12 |
{article.description}
13 |
14 |
15 |
{article.source.name}
16 | {article.publishedAt}
17 |
18 |
19 | );
20 | };
21 |
22 | export default NewsArticlesIndexItem;
23 |
--------------------------------------------------------------------------------
/frontend/reducers/session_reducer.js:
--------------------------------------------------------------------------------
1 | import {
2 | RECEIVE_CURRENT_USER,
3 | LOGOUT_CURRENT_USER,
4 | REMOVE_FIRST_USER,
5 | RECEIVE_FIRST_USER
6 | } from "../actions/session_actions";
7 | import merge from "lodash/merge";
8 |
9 | const _nullUser = Object.freeze({
10 | id: null,
11 | firstTime: false
12 | });
13 |
14 | const sessionReducer = (state = _nullUser, action) => {
15 | Object.freeze(state);
16 | switch (action.type) {
17 | case RECEIVE_CURRENT_USER:
18 | return merge({}, state, { id: action.currentUser.id });
19 | case LOGOUT_CURRENT_USER:
20 | return merge({}, state, _nullUser);
21 | case REMOVE_FIRST_USER:
22 | return merge({}, state, { firstTime: false });
23 | case RECEIVE_FIRST_USER:
24 | return merge({}, state, { firstTime: true });
25 | default:
26 | return state;
27 | }
28 | };
29 |
30 | export default sessionReducer;
31 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
6 | * vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10 | * files in this directory. Styles in this file should be added after the last require_* statement.
11 | * It is generally better to create a new file per style scope.
12 | *= require_tree .
13 | *= require_self
14 | */
15 |
16 | /* @import "reset.css";
17 | @import "animate.css";
18 | @import "greeting.css";
19 | @import "login.css";
20 | @import "signup.css"; */
21 |
--------------------------------------------------------------------------------
/frontend/util/route_util.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { connect } from "react-redux";
3 | import { Route, Redirect, withRouter } from "react-router-dom";
4 |
5 | const Auth = ({ component: Component, path, loggedIn, exact }) => (
6 |
10 | !loggedIn ? :
11 | }
12 | />
13 | );
14 |
15 | const Protected = ({ component: Component, path, loggedIn, exact }) => (
16 |
20 | loggedIn ? :
21 | }
22 | />
23 | );
24 |
25 | const mapStateToProps = state => ({ loggedIn: Boolean(state.session.id) });
26 |
27 | export const AuthRoute = withRouter(connect(mapStateToProps)(Auth));
28 |
29 | export const ProtectedRoute = withRouter(connect(mapStateToProps)(Protected));
30 |
--------------------------------------------------------------------------------
/frontend/reducers/watchlist_reducer.js:
--------------------------------------------------------------------------------
1 | import merge from "lodash/merge";
2 |
3 | import {
4 | RECEIVE_WATCHLIST_ITEM,
5 | RECEIVE_ALL_WATCHLIST_ITEMS,
6 | REMOVE_WATCHLIST_ITEM
7 | } from "./../actions/watchlist_actions";
8 | import { LOGOUT_CURRENT_USER } from "../actions/session_actions";
9 |
10 | const watchlistItemsReducer = (state = {}, action) => {
11 | Object.freeze(state);
12 | switch (action.type) {
13 | case LOGOUT_CURRENT_USER:
14 | return {};
15 | case RECEIVE_ALL_WATCHLIST_ITEMS:
16 | return merge({}, state, action.items);
17 | case RECEIVE_WATCHLIST_ITEM:
18 | return merge({}, state, action.item);
19 | case REMOVE_WATCHLIST_ITEM:
20 | let newState = Object.assign({}, state);
21 | delete newState[Object.values(action.item)[0].id];
22 |
23 | return newState;
24 | default:
25 | return state;
26 | }
27 | };
28 |
29 | export default watchlistItemsReducer;
30 |
--------------------------------------------------------------------------------
/bin/update:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'fileutils'
3 | include FileUtils
4 |
5 | # path to your application root.
6 | APP_ROOT = File.expand_path('..', __dir__)
7 |
8 | def system!(*args)
9 | system(*args) || abort("\n== Command #{args} failed ==")
10 | end
11 |
12 | chdir APP_ROOT do
13 | # This script is a way to update your development environment automatically.
14 | # Add necessary update steps to this file.
15 |
16 | puts '== Installing dependencies =='
17 | system! 'gem install bundler --conservative'
18 | system('bundle check') || system!('bundle install')
19 |
20 | # Install JavaScript dependencies if using Yarn
21 | # system('bin/yarn')
22 |
23 | puts "\n== Updating database =="
24 | system! 'bin/rails db:migrate'
25 |
26 | puts "\n== Removing old logs and tempfiles =="
27 | system! 'bin/rails log:clear tmp:clear'
28 |
29 | puts "\n== Restarting application server =="
30 | system! 'bin/rails restart'
31 | end
32 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/home_chart.css:
--------------------------------------------------------------------------------
1 | .home-chart-view {
2 | float: left;
3 | width: 676px;
4 | margin-top: 70px;
5 | margin-left: 30px;
6 | text-align: left;
7 | display: block;
8 | height: 350px;
9 | }
10 |
11 | .home-port-value {
12 | font-family: "Roboto", sans-serif;
13 | font-size: 35px;
14 | margin-left: 60px;
15 | font-weight: 100;
16 | margin-bottom: 10px;
17 | }
18 |
19 | .home-daily-gain {
20 | font-family: "Roboto", sans-serif;
21 | font-size: 13px;
22 | margin-left: 65px;
23 | font-weight: 100;
24 | margin-top: 0px;
25 | }
26 |
27 | .top-movers-section {
28 | display: block;
29 | margin-top: 60vh;
30 | font-family: "Roboto", sans-serif;
31 | font-weight: 100;
32 | font-size: 21px;
33 | float: left;
34 | text-align: left;
35 | position: absolute;
36 | left: 100px;
37 | }
38 |
39 | .home-chart-container {
40 | height: 80%;
41 | }
42 |
43 | .chartjs-render-monitor {
44 | margin-left: 50px;
45 | height: 275px;
46 | }
47 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # 'true': 'foo'
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at http://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/frontend/components/session_form/signup_form_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import {
5 | signup,
6 | receiveErrors,
7 | receiveFirstUser
8 | } from "../../actions/session_actions";
9 | import SessionForm from "./session_form";
10 | import SignUpForm from "./signup_form";
11 |
12 | const mapStateToProps = ({ errors }) => {
13 | return {
14 | errors: errors.session,
15 | formType: "signup",
16 | navLink: (
17 |
18 | Try the demo
19 |
20 | )
21 | };
22 | };
23 |
24 | const mapDispatchToProps = dispatch => {
25 | return {
26 | processForm: user => dispatch(signup(user)),
27 | receiveErrors: errors => dispatch(receiveErrors(errors)),
28 | receiveFirstUser: () => dispatch(receiveFirstUser())
29 | };
30 | };
31 |
32 | export default connect(
33 | mapStateToProps,
34 | mapDispatchToProps
35 | )(SignUpForm);
36 |
--------------------------------------------------------------------------------
/frontend/components/home/top_movers/top_movers_container.js:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import TopMoversIndex from "./top_movers_index";
5 | import { fetchAllAthletes } from "./../../../actions/athlete_actions";
6 | import { fetchStocks } from "../../../actions/stock_actions";
7 | import { logout } from "../../../actions/session_actions";
8 |
9 | const mapStateToProps = (
10 | { session, entities: { athletes, users, orders, stocks } },
11 | ownProps
12 | ) => {
13 | return {
14 | currentUser: users[session.id],
15 | athletes: Object.values(athletes),
16 | orders: Object.values(orders),
17 | stocks: Object.values(stocks)
18 | };
19 | };
20 |
21 | const mDP = dispatch => ({
22 | fetchAllAthletes: () => dispatch(fetchAllAthletes()),
23 | logout: () => dispatch(logout()),
24 | fetchStocks: () => dispatch(fetchStocks())
25 | });
26 |
27 | export default connect(
28 | mapStateToProps,
29 | mDP
30 | )(TopMoversIndex);
31 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/not_found.css:
--------------------------------------------------------------------------------
1 | .doge-picture {
2 | max-height: 300px;
3 | position: absolute;
4 | bottom: 0;
5 | }
6 |
7 | .not-found-visual {
8 | margin-right: 150px;
9 | }
10 |
11 | .not-found-subtitle {
12 | font-family: "Open Sans", sans-serif;
13 | font-weight: lighter;
14 | font-size: 31px;
15 | }
16 |
17 | .not-found-error-text {
18 | font-family: "Open Sans", sans-serif;
19 | font-weight: 900;
20 | font-size: 36px;
21 | }
22 |
23 | .not-found-button {
24 | width: 120px;
25 | height: 48px;
26 | color: white;
27 | background-color: #21ce99;
28 | font-family: "Noto Sans", sans-serif;
29 | border-radius: 7px;
30 | font-size: 15px;
31 | border: none;
32 | }
33 |
34 | .not-found-button:hover {
35 | background-color: #1ae9aa;
36 | }
37 |
38 | .not-found-description {
39 | font-family: "Open Sans", sans-serif;
40 | font-size: 18px;
41 | font-weight: lighter;
42 | }
43 |
44 | .not-found-section {
45 | display: flex;
46 | justify-content: space-evenly;
47 | overflow: hidden;
48 | }
49 |
50 | .not-found-content {
51 | margin-top: 100px;
52 | }
53 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'fileutils'
3 | include FileUtils
4 |
5 | # path to your application root.
6 | APP_ROOT = File.expand_path('..', __dir__)
7 |
8 | def system!(*args)
9 | system(*args) || abort("\n== Command #{args} failed ==")
10 | end
11 |
12 | chdir APP_ROOT do
13 | # This script is a starting point to setup your application.
14 | # Add necessary setup steps to this file.
15 |
16 | puts '== Installing dependencies =='
17 | system! 'gem install bundler --conservative'
18 | system('bundle check') || system!('bundle install')
19 |
20 | # Install JavaScript dependencies if using Yarn
21 | # system('bin/yarn')
22 |
23 | # puts "\n== Copying sample files =="
24 | # unless File.exist?('config/database.yml')
25 | # cp 'config/database.yml.sample', 'config/database.yml'
26 | # end
27 |
28 | puts "\n== Preparing database =="
29 | system! 'bin/rails db:setup'
30 |
31 | puts "\n== Removing old logs and tempfiles =="
32 | system! 'bin/rails log:clear tmp:clear'
33 |
34 | puts "\n== Restarting application server =="
35 | system! 'bin/rails restart'
36 | end
37 |
--------------------------------------------------------------------------------
/app/models/user.rb:
--------------------------------------------------------------------------------
1 | class User < ApplicationRecord
2 | attr_reader :password
3 |
4 | validates :email, :password_digest, :session_token, :first_name, :last_name, presence: true
5 | validates :email, uniqueness: true
6 | validates :password, length: {minimum: 6}, allow_nil: true
7 |
8 | after_initialize :ensure_session_token
9 |
10 | has_many :orders
11 |
12 | def self.find_by_credentials(email, password)
13 | user = User.find_by(email: email)
14 | return nil unless user
15 | user.is_password?(password) ? user : nil
16 | end
17 |
18 | def password=(pw)
19 | @password = pw
20 | self.password_digest = BCrypt::Password.create(password)
21 | end
22 |
23 | def is_password?(pw)
24 | BCrypt::Password.new(self.password_digest).is_password?(pw)
25 | end
26 |
27 | def reset_session_token!
28 | self.session_token = SecureRandom.urlsafe_base64
29 | self.save!
30 | self.session_token
31 | end
32 |
33 | def ensure_session_token
34 | self.session_token ||= SecureRandom.urlsafe_base64
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/db/migrate/20181011054839_create_athletes.rb:
--------------------------------------------------------------------------------
1 | class CreateAthletes < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :athletes do |t|
4 | t.string :name, null: false, unique: true
5 | t.string :team_acronym
6 | t.string :team_name
7 | t.integer :games_played
8 | t.float :minutes_per_game
9 | t.float :field_goals_attempted_per_game
10 | t.float :field_goals_made_per_game
11 | t.float :field_goal_percentage
12 | t.float :free_throw_percentage
13 | t.float :three_point_attempted_per_game
14 | t.float :three_point_made_per_game
15 | t.float :three_point_percentage
16 | t.float :points_per_game
17 | t.float :offensive_rebounds_per_game
18 | t.float :defensive_rebounds_per_game
19 | t.float :rebounds_per_game
20 | t.float :assists_per_game
21 | t.float :steals_per_game
22 | t.float :blocks_per_game
23 | t.float :turnovers_per_game
24 | t.float :player_efficiency_rating
25 | t.float :twitter_sentiment
26 | t.string :image_url
27 |
28 | t.timestamps
29 | end
30 | add_index(:athletes,:name)
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/frontend/components/home/top_movers/top_movers_index_item.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { withRouter } from "react-router-dom";
3 |
4 | const TopMoversIndexItem = ({ athlete, price, history }) => {
5 | const athleteDetail = () => (
6 |
7 |
{athlete.name}
8 | {athlete.team_acronym.toUpperCase()}
9 | ${price.toFixed(2)}
10 |
11 | );
12 |
13 | const loader = () => (
14 |
15 |
16 |
17 | );
18 | const athleteImg = () => (
19 |
20 |

21 |
22 | );
23 | return (
24 | history.push(`/athletes/${athlete.id}`)}
26 | className="top-movers-item"
27 | >
28 | {athlete ? athleteDetail() : loader()}
29 | {athlete ? athleteImg() : loader()}
30 |
31 | );
32 | };
33 |
34 | export default withRouter(TopMoversIndexItem);
35 |
--------------------------------------------------------------------------------
/config/initializers/content_security_policy.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Define an application-wide content security policy
4 | # For further information see the following documentation
5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
6 |
7 | # Rails.application.config.content_security_policy do |policy|
8 | # policy.default_src :self, :https
9 | # policy.font_src :self, :https, :data
10 | # policy.img_src :self, :https, :data
11 | # policy.object_src :none
12 | # policy.script_src :self, :https
13 | # policy.style_src :self, :https
14 |
15 | # # Specify URI for violation reports
16 | # # policy.report_uri "/csp-violation-report-endpoint"
17 | # end
18 |
19 | # If you are using UJS then enable automatic nonce generation
20 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
21 |
22 | # Report CSP violations to a specified URI
23 | # For further information see the following documentation:
24 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
25 | # Rails.application.config.content_security_policy_report_only = true
26 |
--------------------------------------------------------------------------------
/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10 | # amazon:
11 | # service: S3
12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14 | # region: us-east-1
15 | # bucket: your_own_bucket
16 |
17 | # Remember not to checkin your GCS keyfile to a repository
18 | # google:
19 | # service: GCS
20 | # project: your_project
21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22 | # bucket: your_own_bucket
23 |
24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25 | # microsoft:
26 | # service: AzureStorage
27 | # storage_account_name: your_account_name
28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29 | # container: your_container_name
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/reset.css:
--------------------------------------------------------------------------------
1 | /* CSS reset
2 |
3 | html, body, div, span, applet, object, iframe,
4 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
5 | a, abbr, acronym, address, big, cite, code,
6 | del, dfn, em, img, ins, kbd, q, s, samp,
7 | small, strike, strong, sub, sup, tt, var,
8 | b, u, i, center,
9 | dl, dt, dd, ol, ul, li,
10 | fieldset, form, label, legend,
11 | table, caption, tbody, tfoot, thead, tr, th, td,
12 | article, aside, canvas, details, embed,
13 | figure, figcaption, footer, header, hgroup,
14 | menu, nav, output, ruby, section, summary,
15 | time, mark, audio, video {
16 | margin: 0;
17 | padding: 0;
18 | border: 0;
19 | font-size: 100%;
20 | font: inherit;
21 | vertical-align: baseline;
22 | }
23 | /* HTML5 display-role reset for older browsers */
24 |
25 | details,
26 | figcaption,
27 | figure,
28 | footer,
29 | header,
30 | hgroup,
31 | menu,
32 | nav,
33 | section {
34 | display: block;
35 | }
36 | body {
37 | line-height: 1;
38 | }
39 | ol,
40 | ul {
41 | list-style: none;
42 | }
43 | blockquote,
44 | q {
45 | quotes: none;
46 | }
47 | blockquote:before,
48 | blockquote:after,
49 | q:before,
50 | q:after {
51 | content: "";
52 | content: none;
53 | }
54 | table {
55 | border-collapse: collapse;
56 | border-spacing: 0;
57 | }
58 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/top_movers.css:
--------------------------------------------------------------------------------
1 | .top-movers-item {
2 | width: 210px;
3 | height: 140px;
4 | display: inline-block;
5 | position: relative;
6 | margin-right: 15px;
7 | padding-left: 10px;
8 | border-radius: 4px;
9 | border: 1px solid #e4e4e4;
10 | }
11 |
12 | .top-movers-img {
13 | max-height: 105px;
14 | float: right;
15 | position: absolute;
16 | bottom: 0px;
17 | right: 0px;
18 | }
19 |
20 | .top-movers-item:hover {
21 | background-color: #f5f5f5;
22 | box-shadow: -1px 4px 18px #c4c4c4;
23 | cursor: pointer;
24 | }
25 |
26 | .top-movers-detail {
27 | float: left;
28 | }
29 |
30 | .top-movers-section {
31 | overflow-x: scroll;
32 | overflow-y: hidden;
33 | width: 55%;
34 | white-space: nowrap;
35 | -ms-overflow-style: none;
36 | }
37 |
38 | .top-movers-section::-webkit-scrollbar {
39 | height: 0 !important;
40 | }
41 |
42 | .top-movers-name {
43 | font-size: 17px;
44 | margin-bottom: 1px;
45 | }
46 |
47 | .top-movers-team {
48 | font-size: 22px;
49 | margin-top: 1px;
50 | margin-bottom: 50px;
51 | }
52 |
53 | .top-movers-price {
54 | font-size: 20px;
55 | }
56 |
57 | .top-movers-header {
58 | font-family: "Noto Sans", sans-serif;
59 | font-size: 25px;
60 | }
61 |
62 | .top-movers-item {
63 | font-family: "Noto Sans", sans-serif;
64 | }
65 |
--------------------------------------------------------------------------------
/frontend/components/athlete/athlete_fg_percentage.jsx:
--------------------------------------------------------------------------------
1 | import { PieChart, Pie, Sector, Cell } from "recharts";
2 |
3 | import React from "react";
4 |
5 | const AthleteFGPercentage = ({ fg_percentage, athletes }) => {
6 | const data = [
7 | { name: "Group A", value: 400 },
8 | { name: "Group B", value: 300 },
9 | { name: "Group C", value: 300 },
10 | { name: "Group D", value: 200 }
11 | ];
12 | const COLORS = ["#21ce99", "#1ae9aa"];
13 | const RADIAN = Math.PI / 180;
14 | const radialChart = () => (
15 |
16 |
25 | {data.map((entry, index) => (
26 | |
27 | ))}
28 |
29 |
30 | );
31 |
32 | const loader = () => (
33 |
34 |
35 |
36 | );
37 |
38 | return (
39 |
40 | {Object.values(athletes).length > 0 ? radialChart() : loader()}
41 |
42 | );
43 | };
44 |
45 | export default AthleteFGPercentage;
46 |
--------------------------------------------------------------------------------
/frontend/components/home/user_stocks/user_stocks_item.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Link, withRouter } from "react-router-dom";
3 |
4 | const UserStocksItem = ({ athlete, stock, history }) => {
5 | const athleteName = () => (
6 |
7 |
{athlete.name}
8 | {athlete.team_name}
9 |
10 | );
11 |
12 | const athleteImage = () => (
13 |
14 | );
15 |
16 | const loader = () => (
17 |
18 |
19 |
20 | );
21 |
22 | const itemPrice = () => (
23 |
24 | ${stock.current_price.toFixed(2)}
25 |
26 | );
27 | return (
28 | history.push(`/athletes/${athlete.id}`)}
30 | className="order-index-item"
31 | >
32 | {Object.values(athlete).length > 0 ? athleteImage() : loader()}
33 | {Object.values(athlete).length > 0 ? athleteName() : null}
34 |
35 | {Object.values(athlete).length > 0 ? itemPrice() : null}
36 |
37 | );
38 | };
39 |
40 | export default withRouter(UserStocksItem);
41 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/tweet.css:
--------------------------------------------------------------------------------
1 | .tweet-content-view {
2 | width: 250px;
3 | height: 300px;
4 | display: inline-block;
5 | position: relative;
6 | margin-right: 15px;
7 | border-radius: 2px;
8 | background-color: white;
9 | box-shadow: -1px 4px 18px #c4c4c4;
10 | margin-left: 20px;
11 | overflow: scroll;
12 | height: 200px;
13 | }
14 |
15 | .tweet-body-section {
16 | word-break: normal;
17 | padding: 15px;
18 | overflow-y: hidden;
19 | }
20 |
21 | .athlete-tweets-container {
22 | overflow-x: scroll;
23 | overflow-y: hidden;
24 | white-space: nowrap;
25 | -ms-overflow-style: none;
26 | height: 400px;
27 | margin-left: 115px;
28 | }
29 |
30 | .tweet-body-section p {
31 | word-break: break-all;
32 | white-space: normal;
33 | margin-top: 0;
34 | font-family: "Noto Sans", sans-serif;
35 | font-size: 12px;
36 | }
37 |
38 | .tweet-username {
39 | font-family: "Noto Sans", sans-serif;
40 | font-size: 13px;
41 | }
42 |
43 | .tweet-timestamp {
44 | font-family: "Noto Sans", sans-serif;
45 | font-size: 11px;
46 | margin-left: 11px;
47 | margin-right: 15px;
48 | }
49 |
50 | .tweet-header {
51 | margin-top: 15px;
52 | display: flex;
53 | justify-content: space-between;
54 | margin-left: 15px;
55 | }
56 |
57 | .tweet-break-line {
58 | width: 247px;
59 | border: none;
60 | height: 1px;
61 | background: #f2f2f2;
62 | }
63 |
--------------------------------------------------------------------------------
/frontend/actions/watchlist_actions.js:
--------------------------------------------------------------------------------
1 | import * as APIUtil from "../util/watchlist_api_util";
2 |
3 | export const RECEIVE_WATCHLIST_ITEM = "RECEIVE_WATCHLIST_ITEM";
4 | export const RECEIVE_ALL_WATCHLIST_ITEMS = "RECEIVE_ALL_WATCHLIST_ITEMS";
5 | export const REMOVE_WATCHLIST_ITEM = "REMOVE_WATCHLIST_ITEM";
6 |
7 | export const receiveAllWatchlistItems = items => {
8 | return {
9 | type: RECEIVE_ALL_WATCHLIST_ITEMS,
10 | items: items
11 | };
12 | };
13 |
14 | export const receiveWatchlistItem = item => {
15 | return {
16 | type: RECEIVE_WATCHLIST_ITEM,
17 | item: item
18 | };
19 | };
20 |
21 | export const removeWatchlistItem = item => {
22 | return {
23 | type: REMOVE_WATCHLIST_ITEM,
24 | item: item
25 | };
26 | };
27 |
28 | // thunk action creators
29 |
30 | export const addWatchlistItem = (userId, item) => dispatch => {
31 | return APIUtil.createWatchlistItem(userId, item).then(res =>
32 | dispatch(receiveWatchlistItem(res))
33 | );
34 | };
35 |
36 | export const deleteWatchlistItem = (userId, itemId) => dispatch => {
37 | return APIUtil.deleteWatchlistItem(userId, itemId).then(res =>
38 | dispatch(removeWatchlistItem(res))
39 | );
40 | };
41 |
42 | export const fetchAllWatchlistItems = userId => dispatch => {
43 | return APIUtil.fetchWatchlistItems(userId).then(res =>
44 | dispatch(receiveAllWatchlistItems(res))
45 | );
46 | };
47 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers: a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum; this matches the default thread size of Active Record.
6 | #
7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8 | threads threads_count, threads_count
9 |
10 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
11 | #
12 | port ENV.fetch("PORT") { 3000 }
13 |
14 | # Specifies the `environment` that Puma will run in.
15 | #
16 | environment ENV.fetch("RAILS_ENV") { "development" }
17 |
18 | # Specifies the number of `workers` to boot in clustered mode.
19 | # Workers are forked webserver processes. If using threads and workers together
20 | # the concurrency of the application would be max `threads` * `workers`.
21 | # Workers do not work on JRuby or Windows (both of which do not support
22 | # processes).
23 | #
24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25 |
26 | # Use the `preload_app!` method when specifying a `workers` number.
27 | # This directive tells Puma to first boot the application and load code
28 | # before forking the application. This takes advantage of Copy On Write
29 | # process behavior so workers use less memory.
30 | #
31 | # preload_app!
32 |
33 | # Allow puma to be restarted by `rails restart` command.
34 | plugin :tmp_restart
35 |
--------------------------------------------------------------------------------
/test/fixtures/athletes.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | name: MyString
5 | team_acronym: MyString
6 | team_name: MyString
7 | games_played: 1
8 | minutes_per_game: 1.5
9 | field_goals_attempted_per_game: 1.5
10 | field_goals_made_per_game: 1.5
11 | field_goal_percentage: 1.5
12 | free_throw_percentage: 1.5
13 | three_point_attempted_per_game: 1.5
14 | three_point_made_per_game: 1.5
15 | three_point_percentage: 1.5
16 | points_per_game: 1.5
17 | offensive_rebounds_per_game: 1.5
18 | defensive_rebounds_per_game: 1.5
19 | rebounds_per_game: 1.5
20 | assists_per_game: 1.5
21 | steals_per_game: 1.5
22 | blocks_per_game: 1.5
23 | turnovers_per_game: 1.5
24 | player_efficiency_rating: 1.5
25 | twitter_sentiment: 1.5
26 | image_url: MyString
27 |
28 | two:
29 | name: MyString
30 | team_acronym: MyString
31 | team_name: MyString
32 | games_played: 1
33 | minutes_per_game: 1.5
34 | field_goals_attempted_per_game: 1.5
35 | field_goals_made_per_game: 1.5
36 | field_goal_percentage: 1.5
37 | free_throw_percentage: 1.5
38 | three_point_attempted_per_game: 1.5
39 | three_point_made_per_game: 1.5
40 | three_point_percentage: 1.5
41 | points_per_game: 1.5
42 | offensive_rebounds_per_game: 1.5
43 | defensive_rebounds_per_game: 1.5
44 | rebounds_per_game: 1.5
45 | assists_per_game: 1.5
46 | steals_per_game: 1.5
47 | blocks_per_game: 1.5
48 | turnovers_per_game: 1.5
49 | player_efficiency_rating: 1.5
50 | twitter_sentiment: 1.5
51 | image_url: MyString
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "trade-blitz",
3 | "private": true,
4 | "dependencies": {
5 | "@babel/core": "^7.1.2",
6 | "@babel/preset-env": "^7.1.0",
7 | "@babel/preset-react": "^7.0.0",
8 | "babel-loader": "^8.0.4",
9 | "chart.js": "^2.7.3",
10 | "react": "^16.5.2",
11 | "react-chartjs-2": "^2.7.4",
12 | "react-count-up": "^1.0.0",
13 | "react-countup": "^3.0.0",
14 | "react-dom": "^16.5.2",
15 | "react-redux": "^5.0.7",
16 | "react-router-dom": "^4.3.1",
17 | "react-vis": "^1.11.3",
18 | "recharts": "^1.3.3",
19 | "redux": "^4.0.0",
20 | "redux-logger": "^3.0.6",
21 | "redux-thunk": "^2.3.0",
22 | "victory": "^30.5.0",
23 | "webpack": "^4.20.2",
24 | "webpack-cli": "^3.1.2"
25 | },
26 | "description": "TradeBlitz is a web application that allows users to invest in the top athletes.",
27 | "version": "1.0.0",
28 | "main": "index.js",
29 | "directories": {
30 | "lib": "lib",
31 | "test": "test"
32 | },
33 | "engines": {
34 | "node": "10.6.0",
35 | "yarn": "1.10.1",
36 | "npm": "6.1.0"
37 | },
38 | "scripts": {
39 | "test": "echo \"Error: no test specified\" && exit 1",
40 | "postinstall": "webpack",
41 | "webpack": "webpack --mode=development --watch"
42 | },
43 | "repository": {
44 | "type": "git",
45 | "url": "git+https://github.com/sirivatd/trade-blitz.git"
46 | },
47 | "keywords": [],
48 | "author": "",
49 | "license": "ISC",
50 | "bugs": {
51 | "url": "https://github.com/sirivatd/trade-blitz/issues"
52 | },
53 | "homepage": "https://github.com/sirivatd/trade-blitz#readme"
54 | }
55 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/news_articles.css:
--------------------------------------------------------------------------------
1 | .news-articles-section-container {
2 | display: block;
3 | margin-top: 700px;
4 | width: 60%;
5 | text-align: left;
6 | margin-left: 90px;
7 | }
8 |
9 | .recent-news-header {
10 | font-family: "Noto Sans", sans-serif;
11 | font-size: 25px;
12 | }
13 |
14 | .news-article-item-section {
15 | background-color: white;
16 | position: relative;
17 | }
18 |
19 | .news-article-img {
20 | width: 150px;
21 | max-height: 100px;
22 | border-radius: 20px;
23 | margin-left: 5px;
24 | }
25 |
26 | .news-article-item-section {
27 | display: flex;
28 | padding-top: 15px;
29 | padding-bottom: 15px;
30 | padding-right: 15px;
31 | margin-bottom: 20px;
32 | height: 120px;
33 | border-radius: 5px;
34 | }
35 |
36 | .news-article-item-section:hover {
37 | box-shadow: -1px 4px 18px #c4c4c4;
38 | cursor: pointer;
39 | }
40 |
41 | .news-article-title {
42 | margin-top: 5px;
43 | font-family: "Noto Sans", sans-serif;
44 | font-size: 15px;
45 | }
46 |
47 | .news-article-publisher {
48 | margin-top: 0;
49 | font-family: "Noto Sans", sans-serif;
50 | font-size: 10px;
51 | color: #21ce99;
52 | position: absolute;
53 | left: 5px;
54 | bottom: 0;
55 | }
56 |
57 | .news-article-timestamp {
58 | font-family: "Noto Sans", sans-serif;
59 | font-size: 10px;
60 | color: #21ce99;
61 | position: absolute;
62 | right: 10px;
63 | bottom: 0;
64 | }
65 |
66 | .news-article-description-section {
67 | height: 100%;
68 | overflow: hidden;
69 | font-family: "Noto Sans", sans-serif;
70 | font-size: 12px;
71 | position: absolute;
72 | left: 170px;
73 | padding-right: 10px;
74 | }
75 |
--------------------------------------------------------------------------------
/frontend/components/not_found.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { withRouter } from "react-router-dom";
3 |
4 | class NotFound extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | }
8 | render() {
9 | return (
10 |
11 |
12 |
![]()
this.props.history.push("/")}
14 | className="logo-img"
15 | src="https://media.glassdoor.com/sqll/1167765/robinhood-squarelogo-1530549970728.png"
16 | />
17 |
18 |
19 |
Wow
20 | Such 404
21 |
22 |
23 |
24 | We couldn't find the page you were looking for.
25 |
26 |
27 | It seems you may have taken a wrong turn.
28 |
29 |
30 |
31 |
32 |
38 |
39 |
40 |

45 |
46 |
47 | );
48 | }
49 | }
50 |
51 | export default withRouter(NotFound);
52 |
--------------------------------------------------------------------------------
/frontend/components/athlete/athlete_show_container.js:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import AthleteShow from "./athlete_show.jsx";
5 | import { fetchAllAthletes } from "./../../actions/athlete_actions";
6 | import { fetchStocks } from "../../actions/stock_actions";
7 | import { logout } from "../../actions/session_actions";
8 | import { fetchAllOrders } from "./../../actions/order_actions";
9 | import {
10 | addWatchlistItem,
11 | fetchAllWatchlistItems,
12 | deleteWatchlistItem
13 | } from "./../../actions/watchlist_actions";
14 |
15 | const mapStateToProps = (
16 | { session, entities: { athletes, users, orders, stocks, watchlistItems } },
17 | ownProps
18 | ) => {
19 | return {
20 | athlete: athletes[ownProps.match.params.athleteId],
21 | currentUser: users[session.id],
22 | athletes: Object.values(athletes),
23 | orders: Object.values(orders),
24 | stocks: Object.values(stocks),
25 | watchlistItems: Object.values(watchlistItems)
26 | };
27 | };
28 |
29 | const mDP = dispatch => ({
30 | fetchAllAthletes: () => dispatch(fetchAllAthletes()),
31 | logout: () => dispatch(logout()),
32 | fetchStocks: () => dispatch(fetchStocks()),
33 | fetchAllOrders: userId => dispatch(fetchAllOrders(userId)),
34 | addWatchlistItem: (userId, item) => dispatch(addWatchlistItem(userId, item)),
35 | fetchAllWatchlistItems: userId => dispatch(fetchAllWatchlistItems(userId)),
36 | deleteWatchlistItem: (userId, itemId) =>
37 | dispatch(deleteWatchlistItem(userId, itemId))
38 | });
39 |
40 | export default connect(
41 | mapStateToProps,
42 | mDP
43 | )(AthleteShow);
44 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/athlete_stats.css:
--------------------------------------------------------------------------------
1 | .athlete-stats-name {
2 | font-size: 22px;
3 | color: #21ce99;
4 | }
5 |
6 | .athlete-stats-offense {
7 | display: flex;
8 | justify-content: space-between;
9 | }
10 |
11 | .athlete-stats-defense {
12 | display: flex;
13 | justify-content: space-between;
14 | position: relative;
15 | }
16 |
17 | .athlete-stats-section {
18 | font-family: "Source Sans Pro", sans-serif;
19 | }
20 |
21 | .athlete-stats-points {
22 | text-align: left;
23 | }
24 |
25 | .athlete-stats-fg-percentage {
26 | text-align: left;
27 | }
28 | .athlete-stats-games-played {
29 | text-align: left;
30 | }
31 |
32 | .athlete-stats-efficiency {
33 | text-align: left;
34 | }
35 |
36 | .athlete-stats-assists {
37 | text-align: left;
38 | position: absolute;
39 | left: 195px;
40 | }
41 |
42 | .athlete-stats-steals {
43 | text-align: left;
44 | position: absolute;
45 | left: 380px;
46 | }
47 |
48 | .athlete-stats-blocks {
49 | text-align: left;
50 | position: absolute;
51 | left: 560px;
52 | }
53 |
54 | .athlete-stats-rebounds {
55 | text-align: left;
56 | }
57 |
58 | .games-played-label {
59 | color: lightgray;
60 | }
61 |
62 | .athlete-points-label {
63 | color: lightgray;
64 | }
65 |
66 | .fg-percentage-label {
67 | color: lightgray;
68 | }
69 |
70 | .efficiency-label {
71 | color: lightgray;
72 | }
73 |
74 | .athlete-rebounds-label {
75 | color: lightgray;
76 | }
77 |
78 | .athlete-assists-label {
79 | color: lightgray;
80 | }
81 |
82 | .athlete-steals-label {
83 | color: lightgray;
84 | }
85 |
86 | .athlete-blocks-label {
87 | color: lightgray;
88 | }
89 |
90 | .athlete-stats-team {
91 | font-size: 16px;
92 | }
93 |
--------------------------------------------------------------------------------
/frontend/actions/session_actions.js:
--------------------------------------------------------------------------------
1 | import * as APIUtil from "../util/session_api_util";
2 |
3 | export const RECEIVE_CURRENT_USER = "RECEIVE_CURRENT_USER";
4 | export const LOGOUT_CURRENT_USER = "LOGOUT_CURRENT_USER";
5 | export const RECEIVE_SESSION_ERRORS = "RECEIVE_SESSION_ERRORS";
6 | export const RECEIVE_FIRST_USER = "RECEIVE_FIRST_USER";
7 | export const REMOVE_FIRST_USER = "REMOVE_FIRST_USER";
8 | export const REMOVE_CURRENT_USER = "REMOVE_CURRENT_USER";
9 |
10 | // Regular action creators
11 |
12 | export const receiveFirstUser = () => ({
13 | type: RECEIVE_FIRST_USER,
14 | firstUser: true
15 | });
16 |
17 | export const removeFirstUser = () => ({
18 | type: REMOVE_FIRST_USER,
19 | firstUser: false
20 | });
21 |
22 | export const receiveCurrentUser = currentUser => ({
23 | type: RECEIVE_CURRENT_USER,
24 | currentUser
25 | });
26 |
27 | export const logoutCurrentUser = () => ({
28 | type: LOGOUT_CURRENT_USER
29 | });
30 |
31 | export const receiveErrors = errors => ({
32 | type: RECEIVE_SESSION_ERRORS,
33 | errors
34 | });
35 |
36 | // Thunk action creators
37 |
38 | export const signup = user => dispatch =>
39 | APIUtil.signup(user).then(
40 | user => dispatch(receiveCurrentUser(user)),
41 | err => dispatch(receiveErrors(err.responseJSON))
42 | );
43 |
44 | export const login = user => dispatch =>
45 | APIUtil.login(user).then(
46 | user => dispatch(receiveCurrentUser(user)),
47 | err => dispatch(receiveErrors(err.responseJSON))
48 | );
49 |
50 | export const logout = () => dispatch =>
51 | APIUtil.logout().then(user => dispatch(logoutCurrentUser()));
52 |
53 | export const removeUser = () => dispatch => dispatch(removeCurrentUser());
54 |
--------------------------------------------------------------------------------
/frontend/components/home/home_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import React from "react";
3 | import { Link } from "react-router-dom";
4 | import Home from "./home";
5 | import { logout, removeUser } from "../../actions/session_actions";
6 | import { fetchStocks, receiveAStock } from "../../actions/stock_actions";
7 | import {
8 | fetchAllOrders,
9 | receiveAllOrders,
10 | receiveOrder
11 | } from "../../actions/order_actions";
12 | import {
13 | fetchAllAthletes,
14 | receiveAthlete
15 | } from "../../actions/athlete_actions";
16 |
17 | import { fetchAllWatchlistItems } from "../../actions/watchlist_actions";
18 |
19 | const mapStateToProps = (
20 | {
21 | session: { id, firstTime },
22 | entities: { users, stocks, orders, athletes, watchlistItems }
23 | },
24 | ownProps
25 | ) => {
26 | return {
27 | stocks: Object.values(stocks),
28 | currentUser: users[id],
29 | firstTime: firstTime,
30 | orders: Object.values(orders),
31 | athletes: Object.values(athletes),
32 | watchlistItems: Object.values(watchlistItems)
33 | };
34 | };
35 |
36 | const mapDispatchToProps = dispatch => ({
37 | logout: () => dispatch(logout()),
38 | fetchStocks: () => dispatch(fetchStocks()),
39 | fetchAllOrders: userId => dispatch(fetchAllOrders(userId)),
40 | fetchAllAthletes: () => dispatch(fetchAllAthletes()),
41 | fetchStocks: () => dispatch(fetchStocks()),
42 | receiveAStock: stock => dispatch(receiveAStock(stock)),
43 | removeUser: () => dispatch(removeUser()),
44 | fetchAllWatchlistItems: userId => dispatch(fetchAllWatchlistItems(userId))
45 | });
46 |
47 | export default connect(
48 | mapStateToProps,
49 | mapDispatchToProps
50 | )(Home);
51 |
--------------------------------------------------------------------------------
/frontend/components/home/top_movers/top_movers_index.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import TopMoversIndexItem from "./top_movers_index_item";
3 | import { fetchAllAthletes } from "./../../../actions/athlete_actions";
4 | import { fetchStocks } from "./../../../actions/stock_actions";
5 | import { fetchTweets } from "./../../../actions/tweet_actions";
6 |
7 | class TopMoversIndex extends React.Component {
8 | constructor(props) {
9 | super(props);
10 | this.state = {
11 | topAthletes: [],
12 | tweets: []
13 | };
14 | }
15 |
16 | componentDidMount() {
17 | this.props.fetchAllAthletes();
18 | this.props.fetchStocks();
19 | let topAthletes = [];
20 | for (let i = 0; i < 5; i++) {
21 | const randomNum = Math.floor(Math.random() * this.props.athletes.length);
22 | if (topAthletes.includes(randomNum)) {
23 | } else {
24 | topAthletes.push(randomNum);
25 | }
26 | }
27 | this.setState({
28 | topAthletes: topAthletes
29 | });
30 | }
31 |
32 | render() {
33 | const loader = () => (
34 |
35 |
36 |
37 | );
38 | const athleteItems = () =>
39 | this.state.topAthletes.map(topAthlete => (
40 |
45 | ));
46 |
47 | return (
48 |
49 | {this.props.athletes.length > 0 ? athleteItems() : loader()}
50 |
51 | );
52 | }
53 | }
54 |
55 | export default TopMoversIndex;
56 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/app/controllers/api/orders_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::OrdersController < ApplicationController
2 | def show
3 | @order = Order.find(params[:id])
4 | @stock = @order.stock
5 | render "api/orders/show_order"
6 | end
7 |
8 | def index
9 | id = params[:user_id]
10 | @orders = Order.all.select {|m| m.user_id == id}
11 | end
12 |
13 | def update
14 | @order = Order.find(params[:id])
15 | sentimentScore = Tweet.scrape_tweeter(@order.athlete.name)
16 | @tweet_snapshot = TweetScoreSnapshot.create(athlete_id: @order.athlete.id, twitter_sentiment: sentimentScore)
17 | scoreImpact = 0
18 | if sentimentScore < 1
19 | scoreImpact = -0.05
20 | elsif sentimentScore < 0
21 | scoreImpact = -0.01
22 | elsif sentimentScore > 1
23 | scoreImpact = 0.05
24 | elsif sentimentScore > 0
25 | scoreImpact = 0.10
26 | end
27 | if scoreImpact + @order.stock.current_price < @order.stock.initial_price/2
28 | @order.stock.update(current_price: @order.stock.initial_price * 0.5 + 0.25)
29 | else
30 | @order.stock.update(current_price: @order.stock.current_price + scoreImpact)
31 | @stock = @order.stock
32 | end
33 | @athlete_price_snapshot = AthletePriceSnapshot.create(athlete_id: @order.athlete.id, price: @order.stock.current_price)
34 |
35 | render "api/orders/show"
36 | end
37 |
38 | def create
39 | @order = Order.new(order_params)
40 | if @order.save!
41 | render "api/orders/show_order"
42 |
43 | else
44 | render json: @order.errors.full_messages, status: 422
45 |
46 | end
47 | end
48 |
49 | private
50 |
51 | def order_params
52 | params.require(:order).permit(:order_type, :num_share, :user_id, :stock_id, :purchase_date, :purchase_price)
53 | end
54 |
55 | end
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/app/models/stock.rb:
--------------------------------------------------------------------------------
1 | class Stock < ApplicationRecord
2 | belongs_to :athlete
3 | has_many :orders
4 |
5 | def self.update_price(stock)
6 | randomNumber = rand(-5...5)
7 |
8 | stock.update(current_price: stock.current_price + (randomNumber * (0.5)))
9 |
10 |
11 | end
12 |
13 | def self.calculate_value(athlete)
14 | games_played_score = athlete.games_played * 100000
15 | minutes_per_game_score = athlete.minutes_per_game * 50000
16 | field_goals_made_per_game_score = athlete.field_goals_made_per_game * 1000000
17 | field_goal_percentage_score = (athlete.field_goal_percentage * 50000000)/100
18 | free_throw_percentage_score = (athlete.free_throw_percentage * 5000000)/100
19 | three_point_made_per_game_score = athlete.three_point_made_per_game * 250000
20 | three_point_percentage_score = (athlete.three_point_percentage * 50000000)/100
21 | points_per_game_score = athlete.points_per_game * 200000
22 | rebounds_per_game_score = athlete.rebounds_per_game * 170000
23 | assists_per_game_score = athlete.assists_per_game * 170000
24 | steals_per_game_score = athlete.steals_per_game * 400000
25 | blocks_per_game_score = athlete.blocks_per_game * 400000
26 | turnovers_per_game_score = athlete.turnovers_per_game * 500000
27 | player_efficiency_rating_score = (athlete.player_efficiency_rating * 75000000)/100
28 | twitter_sentiment_score = athlete.twitter_sentiment * 15000000
29 |
30 | total_value = games_played_score + minutes_per_game_score + field_goal_percentage_score + field_goals_made_per_game_score + field_goal_percentage_score + free_throw_percentage_score + three_point_made_per_game_score + three_point_percentage_score + points_per_game_score + rebounds_per_game_score + assists_per_game_score + steals_per_game_score + blocks_per_game_score - turnovers_per_game_score + player_efficiency_rating_score + twitter_sentiment_score
31 |
32 | return total_value/1000000
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/account_menu.css:
--------------------------------------------------------------------------------
1 | .account-settings-menu {
2 | text-align: left;
3 | z-index: 999999;
4 | }
5 |
6 | .account-settings-stats {
7 | font-family: "Noto Sans", sans-serif;
8 | }
9 |
10 | .account-settings-name {
11 | font-family: "Noto Sans", sans-serif;
12 | font-size: 17px;
13 | margin-left: 20px;
14 | margin-top: 30px;
15 | }
16 |
17 | .account-setting-label {
18 | font-size: 12px;
19 | margin: 0px;
20 | font-weight: 100;
21 | font-family: "Noto Sans", sans-serif;
22 | padding-bottom: 20px;
23 | }
24 |
25 | .account-setting-port-value {
26 | font-size: 17px;
27 | font-family: "Noto Sans", sans-serif;
28 | margin-bottom: 7px;
29 | margin-top: 0px;
30 | }
31 |
32 | .account-setting-power-value {
33 | font-size: 17px;
34 | font-family: "Noto Sans", sans-serif;
35 | margin-bottom: 7px;
36 | margin-top: 10px;
37 | }
38 |
39 | .account-setting-divider {
40 | display: block;
41 | margin-top: 0.5em;
42 | margin-bottom: 0;
43 | width: 99%;
44 | border-color: black;
45 | border-style: inset;
46 | border-width: 0.7px;
47 | }
48 |
49 | .account-setting-port {
50 | display: inline-block;
51 | text-align: left;
52 | margin-left: 20px;
53 | }
54 |
55 | .account-setting-power {
56 | display: inline-block;
57 | text-align: left;
58 | margin-left: 30px;
59 | }
60 |
61 | .account-settings-list {
62 | height: 23px;
63 | margin: 0;
64 | padding-top: 16px;
65 | padding-bottom: 16px;
66 | }
67 |
68 | .account-settings-item {
69 | font-family: "Noto Sans", sans-serif;
70 | font-size: 16px;
71 | position: absolute;
72 | left: 20px;
73 | }
74 |
75 | .account-settings-list:hover {
76 | background-color: rgb(23, 23, 24);
77 | cursor: pointer;
78 | }
79 |
80 | .account-settings-list li {
81 | display: inline;
82 | padding-right: 6px;
83 | padding-left: 25px;
84 | }
85 |
86 | .account-settings-list .account-settings-item {
87 | background-image: url("https://www.iconsdb.com/icons/preview/white/logout-xxl.png");
88 | background-repeat: no-repeat;
89 | background-size: contain;
90 | }
91 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure public file server for tests with Cache-Control for performance.
16 | config.public_file_server.enabled = true
17 | config.public_file_server.headers = {
18 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
19 | }
20 |
21 | # Show full error reports and disable caching.
22 | config.consider_all_requests_local = true
23 | config.action_controller.perform_caching = false
24 |
25 | # Raise exceptions instead of rendering exception templates.
26 | config.action_dispatch.show_exceptions = false
27 |
28 | # Disable request forgery protection in test environment.
29 | config.action_controller.allow_forgery_protection = false
30 |
31 | # Store uploaded files on the local file system in a temporary directory
32 | config.active_storage.service = :test
33 |
34 | config.action_mailer.perform_caching = false
35 |
36 | # Tell Action Mailer not to deliver emails to the real world.
37 | # The :test delivery method accumulates sent emails in the
38 | # ActionMailer::Base.deliveries array.
39 | config.action_mailer.delivery_method = :test
40 |
41 | # Print deprecation notices to the stderr.
42 | config.active_support.deprecation = :stderr
43 |
44 | # Raises error for missing translations
45 | # config.action_view.raise_on_missing_translations = true
46 | end
47 |
--------------------------------------------------------------------------------
/frontend/components/session_form/session_form.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { withRouter } from "react-router-dom";
3 |
4 | class SessionForm extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.state = {
8 | email: "",
9 | password: ""
10 | };
11 | this.handleSubmit = this.handleSubmit.bind(this);
12 | }
13 |
14 | update(field) {
15 | return e =>
16 | this.setState({
17 | [field]: e.currentTarget.value
18 | });
19 | }
20 |
21 | handleSubmit(e) {
22 | e.preventDefault();
23 | const user = Object.assign({}, this.state);
24 | this.props.processForm(user);
25 | }
26 | renderErrors() {
27 | return (
28 |
29 | {this.props.errors.map((error, i) => (
30 | - {error}
31 | ))}
32 |
33 | );
34 | }
35 |
36 | render() {
37 | return (
38 |
74 | );
75 | }
76 | }
77 |
78 | export default withRouter(SessionForm);
79 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/login.css:
--------------------------------------------------------------------------------
1 | .img-container {
2 | width: 50%;
3 | height: 100%;
4 | }
5 |
6 | .login-image {
7 | max-width: 100%;
8 | max-height: 100%;
9 | }
10 |
11 | .login-form-box {
12 | width: 50%;
13 | height: 100%;
14 | margin-left: 50px;
15 | margin-top: 120px;
16 | }
17 |
18 | .login-form-container {
19 | display: flex;
20 | justify-content: center;
21 | height: 100%;
22 | }
23 |
24 | .login-header {
25 | font-family: "Source Sans Pro", sans-serif;
26 | font-size: 30px;
27 | }
28 |
29 | .email-text {
30 | font-family: "Poppins", sans-serif;
31 | margin-bottom: 130px;
32 | }
33 |
34 | .password-text {
35 | font-family: "Poppins", sans-serif;
36 | margin-bottom: 130px;
37 | }
38 |
39 | .login-input {
40 | width: 70%;
41 | height: 48px;
42 | border-radius: 5px;
43 | border: 1px solid white;
44 | background-color: #fafafa;
45 | padding-left: 20px;
46 | font-size: 17px;
47 | }
48 |
49 | .login-input:hover {
50 | border-color: #cbcbcd;
51 | }
52 |
53 | .login-input:focus {
54 | border-color: #21ce99;
55 | outline: none;
56 | }
57 |
58 | .login-submit {
59 | width: 140px;
60 | height: 48px;
61 | background-color: #21ce99;
62 | font-family: "Source Sans Pro", sans-serif;
63 | color: white;
64 | border-radius: 5px;
65 | border: none;
66 | font-size: 15px;
67 | cursor: pointer;
68 | }
69 |
70 | .login-submit:hover {
71 | background-color: #1ae9aa;
72 | }
73 |
74 | .demo-link {
75 | font-family: "Source Sans Pro", sans-serif;
76 | text-decoration: none;
77 | color: #21ce99;
78 | }
79 |
80 | .demo-link:hover {
81 | color: #1ae9aa;
82 | }
83 |
84 | .demo-button {
85 | font-family: "Source Sans Pro", sans-serif;
86 | background-color: white;
87 | border: none;
88 | color: #21ce99;
89 | font-size: 15px;
90 | }
91 |
92 | .demo-button:hover {
93 | color: #1ae9aa;
94 | }
95 |
96 | .error-list li {
97 | display: inline;
98 | padding-right: 6px;
99 | padding-left: 25px;
100 | }
101 |
102 | .error-list .error-text {
103 | background-image: url("http://icons.iconarchive.com/icons/custom-icon-design/mono-general-1/512/alert-icon.png");
104 | background-repeat: no-repeat;
105 | background-size: contain;
106 | font-family: "Source Sans Pro", sans-serif;
107 | }
108 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3 |
4 | ruby '2.5.1'
5 |
6 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7 | gem 'rails', '~> 5.2.1'
8 | # Use postgresql as the database for Active Record
9 | gem 'pg', '>= 0.18', '< 2.0'
10 | gem 'sentimental'
11 | gem 'twitter'
12 | gem 'httparty'
13 | # Use Puma as the app server
14 | gem 'puma', '~> 3.11'
15 | # Use SCSS for stylesheets
16 | gem 'sass-rails', '~> 5.0'
17 | # Use Uglifier as compressor for JavaScript assets
18 | gem 'uglifier', '>= 1.3.0'
19 | # See https://github.com/rails/execjs#readme for more supported runtimes
20 | # gem 'mini_racer', platforms: :ruby
21 |
22 | # Use CoffeeScript for .coffee assets and views
23 | gem 'coffee-rails', '~> 4.2'
24 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
25 | gem 'jbuilder', '~> 2.5'
26 | # Use Redis adapter to run Action Cable in production
27 | # gem 'redis', '~> 4.0'
28 | # Use ActiveModel has_secure_password
29 | gem 'bcrypt', '~> 3.1.7'
30 | gem 'jquery-rails'
31 | gem 'rails_12factor'
32 | # Use ActiveStorage variant
33 | # gem 'mini_magick', '~> 4.8'
34 |
35 | # Use Capistrano for deployment
36 | # gem 'capistrano-rails', group: :development
37 |
38 | # Reduces boot times through caching; required in config/boot.rb
39 | gem 'bootsnap', '>= 1.1.0', require: false
40 |
41 | group :development, :test do
42 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
43 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
44 | end
45 |
46 | group :development do
47 | # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
48 | gem 'web-console', '>= 3.3.0'
49 | gem 'listen', '>= 3.0.5', '< 3.2'
50 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
51 | gem 'spring'
52 | gem 'spring-watcher-listen', '~> 2.0.0'
53 | gem 'pry-rails'
54 | end
55 |
56 | group :test do
57 | # Adds support for Capybara system testing and selenium driver
58 | gem 'capybara', '>= 2.15'
59 | gem 'selenium-webdriver'
60 | # Easy installation and use of chromedriver to run system tests with Chrome
61 | gem 'chromedriver-helper'
62 | end
63 |
64 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
65 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
66 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports.
13 | config.consider_all_requests_local = true
14 |
15 | # Enable/disable caching. By default caching is disabled.
16 | # Run rails dev:cache to toggle caching.
17 | if Rails.root.join('tmp', 'caching-dev.txt').exist?
18 | config.action_controller.perform_caching = true
19 |
20 | config.cache_store = :memory_store
21 | config.public_file_server.headers = {
22 | 'Cache-Control' => "public, max-age=#{2.days.to_i}"
23 | }
24 | else
25 | config.action_controller.perform_caching = false
26 |
27 | config.cache_store = :null_store
28 | end
29 |
30 | # Store uploaded files on the local file system (see config/storage.yml for options)
31 | config.active_storage.service = :local
32 |
33 | # Don't care if the mailer can't send.
34 | config.action_mailer.raise_delivery_errors = false
35 |
36 | config.action_mailer.perform_caching = false
37 |
38 | # Print deprecation notices to the Rails logger.
39 | config.active_support.deprecation = :log
40 |
41 | # Raise an error on page load if there are pending migrations.
42 | config.active_record.migration_error = :page_load
43 |
44 | # Highlight code that triggered database queries in logs.
45 | config.active_record.verbose_query_logs = true
46 |
47 | # Debug mode disables concatenation and preprocessing of assets.
48 | # This option may cause significant delays in view rendering with a large
49 | # number of complex assets.
50 | config.assets.debug = true
51 |
52 | # Suppress logger output for asset requests.
53 | config.assets.quiet = true
54 |
55 | # Raises error for missing translations
56 | # config.action_view.raise_on_missing_translations = true
57 |
58 | # Use an evented file watcher to asynchronously detect changes in source code,
59 | # routes, locales, etc. This feature depends on the listen gem.
60 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
61 | end
62 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/search.css:
--------------------------------------------------------------------------------
1 | input::-webkit-input-placeholder {
2 | color: #e4e4e4 !important;
3 | }
4 |
5 | input:-moz-placeholder {
6 | /* Firefox 18- */
7 | color: #e4e4e4 !important;
8 | }
9 |
10 | input::-moz-placeholder {
11 | /* Firefox 19+ */
12 | color: #e4e4e4 !important;
13 | }
14 |
15 | input:-ms-input-placeholder {
16 | color: #e4e4e4 !important;
17 | }
18 |
19 | .search-input {
20 | width: 420px;
21 | height: 36px;
22 | float: left;
23 | padding-left: 10px;
24 | color: #e4e4e4;
25 | font-size: 13px;
26 | border: none;
27 | font-family: "Noto Sans", sans-serif;
28 | }
29 |
30 | .search-bar-container {
31 | width: 478px;
32 | display: inline-block;
33 | margin-top: 0px;
34 | text-align: left;
35 | }
36 |
37 | .search-bar {
38 | width: 433px;
39 | overflow: hidden;
40 | position: fixed;
41 | top: 0;
42 | left: 120px;
43 | margin-top: 10px;
44 | border: 1px solid #e4e4e4;
45 | border-radius: 7px;
46 | background-color: white;
47 | }
48 |
49 | .search-bar:hover {
50 | box-shadow: -1px 4px 18px #c4c4c4;
51 | }
52 |
53 | .search-bar:active {
54 | box-shadow: -1px 4px 18px #c4c4c4;
55 | background-color: white;
56 | }
57 |
58 | .search-bar:focus {
59 | box-shadow: -1px 4px 18px #c4c4c4;
60 | background-color: white;
61 | }
62 |
63 | .search-input:active {
64 | outline: none;
65 | color: black;
66 | border: none;
67 | }
68 |
69 | .search-results {
70 | padding: 0px;
71 | }
72 |
73 | .search-input:focus {
74 | outline: none;
75 | color: black;
76 | border: none;
77 | }
78 | .search-athlete-team {
79 | font-family: "Noto Sans", sans-serif;
80 | font-size: 15px;
81 | margin-top: 0px;
82 | width: 60px;
83 | margin-bottom: 0px;
84 | padding-left: 10px;
85 | }
86 |
87 | .search-athlete-name {
88 | font-family: "Noto Sans", sans-serif;
89 | font-size: 15px;
90 | margin-top: 0px;
91 | margin-left: 20px;
92 | margin-bottom: 0px;
93 | }
94 |
95 | .search-result-label {
96 | margin-top: 65px;
97 | font-family: "Noto Sans", sans-serif;
98 | color: lightgray;
99 | font-size: 15px;
100 | padding-left: 10px;
101 | }
102 |
103 | .search-result-item {
104 | display: flex;
105 | justify-content: left;
106 | padding-top: 10px;
107 | padding-bottom: 10px;
108 | }
109 |
110 | .search-result-item:hover {
111 | cursor: pointer;
112 | background-color: #f5f5f5;
113 | }
114 |
--------------------------------------------------------------------------------
/app/models/tweet.rb:
--------------------------------------------------------------------------------
1 | require 'nokogiri'
2 | require 'httparty'
3 |
4 | class Tweet < ApplicationRecord
5 | belongs_to :athlete
6 |
7 | def self.sync(athlete)
8 | client = Twitter::REST::Client.new do |config|
9 | config.consumer_key = "jrlq2OdVBQzwBkwPMBmwlcYjY"
10 | config.consumer_secret = "3zsxDQh5eGzqEklgRnPTNsaPdqLLooXhtF4wcido2jhgvZZdrU"
11 | config.access_token = "359603447-2EcA5jn63EWAUp2DZS8bswgG1KIAom5Njpw5lDGv"
12 | config.access_token_secret = "mZ20O7oooQt5RpdR72mEnbuwxrZTm0c717ofthsV45T5C"
13 | end
14 | client.search("to:#{athlete.name}", result_type: "recent").take(1).collect.each do |tweet|
15 | score = $analyzer.score tweet.text
16 | Tweet.create({body: tweet.text, athlete_id: athlete.id, score: score})
17 | end
18 |
19 | end
20 |
21 | def self.scrape_tweeter(athlete_name)
22 | names = athlete_name.split(" ")
23 | firstName = names[0]
24 | lastName = names[1]
25 | url = "https://twitter.com/search?q=" + lastName + "%20" + firstName + "&src=typd"
26 |
27 | unparsed_page = HTTParty.get(url)
28 | parsed_page = Nokogiri::HTML(unparsed_page)
29 |
30 | tweetDivs = parsed_page.css('div.tweet')
31 |
32 | scrappedTweets = []
33 | tweetDivs.each do |div|
34 | tweetBody = div.css('p.TweetTextSize.js-tweet-text.tweet-text').text
35 | tweetUsername = div.css("span.username").text
36 | tweetTimestamp = div.css("span._timestamp").text
37 | scrappedTweets.push({tweetBody: tweetBody, tweetUsername: tweetUsername, time_created: tweetTimestamp})
38 | end
39 |
40 | return $analyzer.score scrappedTweets
41 | end
42 |
43 | def self.find_tweets(athlete_name)
44 | names = athlete_name.split(" ")
45 | firstName = names[0]
46 | lastName = names[1]
47 | url = "https://twitter.com/search?q=" + lastName + "%20" + firstName + "&src=typd"
48 |
49 | unparsed_page = HTTParty.get(url)
50 | parsed_page = Nokogiri::HTML(unparsed_page)
51 |
52 | tweetDivs = parsed_page.css('div.tweet')
53 |
54 | scrappedTweets = []
55 | tweetDivs.each do |div|
56 | tweetBody = div.css('p.TweetTextSize.js-tweet-text.tweet-text').text
57 | tweetUsername = div.css("span.username").text
58 | tweetTimestamp = div.css("span._timestamp").text
59 | scrappedTweets.push({ tweetBody: tweetBody, tweetUsername: tweetUsername, time_created: tweetTimestamp})
60 | end
61 |
62 | return scrappedTweets
63 | end
64 |
65 | end
66 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Robinhoops
2 |
3 | [Live Site](http://www.robinhoops.io)
4 |
5 |
6 | Robinhoops is a Robinhood.com clone built with Rails and React/Redux that allows users to invest in the top NBA athletes.
7 |
8 | 
9 |
10 | Athletes' prices are updated every few seconds based on their stats and recent overall Twitter sentiment.
11 |
12 |
13 | ## Twitter Sentiment
14 |
15 | Credit to sentimental gem
16 | Robinhoops scrapes Twitter for recent tweets and then maps each word and assigns an overall score based on each tweet.
17 |
18 | Using Nokogiri and HTTParty
19 |
20 | ```ruby
21 | def self.scrape_tweeter(athlete_name)
22 | names = athlete_name.split(" ")
23 | firstName = names[0]
24 | lastName = names[1]
25 | url = "https://twitter.com/search?q=" + lastName + "%20" + firstName + "&src=typd"
26 |
27 | unparsed_page = HTTParty.get(url)
28 | parsed_page = Nokogiri::HTML(unparsed_page)
29 |
30 | tweetDivs = parsed_page.css('div.tweet')
31 |
32 | scrappedTweets = []
33 | tweetDivs.each do |div|
34 | tweetBody = div.css('p.TweetTextSize.js-tweet-text.tweet-text').text
35 | tweetUsername = div.css("span.username").text
36 | tweetTimestamp = div.css("span._timestamp").text
37 | scrappedTweets.push({tweetBody: tweetBody, tweetUsername: tweetUsername, time_created: tweetTimestamp})
38 | end
39 |
40 | return $analyzer.score scrappedTweets
41 | end
42 | ```
43 |
44 | ## How it Works
45 |
46 | All new users receive $2000.00 and a free stock/athlete.
47 |
48 | To be really specific, Robinhoops creates a new user and then store snapshots of portfolio value and twitter sentiment every 20 seconds. These data points are then used to graph stock and user portfolio value volatility. An athlete's price will only fluctuate if users on trading that specific stock.
49 |
50 | 
51 |
52 |
53 | ## Usage
54 |
55 | First, install bundles
56 |
57 | ```
58 | $ bundle install
59 | ```
60 |
61 | Install node dependencies
62 | ```
63 | $ npm install
64 | ```
65 | Start local rails server
66 | ```
67 | $ rails server
68 | ```
69 |
70 | ## Credits
71 | The following packages/libraries were used in the development of Robinhoops.io
72 |
73 | * [Chart.js](https://www.chartjs.org/)
74 | * [Sentimental gem](https://github.com/7compass/sentimental)
75 | * [News API](https://newsapi.org/)
76 | * [NBA Players Stats API](https://github.com/hlyford/nba-player-stats-api)
77 |
78 |
--------------------------------------------------------------------------------
/frontend/components/App.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import GreetingContainer from "./greeting/greeting_container";
3 | import { Route, Redirect, Switch, Link, HashRouter } from "react-router-dom";
4 | import LoginFormContainer from "./session_form/login_form_container";
5 | import SignupFormContainer from "./session_form/signup_form_container";
6 | import { AuthRoute, ProtectedRoute } from "../util/route_util";
7 | import HomeContainer from "./home/home_container";
8 | import NotFound from "./not_found";
9 | import FreeStockContainer from "./free_stock/free_stock_container";
10 | import AthleteShowContainer from "./athlete/athlete_show_container";
11 |
12 | const App = () => (
13 |
14 |
15 |
19 |
23 |
27 |
31 |
35 |
39 |
43 |
47 |
51 |
55 |
56 |
57 |
58 |
63 |
64 |
65 |
66 |
67 |
71 |
72 |
73 |
74 | );
75 |
76 | export default App;
77 |
--------------------------------------------------------------------------------
/frontend/components/home/home_chart/home_chart.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Bar, Line, Pie } from "react-chartjs-2";
3 |
4 | class HomeChart extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.state = { data: { datasets: [], labels: [] } };
8 | }
9 |
10 | componentDidMount() {
11 | $.ajax({
12 | url: `/api/users/${this.props.currentUser.id}/users_port_snapshots`,
13 | method: "GET"
14 | }).then(res => {
15 | let snapshotPoints = Object.values(res);
16 | let labels = [];
17 | let data = [];
18 |
19 | for (let i = 0; i < snapshotPoints.length; i++) {
20 | labels.push(snapshotPoints[i].created_at);
21 | data.push(snapshotPoints[i].port_value);
22 | }
23 | this.setState({
24 | data: {
25 | labels: labels,
26 | datasets: [
27 | {
28 | fill: false,
29 | borderColor: "#21ce99",
30 | strokeColor: "#21ce99",
31 | pointColor: "#21ce99",
32 | pointRadius: 0,
33 | pointStrokeColor: "#21ce99",
34 | pointHighlightFill: "#21ce99",
35 | data: data
36 | }
37 | ]
38 | }
39 | });
40 | });
41 | }
42 |
43 | render() {
44 | const loader = () => (
45 |
46 |
47 |
48 | );
49 | const athleteGraph = () => (
50 |
95 | );
96 | return (
97 | {this.props.athletes.length > 0 ? athleteGraph() : loader()}
98 | );
99 | }
100 | }
101 |
102 | export default HomeChart;
103 |
--------------------------------------------------------------------------------
/frontend/components/search_bar/search_bar.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { withRouter } from "react-router-dom";
3 |
4 | class SearchBar extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.state = {
8 | search: ""
9 | };
10 | this.updateSearch = this.updateSearch.bind(this);
11 | this.showSearchResults = this.showSearchResults.bind(this);
12 | this.handleClick = this.handleClick.bind(this);
13 | }
14 |
15 | componentDidMount() {
16 | document.addEventListener("mousedown", this.handleClick, false);
17 | }
18 |
19 | showSearchResults() {
20 | const searchResults = document.getElementsByClassName("search-results")[0];
21 | searchResults.classList.toggle("hidden-menu");
22 | }
23 | updateSearch(e) {
24 | this.setState({ search: e.target.value.substr(0).toLowerCase() });
25 | }
26 |
27 | handleClick(e) {
28 | const button = document.getElementsByClassName("search-input")[0];
29 | if (document.getElementsByClassName("search-bar")[0].contains(e.target)) {
30 | return;
31 | }
32 | this.handleClickOutside();
33 | }
34 |
35 | handleClickOutside() {
36 | const searchResults = document.getElementsByClassName("search-results")[0];
37 | if (searchResults.classList.contains("hidden-menu")) {
38 | } else {
39 | searchResults.classList.toggle("hidden-menu");
40 | }
41 | }
42 |
43 | render() {
44 | let filteredAthletes = this.props.athletes.filter(athlete => {
45 | if (
46 | athlete.name.toLowerCase().indexOf(this.state.search) !== -1 ||
47 | athlete.team_acronym.toLowerCase().indexOf(this.state.search) !== -1
48 | ) {
49 | return athlete;
50 | }
51 | });
52 |
53 | return (
54 |
86 | );
87 | }
88 | }
89 |
90 | export default withRouter(SearchBar);
91 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/signup.css:
--------------------------------------------------------------------------------
1 | .logo-container {
2 | display: block;
3 | height: 70px;
4 | margin-bottom: 40px;
5 | margin-left: 60px;
6 | }
7 |
8 | .signup-form {
9 | text-align: center;
10 | }
11 |
12 | .signup-content {
13 | display: flex;
14 | justify-content: space-around;
15 | }
16 |
17 | .signup-form-box {
18 | width: 40%;
19 | margin-left: 60px;
20 | }
21 |
22 | .signup-header {
23 | width: 100%;
24 | font-family: "Montserrat", sans-serif;
25 | font-size: 40px;
26 | font-weight: lighter;
27 | }
28 |
29 | .signup-description {
30 | width: 100%;
31 | font-family: "Montserrat", sans-serif;
32 | font-size: 20px;
33 | font-weight: lighter;
34 | }
35 |
36 | .signup-text-box {
37 | margin-left: 100px;
38 | }
39 |
40 | .name-inputs {
41 | width: 99%;
42 | display: flex;
43 | justify-content: space-between;
44 | }
45 |
46 | .login-link-text {
47 | font-family: "Source Sans Pro", sans-serif;
48 | margin-right: 5px;
49 | }
50 |
51 | .signup-first-name-input {
52 | width: 42%;
53 | left: 0px;
54 | height: 48px;
55 | border-radius: 5px;
56 | border: 1px solid white;
57 | background-color: #fafafa;
58 | padding-left: 20px;
59 | font-size: 17px;
60 | }
61 |
62 | .signup-first-name-input:hover {
63 | border-color: #cbcbcd;
64 | }
65 |
66 | .signup-first-name-input:focus {
67 | border-color: #21ce99;
68 | outline: none;
69 | }
70 |
71 | .signup-last-name-input:hover {
72 | border-color: #cbcbcd;
73 | }
74 |
75 | .signup-last-name-input:focus {
76 | border-color: #21ce99;
77 | outline: none;
78 | }
79 | .signup-last-name-input {
80 | width: 42%;
81 | right: 0px;
82 | height: 48px;
83 | border-radius: 5px;
84 | border: 1px solid white;
85 | background-color: #fafafa;
86 | padding-left: 20px;
87 | font-size: 17px;
88 | }
89 |
90 | .signup-email-input:hover {
91 | border-color: #cbcbcd;
92 | }
93 |
94 | .signup-email-input:focus {
95 | border-color: #21ce99;
96 | outline: none;
97 | }
98 |
99 | .signup-email-input {
100 | width: 95%;
101 | height: 48px;
102 | border-radius: 5px;
103 | border: 1px solid white;
104 | background-color: #fafafa;
105 | padding-left: 20px;
106 | font-size: 17px;
107 | }
108 |
109 | .signup-password-input {
110 | width: 95%;
111 | height: 48px;
112 | border-radius: 5px;
113 | border: 1px solid white;
114 | background-color: #fafafa;
115 | padding-left: 20px;
116 | font-size: 17px;
117 | }
118 | .signup-password-input:hover {
119 | border-color: #cbcbcd;
120 | }
121 |
122 | .signup-password-input:focus {
123 | border-color: #21ce99;
124 | outline: none;
125 | }
126 |
127 | .session-submit {
128 | width: 100%;
129 | height: 48px;
130 | background-color: #21ce99;
131 | font-family: "Source Sans Pro", sans-serif;
132 | color: white;
133 | border-radius: 5px;
134 | border: none;
135 | font-size: 15px;
136 | cursor: pointer;
137 | }
138 |
139 | .session-submit:hover {
140 | background-color: #1ae9aa;
141 | }
142 |
143 | .signup-visual-box {
144 | width: 50%;
145 | margin-top: 160px;
146 | }
147 |
148 | .signup-gif {
149 | width: 400px;
150 | position: fixed;
151 | bottom: 0px;
152 | }
153 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7 | # Character.create(name: 'Luke', movie: movies.first)
8 |
9 | require 'net/http'
10 | require 'json'
11 |
12 | User.destroy_all
13 | Athlete.destroy_all
14 | Stock.destroy_all
15 | Order.destroy_all
16 | Tweet.destroy_all
17 | TweetScoreSnapshot.destroy_all
18 | UserPortSnapshot.destroy_all
19 | AthletePriceSnapshot.destroy_all
20 |
21 | uri = URI("http://nba-players.herokuapp.com/players-stats/")
22 | http = Net::HTTP.new(uri.host, uri.port)
23 | req = Net::HTTP::Get.new(uri.path)
24 | resp = http.request(req)
25 |
26 | players_data = JSON.parse(resp.body)
27 |
28 | User.create({email: "demo@demo.com", first_name: "Demo", last_name: "Demo", password: "password", buying_power: 2000})
29 |
30 | players_data.each do |player|
31 | name = player["name"].split(" ")
32 |
33 | first_name = name[0]
34 | last_name = name[1]
35 |
36 | first_name.gsub!(/[^0-9A-Za-z-]/, '')
37 | last_name.gsub!(/[^0-9A-Za-z-]/, '')
38 |
39 | if(name.length > 2)
40 | third_name = name[2]
41 | third_name.gsub!(/[^0-9A-Za-z-]/, '')
42 | last_name = last_name + "_" + third_name
43 | end
44 |
45 |
46 |
47 |
48 | image_url = "http://nba-players.herokuapp.com/players/#{last_name}/#{first_name}"
49 | res = Net::HTTP.get_response(URI.parse(image_url))
50 | image_url = 'http://nba-players.herokuapp.com/players/barnes/harrison' if res.body == "Sorry, that player was not found. Please check the spelling."
51 | twitter_sentiment = 0
52 |
53 | Athlete.create({name: player["name"], team_acronym: player["team_acronym"], team_name: player["team_name"], games_played: player["games_played"], minutes_per_game: player["minutes_per_game"], field_goals_attempted_per_game: player["field_goals_attempted_per_game"], field_goals_made_per_game: player["field_goals_made_per_game"], field_goal_percentage: player["field_goal_percentage"], free_throw_percentage: player["free_throw_percentage"], three_point_attempted_per_game: player["three_point_attempted_per_game"], three_point_made_per_game: player["three_point_made_per_game"], three_point_percentage: player["three_point_percentage"], points_per_game: player["points_per_game"], offensive_rebounds_per_game: player["offensive_rebounds_per_game"], defensive_rebounds_per_game: player["defensive_rebounds_per_game"], rebounds_per_game: player["rebounds_per_game"], assists_per_game: player["assists_per_game"], steals_per_game: player["steals_per_game"], blocks_per_game: player["blocks_per_game"], turnovers_per_game: player["turnovers_per_game"], player_efficiency_rating: player["player_efficiency_rating"], twitter_sentiment: twitter_sentiment, image_url: image_url})
54 | end
55 |
56 | Athlete.all.each do |athlete|
57 | initial_price = Stock.calculate_value(athlete)
58 | Stock.create({athlete_id: athlete.id, current_price: initial_price, initial_price: initial_price, day_start_price: initial_price})
59 | end
60 |
61 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # PostgreSQL. Versions 9.1 and up are supported.
2 | #
3 | # Install the pg driver:
4 | # gem install pg
5 | # On OS X with Homebrew:
6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7 | # On OS X with MacPorts:
8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9 | # On Windows:
10 | # gem install pg
11 | # Choose the win32 build.
12 | # Install PostgreSQL and put its /bin directory on your path.
13 | #
14 | # Configure Using Gemfile
15 | # gem 'pg'
16 | #
17 | default: &default
18 | adapter: postgresql
19 | encoding: unicode
20 | # For details on connection pooling, see Rails configuration guide
21 | # http://guides.rubyonrails.org/configuring.html#database-pooling
22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23 |
24 | development:
25 | <<: *default
26 | database: trade-blitz_development
27 |
28 | # The specified database role being used to connect to postgres.
29 | # To create additional roles in postgres see `$ createuser --help`.
30 | # When left blank, postgres will use the default role. This is
31 | # the same name as the operating system user that initialized the database.
32 | #username: trade-blitz
33 |
34 | # The password associated with the postgres role (username).
35 | #password:
36 |
37 | # Connect on a TCP socket. Omitted by default since the client uses a
38 | # domain socket that doesn't need configuration. Windows does not have
39 | # domain sockets, so uncomment these lines.
40 | #host: localhost
41 |
42 | # The TCP port the server listens on. Defaults to 5432.
43 | # If your server runs on a different port number, change accordingly.
44 | #port: 5432
45 |
46 | # Schema search path. The server defaults to $user,public
47 | #schema_search_path: myapp,sharedapp,public
48 |
49 | # Minimum log levels, in increasing order:
50 | # debug5, debug4, debug3, debug2, debug1,
51 | # log, notice, warning, error, fatal, and panic
52 | # Defaults to warning.
53 | #min_messages: notice
54 |
55 | # Warning: The database defined as "test" will be erased and
56 | # re-generated from your development database when you run "rake".
57 | # Do not set this db to the same as development or production.
58 | test:
59 | <<: *default
60 | database: trade-blitz_test
61 |
62 | # As with config/secrets.yml, you never want to store sensitive information,
63 | # like your database password, in your source code. If your source code is
64 | # ever seen by anyone, they now have access to your database.
65 | #
66 | # Instead, provide the password as a unix environment variable when you boot
67 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
68 | # for a full rundown on how to provide these environment variables in a
69 | # production deployment.
70 | #
71 | # On Heroku and other platform providers, you may have a full connection URL
72 | # available as an environment variable. For example:
73 | #
74 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75 | #
76 | # You can use this database configuration with:
77 | #
78 | # production:
79 | # url: <%= ENV['DATABASE_URL'] %>
80 | #
81 | production:
82 | <<: *default
83 | database: trade-blitz_production
84 | username: trade-blitz
85 | password: <%= ENV['TRADE-BLITZ_DATABASE_PASSWORD'] %>
86 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/home.css:
--------------------------------------------------------------------------------
1 | .login-logout-button {
2 | margin-right: 35px;
3 | text-decoration: none;
4 | color: #21ce99;
5 | font-family: "Noto Sans", sans-serif;
6 | background-color: white;
7 | border: none;
8 | font-size: 16px;
9 | }
10 |
11 | .login-logout-button:hover {
12 | color: #1ae9aa;
13 | }
14 |
15 | .free-stock-result {
16 | margin-top: 70px;
17 | display: none;
18 | padding-bottom: 30px;
19 | }
20 |
21 | #player-info {
22 | background-color: white;
23 | width: 50%;
24 | margin: 0 auto;
25 | box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
26 | height: 200px;
27 | border-radius: 7px;
28 | padding: 15px;
29 | }
30 |
31 | #free-price {
32 | margin-top: 0;
33 | font-family: "Mukta", sans-serif;
34 | font-size: 34px;
35 | }
36 |
37 | #free-player-name {
38 | font-family: "Noto Sans", sans-serif;
39 | }
40 |
41 | #free-stock-button {
42 | background-color: #21ce99;
43 | color: white;
44 | border: none;
45 | width: 88px;
46 | height: 48px;
47 | font-size: 17px;
48 | border-radius: 10px;
49 | font-family: "Noto Sans", sans-serif;
50 | }
51 |
52 | #free-stock-button:hover {
53 | background-color: #1ae9aa;
54 | cursor: pointer;
55 | }
56 |
57 | #free-player-picture {
58 | max-width: 200px;
59 | margin-bottom: 0;
60 | }
61 | .free-stock-pop-up {
62 | background-color: #171718;
63 | z-index: 10;
64 | color: white;
65 | width: 65%;
66 | border-radius: 10px;
67 | margin: 0 auto;
68 | margin-top: 120px;
69 | height: 350px;
70 | box-shadow: 2px 2px 2px 1px #ccc;
71 | padding: 10px;
72 | }
73 |
74 | .home-section {
75 | text-align: center;
76 | overflow: hidden;
77 | }
78 |
79 | .free-stock-button {
80 | background-image: url("https://image.flaticon.com/icons/svg/1043/1043476.svg");
81 | height: 100px;
82 | width: 100px;
83 | margin-top: 50px;
84 | background-color: transparent;
85 | border: none;
86 | margin-left: 10px;
87 | margin-right: 10px;
88 | transition: width 0.5s ease;
89 | transition: height 0.5 ease;
90 | background-repeat: no-repeat;
91 | cursor: pointer;
92 | }
93 |
94 | #free-stock-button {
95 | box-shadow: 0 0 0 0 #1ae9aa;
96 | animation: pulse 1.5s infinite cubic-bezier(0.66, 0, 0, 1);
97 | }
98 |
99 | .free-stock-button:focus {
100 | outline: none;
101 | border: none;
102 | }
103 |
104 | .free-stock-header {
105 | color: #1ae9aa;
106 | font-family: "Knewave", cursive;
107 | font-size: 50px;
108 | }
109 |
110 | .free-stock-subtitle {
111 | font-family: "Orbitron", sans-serif;
112 | font-size: 17px;
113 | }
114 |
115 | .free-stock-button:hover {
116 | width: 120px;
117 | height: 120px;
118 | }
119 |
120 | #hide {
121 | display: none;
122 | }
123 |
124 | #show {
125 | display: block;
126 | }
127 |
128 | .user-stock-card {
129 | margin-top: 200px;
130 | overflow: hidden;
131 | }
132 |
133 | @-webkit-keyframes pulse {
134 | to {
135 | box-shadow: 0 0 0 145px #1ae9aa;
136 | }
137 | }
138 |
139 | .account-settings-menu {
140 | color: white;
141 | background-color: rgba(27, 27, 29, 1);
142 | z-index: 9999;
143 | position: fixed;
144 | width: 296px;
145 | height: 195px;
146 | right: 30px;
147 | top: 60px;
148 | box-shadow: -1px 4px 18px gray;
149 | border-radius: 3px;
150 | }
151 |
--------------------------------------------------------------------------------
/frontend/components/session_form/login_form.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { withRouter } from "react-router-dom";
3 |
4 | class LoginForm extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.state = {
8 | email: "",
9 | password: ""
10 | };
11 | this.handleSubmit = this.handleSubmit.bind(this);
12 | }
13 |
14 | componentDidMount() {
15 | this.props.receiveErrors([]);
16 | }
17 |
18 | update(field) {
19 | return e =>
20 | this.setState({
21 | [field]: e.currentTarget.value
22 | });
23 | }
24 |
25 | handleSubmit(e) {
26 | e.preventDefault();
27 | const user = Object.assign({}, this.state);
28 | this.props.processForm(user);
29 | }
30 | renderErrors() {
31 | return (
32 |
33 | {this.props.errors.map((error, i) => (
34 | -
35 | {error}
36 |
37 | ))}
38 |
39 | );
40 | }
41 |
42 | render() {
43 | return (
44 |
45 |
46 |

51 |
52 |
103 |
104 |
105 | );
106 | }
107 | }
108 |
109 | export default withRouter(LoginForm);
110 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/athlete_show.css:
--------------------------------------------------------------------------------
1 | .athlete-show-header {
2 | margin-top: 125px;
3 | margin-left: 110px;
4 | font-family: "Noto Sans", sans-serif;
5 | }
6 |
7 | .athlete-show-name h1 {
8 | margin-bottom: 10px;
9 | }
10 |
11 | .athlete-show-price {
12 | font-size: 30px;
13 | font-weight: 100;
14 | }
15 |
16 | .athlete-show-percent-change {
17 | font-size: 13px;
18 | margin-top: 10px;
19 | }
20 |
21 | .athlete-show-graph {
22 | width: 676px;
23 | height: 250px;
24 | margin-left: 60px;
25 | margin-top: 50px;
26 | }
27 |
28 | .athlete-stats-section {
29 | margin-left: 110px;
30 |
31 | margin-top: 50px;
32 | width: 676px;
33 | height: 350px;
34 | }
35 |
36 | .athlete-stats-header {
37 | font-family: "Noto Sans", sans-serif;
38 | font-weight: 100;
39 | font-size: 30px;
40 | }
41 |
42 | .athlete-show-break-line {
43 | width: 100%;
44 | display: block;
45 | border: none;
46 | height: 1px;
47 | background: #f2f2f2;
48 |
49 | margin-bottom: 40px;
50 | }
51 |
52 | .athlete-show-buy-sell {
53 | width: 275px;
54 | height: 375px;
55 | background-color: white;
56 | position: fixed;
57 | right: 100px;
58 | bottom: 90px;
59 | z-index: 999;
60 | box-shadow: -1px 4px 18px #c4c4c4;
61 | }
62 |
63 | .athlete-show-image-container {
64 | width: 150px;
65 | height: 150px;
66 | position: fixed;
67 | right: 163px;
68 | bottom: 465px;
69 | }
70 |
71 | .athlete-show-headshot {
72 | max-width: 150px;
73 | position: absolute;
74 | bottom: 0px;
75 | }
76 |
77 | .athlete-tweets-container {
78 | margin-left: 110px;
79 |
80 | margin-top: 50px;
81 | width: 676px;
82 | height: 300px;
83 | }
84 |
85 | .athlete-similar-container {
86 | margin-left: 110px;
87 | width: 676px;
88 | height: 300px;
89 | overflow-x: scroll;
90 | overflow-y: hidden;
91 | white-space: nowrap;
92 | -ms-overflow-style: none;
93 | }
94 |
95 | .add-watchlist-button {
96 | width: 227px;
97 | height: 48px;
98 | background-color: transparent;
99 | border: 1px solid #21ce99;
100 | color: #21ce99;
101 | font-family: "Noto Sans", sans-serif;
102 | font-size: 15px;
103 | position: fixed;
104 | right: 122px;
105 | bottom: 20px;
106 | }
107 |
108 | .add-watchlist-button:hover {
109 | border: none;
110 | background-color: #21ce99;
111 | color: white;
112 | cursor: pointer;
113 | }
114 |
115 | .remove-watchlist-button {
116 | width: 227px;
117 | height: 48px;
118 | background-color: #21ce99;
119 | border: none;
120 | color: white;
121 | font-family: "Noto Sans", sans-serif;
122 | font-size: 15px;
123 | position: fixed;
124 | right: 122px;
125 | bottom: 20px;
126 | }
127 |
128 | .remove-watchlist-button:hover {
129 | background-color: #1ae9aa;
130 | cursor: pointer;
131 | }
132 |
133 | .athlete-show-graph-options {
134 | display: flex;
135 | margin-top: 0px;
136 | margin-left: 70px;
137 | font-family: "Noto Sans", sans-serif;
138 | margin-bottom: 0px;
139 | }
140 |
141 | .athlete-show-graph-break-line {
142 | position: absolute;
143 | left: 120px;
144 | width: 670px;
145 | border: none;
146 | background: #f2f2f2;
147 | height: 1px;
148 | margin-top: 0px;
149 | }
150 |
151 | .graph-option-sentiment {
152 | margin-left: 20px;
153 | }
154 |
155 | .athlete-show-graph-options li:hover {
156 | color: #1ae9aa;
157 | cursor: pointer;
158 | }
159 |
160 | .option-active {
161 | color: #1ae9aa;
162 | border-bottom: 2px solid #1ae9aa;
163 | }
164 |
165 | .athlete-show-graph-options li {
166 | padding-bottom: 20px;
167 | }
168 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/user_stocks_card.css:
--------------------------------------------------------------------------------
1 | .user-stocks-card {
2 | position: fixed;
3 | top: 70px;
4 | right: 100px;
5 | bottom: 10px;
6 | width: 275px;
7 | background-color: white;
8 | overflow-y: scroll;
9 | box-shadow: -1px 4px 18px #c4c4c4;
10 | border-radius: 2px;
11 | text-align: center;
12 | padding: 0;
13 | z-index: 999;
14 | -ms-overflow-style: none;
15 | }
16 |
17 | .user-stocks-card::-webkit-scrollbar {
18 | width: 0 !important;
19 | }
20 |
21 | .user-stocks-title {
22 | font-family: "Roboto", sans-serif;
23 | font-size: 15px;
24 | float: left;
25 | font-weight: 100;
26 | margin-left: 15px;
27 | padding-top: 10px;
28 | }
29 |
30 | .user-stocks-break-line {
31 | width: 100%;
32 | display: block;
33 | border: none;
34 | height: 1px;
35 | background: #f2f2f2;
36 | background: -webkit-gradient(
37 | radial,
38 | 50% 50%,
39 | 0,
40 | 50% 50%,
41 | 350,
42 | from(#f2f2f2),
43 | to(white)
44 | );
45 | }
46 |
47 | .order-index-item {
48 | height: 60px;
49 | }
50 |
51 | .order-index-item:hover {
52 | background-color: #f5f5f5;
53 | cursor: pointer;
54 | }
55 |
56 | .order-index-item-img {
57 | max-height: 45px;
58 | float: left;
59 | border-radius: 15px;
60 | padding-top: 3px;
61 | }
62 |
63 | .order-index-item-athlete-info {
64 | display: inline-block;
65 | margin: auto;
66 | margin-top: 15px;
67 | font-size: 13px;
68 | font-weight: 100;
69 | font-family: "Roboto", sans-serif;
70 | }
71 |
72 | .order-index-item-athlete-name {
73 | font-size: 14px;
74 | margin-bottom: 0px;
75 | margin-top: 0px;
76 | font-weight: 100;
77 | }
78 |
79 | .order-index-item-athlete-team {
80 | padding-top: 5px;
81 | font-size: 11px;
82 | margin-top: 1px;
83 | font-weight: 100;
84 | }
85 | .user-stocks-item-price {
86 | float: right;
87 | margin-right: 17px;
88 | font-family: "Prompt", sans-serif;
89 | font-weight: 100;
90 | font-size: 13px;
91 | padding-top: 6px;
92 | }
93 |
94 | .user-stocks-options-button {
95 | float: right;
96 | font-size: 32px;
97 | height: 20px;
98 | background-color: white;
99 | border: none;
100 | margin-right: 20px;
101 | margin-top: -2px;
102 | }
103 |
104 | .user-stocks-options-button:hover {
105 | color: #21ce99;
106 | cursor: pointer;
107 | }
108 |
109 | .user-stocks-options-button:active,
110 | .user-stocks-options-button:focus {
111 | outline: 0;
112 | border: none;
113 | -moz-outline-style: none;
114 | }
115 |
116 | .user-stocks-options-button:active {
117 | color: #21ce99;
118 | }
119 |
120 | .user-stocks-dropdown {
121 | box-shadow: -1px 4px 18px #c4c4c4;
122 |
123 | background-color: white;
124 | width: 170px;
125 | height: 280px;
126 | position: fixed;
127 | top: 120px;
128 | z-index: 9999;
129 | right: 40px;
130 | padding: 0px;
131 | text-align: left;
132 | }
133 |
134 | .hidden-menu {
135 | display: none;
136 | }
137 |
138 | .user-stocks-options-title {
139 | font-family: "Roboto", sans-serif;
140 | font-size: 16px;
141 | float: left;
142 | font-weight: 100;
143 | margin-left: 25px;
144 | padding-top: 10px;
145 | }
146 |
147 | .user-stocks-options-break-line {
148 | width: 100%;
149 | display: block;
150 | border: none;
151 | height: 1px;
152 | background: #f2f2f2;
153 | background: -webkit-gradient(
154 | radial,
155 | 50% 50%,
156 | 0,
157 | 50% 50%,
158 | 350,
159 | from(#f2f2f2),
160 | to(white)
161 | );
162 | }
163 |
164 | .user-stocks-option {
165 | font-family: "Roboto", sans-serif;
166 | font-size: 13px;
167 | padding-left: 25px;
168 | margin-top: 22px;
169 | padding-top: 8px;
170 | padding-bottom: 8px;
171 | margin-bottom: 22px;
172 | }
173 |
174 | .user-stocks-option:hover {
175 | color: #21ce99;
176 | cursor: pointer;
177 | border-left: 2px solid #21ce99;
178 | }
179 |
--------------------------------------------------------------------------------
/frontend/components/athlete/athlete_stats.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | class AthleteStats extends React.Component {
4 | constructor(props) {
5 | super(props);
6 | this.findAthlete = this.findAthlete.bind(this);
7 | this.state = {
8 | athlete: {}
9 | };
10 | }
11 |
12 | findAthlete(athleteId) {
13 | let athlete = {};
14 | for (let i = 0; i < this.props.athletes.length; i++) {
15 | if (this.props.athletes[i].id === parseInt(athleteId)) {
16 | athlete = this.props.athletes[i];
17 | }
18 | }
19 |
20 | this.setState({
21 | athlete: athlete
22 | });
23 | }
24 |
25 | componentDidMount() {
26 | this.findAthlete(this.props.athleteId);
27 | }
28 |
29 | componentWillReceiveProps(nextProps) {
30 | if (this.props.athleteId !== nextProps.athleteId) {
31 | this.findAthlete(nextProps.athleteId);
32 | }
33 | }
34 |
35 | render() {
36 | const athleteStats = () => (
37 |
38 |
{this.state.athlete.name}
39 |
{this.state.athlete.team_name}
40 |
41 |
42 |
Games Played
43 |
44 | {this.state.athlete.games_played}
45 |
46 |
47 |
48 |
Points/Game
49 |
50 | {this.state.athlete.points_per_game}
51 |
52 |
53 |
54 |
55 |
Field Goal %
56 |
57 | {this.state.athlete.field_goal_percentage}
58 |
59 |
60 |
61 |
62 |
Efficiency Rating
63 |
64 | {this.state.athlete.player_efficiency_rating}
65 |
66 |
67 |
68 |
69 |
70 |
71 |
Rebounds/Game
72 |
73 | {this.state.athlete.rebounds_per_game}
74 |
75 |
76 |
77 |
78 |
Assists/Game
79 |
80 | {this.state.athlete.assists_per_game}
81 |
82 |
83 |
84 |
85 |
Steals/Game
86 |
87 | {this.state.athlete.steals_per_game}
88 |
89 |
90 |
91 |
92 |
Blocks/Game
93 |
94 | {this.state.athlete.blocks_per_game}
95 |
96 |
97 |
98 |
99 | );
100 | return (
101 |
102 | {Object.values(this.state.athlete).length > 0 ? athleteStats() : null}
103 |
104 | );
105 | }
106 | }
107 |
108 | export default AthleteStats;
109 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/buy_sell.css:
--------------------------------------------------------------------------------
1 | .buy-sell-options-list {
2 | display: flex;
3 | justify-content: center;
4 | padding: 0;
5 | font-family: "Noto Sans", sans-serif;
6 | margin-bottom: 0;
7 | }
8 |
9 | .buy-sell-options-list li:hover {
10 | color: #21ce99;
11 | cursor: pointer;
12 | }
13 |
14 | .options-selected {
15 | color: #21ce99;
16 | border-bottom: 3px solid #21ce99;
17 | }
18 |
19 | .buy-order-option {
20 | margin-right: 20px;
21 | padding-bottom: 15px;
22 | }
23 |
24 | .sell-order-option {
25 | margin-left: 20px;
26 | padding-bottom: 15px;
27 | }
28 |
29 | .stock-num-shares-section {
30 | display: flex;
31 | justify-content: center;
32 | font-family: "Noto Sans", sans-serif;
33 | }
34 |
35 | .shares-label {
36 | margin-top: 40px;
37 | margin: 0 auto;
38 | font-size: 14px;
39 | margin-left: 27px;
40 | }
41 |
42 | .shares-num-input {
43 | margin-left: 90px;
44 | width: 70px;
45 | width: 75px;
46 | height: 30px;
47 | border-radius: 4px;
48 | border: none;
49 | text-align: right;
50 | padding-right: 12px;
51 | background-color: #f2f2f2;
52 | }
53 |
54 | input[type="number"] {
55 | -moz-appearance: textfield;
56 | }
57 |
58 | input::-webkit-outer-spin-button,
59 | input::-webkit-inner-spin-button {
60 | -webkit-appearance: none;
61 | }
62 | .stock-price-section {
63 | display: flex;
64 | margin-top: 10px;
65 | font-family: "Noto Sans", sans-serif;
66 | font-size: 14px;
67 | }
68 |
69 | .price-label {
70 | width: 100%;
71 | justify-content: center;
72 | margin-left: 27px;
73 | margin-bottom: 10px;
74 | }
75 |
76 | .stock-price-value {
77 | display: inline-block;
78 | margin-left: 95px;
79 | font-size: 14px;
80 | }
81 |
82 | .estimated-cost-credit-label {
83 | font-family: "Noto Sans", sans-serif;
84 | font-size: 15px;
85 | position: absolute;
86 | bottom: 6px;
87 | left: 10px;
88 | }
89 |
90 | .estimated-cost-credit {
91 | margin-top: 57px;
92 | display: flex;
93 | justify-content: space-between;
94 | position: relative;
95 | }
96 |
97 | .estimated-cost-credit-value {
98 | display: inline-block;
99 | margin-left: 78px;
100 | font-family: "Noto Sans", sans-serif;
101 | font-size: 15px;
102 | position: absolute;
103 | bottom: 3px;
104 | right: 10px;
105 | }
106 |
107 | .order-submit-button {
108 | display: block;
109 | margin: 0 auto;
110 | width: 227.7px;
111 | height: 48px;
112 | margin-top: 27px;
113 | margin-bottom: 20px;
114 | font-family: "Noto Sans", sans-serif;
115 | font-size: 14px;
116 | background-color: #21ce99;
117 | border-radius: 5px;
118 | border: none;
119 | }
120 |
121 | .order-submit-button:hover {
122 | background-color: #1ae9aa;
123 | cursor: pointer;
124 | }
125 |
126 | .buying-power-shares-available {
127 | margin-top: 15px;
128 | font-family: "Noto Sans", sans-serif;
129 | font-size: 14px;
130 | text-align: center;
131 | }
132 |
133 | .order-options-break-line {
134 | margin-bottom: 25px;
135 | margin-top: 0px;
136 | width: 100%;
137 | border: none;
138 | height: 1px;
139 | background: #f2f2f2;
140 | background: -webkit-gradient(
141 | radial,
142 | 50% 50%,
143 | 0,
144 | 50% 50%,
145 | 350,
146 | from(#f2f2f2),
147 | to(white)
148 | );
149 | }
150 |
151 | .buying-power-break-line {
152 | width: 100%;
153 | border: none;
154 | height: 1px;
155 | background: #f2f2f2;
156 | background: -webkit-gradient(
157 | radial,
158 | 50% 50%,
159 | 0,
160 | 50% 50%,
161 | 350,
162 | from(#f2f2f2),
163 | to(white)
164 | );
165 | }
166 |
167 | .estimated-cost-break-line {
168 | width: 80%;
169 | border: none;
170 | height: 1px;
171 | background: #f2f2f2;
172 | background: -webkit-gradient(
173 | radial,
174 | 50% 50%,
175 | 0,
176 | 50% 50%,
177 | 350,
178 | from(#f2f2f2),
179 | to(white)
180 | );
181 | }
182 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
18 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
19 | # config.require_master_key = true
20 |
21 | # Disable serving static files from the `/public` folder by default since
22 | # Apache or NGINX already handles this.
23 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
24 |
25 | # Compress JavaScripts and CSS.
26 | config.assets.js_compressor = :uglifier
27 | # config.assets.css_compressor = :sass
28 |
29 | # Do not fallback to assets pipeline if a precompiled asset is missed.
30 | config.assets.compile = false
31 |
32 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
33 |
34 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
35 | # config.action_controller.asset_host = 'http://assets.example.com'
36 |
37 | # Specifies the header that your server uses for sending files.
38 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
39 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
40 |
41 | # Store uploaded files on the local file system (see config/storage.yml for options)
42 | config.active_storage.service = :local
43 |
44 | # Mount Action Cable outside main process or domain
45 | # config.action_cable.mount_path = nil
46 | # config.action_cable.url = 'wss://example.com/cable'
47 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
48 |
49 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
50 | # config.force_ssl = true
51 |
52 | # Use the lowest log level to ensure availability of diagnostic information
53 | # when problems arise.
54 | config.log_level = :debug
55 |
56 | # Prepend all log lines with the following tags.
57 | config.log_tags = [ :request_id ]
58 |
59 | # Use a different cache store in production.
60 | # config.cache_store = :mem_cache_store
61 |
62 | # Use a real queuing backend for Active Job (and separate queues per environment)
63 | # config.active_job.queue_adapter = :resque
64 | # config.active_job.queue_name_prefix = "trade-blitz_#{Rails.env}"
65 |
66 | config.action_mailer.perform_caching = false
67 |
68 | # Ignore bad email addresses and do not raise email delivery errors.
69 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
70 | # config.action_mailer.raise_delivery_errors = false
71 |
72 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
73 | # the I18n.default_locale when a translation cannot be found).
74 | config.i18n.fallbacks = true
75 |
76 | # Send deprecation notices to registered listeners.
77 | config.active_support.deprecation = :notify
78 |
79 | # Use default logging formatter so that PID and timestamp are not suppressed.
80 | config.log_formatter = ::Logger::Formatter.new
81 |
82 | # Use a different logger for distributed setups.
83 | # require 'syslog/logger'
84 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
85 |
86 | if ENV["RAILS_LOG_TO_STDOUT"].present?
87 | logger = ActiveSupport::Logger.new(STDOUT)
88 | logger.formatter = config.log_formatter
89 | config.logger = ActiveSupport::TaggedLogging.new(logger)
90 | end
91 |
92 | # Do not dump schema after migrations.
93 | config.active_record.dump_schema_after_migration = false
94 | end
95 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/loader.css:
--------------------------------------------------------------------------------
1 | /* Credit to Tashfeen Ahamd
2 | https://icons8.com/cssload/en/spinners/2 */
3 |
4 | .cssload-loader {
5 | display: block;
6 | width: 50px;
7 | height: 50px;
8 | margin: auto;
9 | position: absolute;
10 | top: 0;
11 | left: 0;
12 | bottom: 0;
13 | right: 0;
14 | border: 4px solid #21ce99;
15 | animation: cssload-loader 2.3s infinite ease;
16 | -o-animation: cssload-loader 2.3s infinite ease;
17 | -ms-animation: cssload-loader 2.3s infinite ease;
18 | -webkit-animation: cssload-loader 2.3s infinite ease;
19 | -moz-animation: cssload-loader 2.3s infinite ease;
20 | }
21 |
22 | .cssload-loader-inner {
23 | vertical-align: top;
24 | display: inline-block;
25 | width: 100%;
26 | background-color: #21ce99;
27 | animation: cssload-loader-inner 2.3s infinite ease-in;
28 | -o-animation: cssload-loader-inner 2.3s infinite ease-in;
29 | -ms-animation: cssload-loader-inner 2.3s infinite ease-in;
30 | -webkit-animation: cssload-loader-inner 2.3s infinite ease-in;
31 | -moz-animation: cssload-loader-inner 2.3s infinite ease-in;
32 | }
33 |
34 | @keyframes cssload-loader {
35 | 0% {
36 | transform: rotate(0deg);
37 | }
38 |
39 | 25% {
40 | transform: rotate(180deg);
41 | }
42 |
43 | 50% {
44 | transform: rotate(180deg);
45 | }
46 |
47 | 75% {
48 | transform: rotate(360deg);
49 | }
50 |
51 | 100% {
52 | transform: rotate(360deg);
53 | }
54 | }
55 |
56 | @-o-keyframes cssload-loader {
57 | 0% {
58 | transform: rotate(0deg);
59 | }
60 |
61 | 25% {
62 | transform: rotate(180deg);
63 | }
64 |
65 | 50% {
66 | transform: rotate(180deg);
67 | }
68 |
69 | 75% {
70 | transform: rotate(360deg);
71 | }
72 |
73 | 100% {
74 | transform: rotate(360deg);
75 | }
76 | }
77 |
78 | @-ms-keyframes cssload-loader {
79 | 0% {
80 | transform: rotate(0deg);
81 | }
82 |
83 | 25% {
84 | transform: rotate(180deg);
85 | }
86 |
87 | 50% {
88 | transform: rotate(180deg);
89 | }
90 |
91 | 75% {
92 | transform: rotate(360deg);
93 | }
94 |
95 | 100% {
96 | transform: rotate(360deg);
97 | }
98 | }
99 |
100 | @-webkit-keyframes cssload-loader {
101 | 0% {
102 | transform: rotate(0deg);
103 | }
104 |
105 | 25% {
106 | transform: rotate(180deg);
107 | }
108 |
109 | 50% {
110 | transform: rotate(180deg);
111 | }
112 |
113 | 75% {
114 | transform: rotate(360deg);
115 | }
116 |
117 | 100% {
118 | transform: rotate(360deg);
119 | }
120 | }
121 |
122 | @-moz-keyframes cssload-loader {
123 | 0% {
124 | transform: rotate(0deg);
125 | }
126 |
127 | 25% {
128 | transform: rotate(180deg);
129 | }
130 |
131 | 50% {
132 | transform: rotate(180deg);
133 | }
134 |
135 | 75% {
136 | transform: rotate(360deg);
137 | }
138 |
139 | 100% {
140 | transform: rotate(360deg);
141 | }
142 | }
143 |
144 | @keyframes cssload-loader-inner {
145 | 0% {
146 | height: 0%;
147 | }
148 |
149 | 25% {
150 | height: 0%;
151 | }
152 |
153 | 50% {
154 | height: 100%;
155 | }
156 |
157 | 75% {
158 | height: 100%;
159 | }
160 |
161 | 100% {
162 | height: 0%;
163 | }
164 | }
165 |
166 | @-o-keyframes cssload-loader-inner {
167 | 0% {
168 | height: 0%;
169 | }
170 |
171 | 25% {
172 | height: 0%;
173 | }
174 |
175 | 50% {
176 | height: 100%;
177 | }
178 |
179 | 75% {
180 | height: 100%;
181 | }
182 |
183 | 100% {
184 | height: 0%;
185 | }
186 | }
187 |
188 | @-ms-keyframes cssload-loader-inner {
189 | 0% {
190 | height: 0%;
191 | }
192 |
193 | 25% {
194 | height: 0%;
195 | }
196 |
197 | 50% {
198 | height: 100%;
199 | }
200 |
201 | 75% {
202 | height: 100%;
203 | }
204 |
205 | 100% {
206 | height: 0%;
207 | }
208 | }
209 |
210 | @-webkit-keyframes cssload-loader-inner {
211 | 0% {
212 | height: 0%;
213 | }
214 |
215 | 25% {
216 | height: 0%;
217 | }
218 |
219 | 50% {
220 | height: 100%;
221 | }
222 |
223 | 75% {
224 | height: 100%;
225 | }
226 |
227 | 100% {
228 | height: 0%;
229 | }
230 | }
231 |
232 | @-moz-keyframes cssload-loader-inner {
233 | 0% {
234 | height: 0%;
235 | }
236 |
237 | 25% {
238 | height: 0%;
239 | }
240 |
241 | 50% {
242 | height: 100%;
243 | }
244 |
245 | 75% {
246 | height: 100%;
247 | }
248 |
249 | 100% {
250 | height: 0%;
251 | }
252 | }
253 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # Note that this schema.rb definition is the authoritative source for your
6 | # database schema. If you need to create the application database on another
7 | # system, you should be using db:schema:load, not running all the migrations
8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 | # you'll amass, the slower it'll run and the greater likelihood for issues).
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema.define(version: 2018_10_18_030032) do
14 |
15 | # These are extensions that must be enabled in order to support this database
16 | enable_extension "plpgsql"
17 |
18 | create_table "athlete_price_snapshots", force: :cascade do |t|
19 | t.integer "athlete_id", null: false
20 | t.float "price", null: false
21 | t.datetime "created_at", null: false
22 | t.datetime "updated_at", null: false
23 | end
24 |
25 | create_table "athletes", force: :cascade do |t|
26 | t.string "name", null: false
27 | t.string "team_acronym"
28 | t.string "team_name"
29 | t.integer "games_played"
30 | t.float "minutes_per_game"
31 | t.float "field_goals_attempted_per_game"
32 | t.float "field_goals_made_per_game"
33 | t.float "field_goal_percentage"
34 | t.float "free_throw_percentage"
35 | t.float "three_point_attempted_per_game"
36 | t.float "three_point_made_per_game"
37 | t.float "three_point_percentage"
38 | t.float "points_per_game"
39 | t.float "offensive_rebounds_per_game"
40 | t.float "defensive_rebounds_per_game"
41 | t.float "rebounds_per_game"
42 | t.float "assists_per_game"
43 | t.float "steals_per_game"
44 | t.float "blocks_per_game"
45 | t.float "turnovers_per_game"
46 | t.float "player_efficiency_rating"
47 | t.float "twitter_sentiment"
48 | t.string "image_url"
49 | t.datetime "created_at", null: false
50 | t.datetime "updated_at", null: false
51 | t.index ["name"], name: "index_athletes_on_name"
52 | end
53 |
54 | create_table "orders", force: :cascade do |t|
55 | t.string "order_type"
56 | t.integer "num_share"
57 | t.string "user_id", null: false
58 | t.string "stock_id", null: false
59 | t.date "purchase_date"
60 | t.float "purchase_price"
61 | t.float "total_return"
62 | t.float "today_return"
63 | t.float "equity"
64 | t.datetime "created_at", null: false
65 | t.datetime "updated_at", null: false
66 | end
67 |
68 | create_table "stocks", force: :cascade do |t|
69 | t.integer "athlete_id", null: false
70 | t.float "current_price"
71 | t.float "initial_price"
72 | t.datetime "created_at", null: false
73 | t.datetime "updated_at", null: false
74 | t.float "day_end_price"
75 | t.float "day_start_price"
76 | t.index ["athlete_id"], name: "index_stocks_on_athlete_id"
77 | end
78 |
79 | create_table "tweet_score_snapshots", force: :cascade do |t|
80 | t.integer "athlete_id", null: false
81 | t.float "twitter_sentiment", null: false
82 | t.datetime "created_at", null: false
83 | t.datetime "updated_at", null: false
84 | end
85 |
86 | create_table "tweets", force: :cascade do |t|
87 | t.string "body"
88 | t.float "score"
89 | t.integer "athlete_id", null: false
90 | t.datetime "created_at", null: false
91 | t.datetime "updated_at", null: false
92 | end
93 |
94 | create_table "user_port_snapshots", force: :cascade do |t|
95 | t.integer "user_id", null: false
96 | t.float "port_value", null: false
97 | t.datetime "created_at", null: false
98 | t.datetime "updated_at", null: false
99 | end
100 |
101 | create_table "users", force: :cascade do |t|
102 | t.string "email", null: false
103 | t.string "password_digest", null: false
104 | t.string "first_name", null: false
105 | t.string "last_name", null: false
106 | t.string "session_token", null: false
107 | t.datetime "created_at", null: false
108 | t.datetime "updated_at", null: false
109 | t.float "buying_power", null: false
110 | t.index ["email"], name: "index_users_on_email"
111 | end
112 |
113 | create_table "watchlist_items", force: :cascade do |t|
114 | t.integer "user_id", null: false
115 | t.integer "stock_id", null: false
116 | t.datetime "created_at", null: false
117 | t.datetime "updated_at", null: false
118 | end
119 |
120 | end
121 |
--------------------------------------------------------------------------------
/frontend/components/free_stock/free_stock.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { fetchAthlete } from "./../../util/athlete_api_util";
3 | import { withRouter } from "react-router";
4 |
5 | class FreeStock extends React.Component {
6 | constructor(props) {
7 | super(props);
8 | this.state = {
9 | freeStock: {},
10 | freeAthlete: {},
11 | userId: ""
12 | };
13 | this.freeStockClicked = this.freeStockClicked.bind(this);
14 | this.freeStockReceived = this.freeStockReceived.bind(this);
15 | }
16 |
17 | componentDidMount() {
18 | this.props.fetchStocks();
19 | }
20 |
21 | freeStockClicked(e) {
22 | e.preventDefault();
23 | const randomNum = Math.floor(Math.random() * this.props.stocks.length);
24 | const freeSection = document.getElementById("free-stock-section");
25 | freeSection.classList.remove("jackInTheBox");
26 | freeSection.classList.add("lightSpeedOut");
27 | freeSection.setAttribute("id", "hide");
28 | this.setState({ freeStock: this.props.stocks[randomNum] });
29 | fetchAthlete(this.props.stocks[randomNum].athlete_id).then(athlete => {
30 | this.setState({ freeAthlete: Object.values(athlete)[0] });
31 | document.getElementById("free-stock-view").setAttribute("id", "show");
32 | });
33 | }
34 |
35 | freeStockReceived(e) {
36 | e.preventDefault();
37 | const freeStock = document.getElementById("show");
38 | freeStock.classList.remove("fadeInUp");
39 | freeStock.classList.remove("animated");
40 | freeStock.setAttribute("id", "hide");
41 | const newOrder = {
42 | num_share: 1,
43 | user_id: parseInt(this.props.match.params.user_id),
44 | stock_id: this.state.freeStock.id,
45 | purchase_price: this.state.freeStock.initial_price,
46 | order_type: "BUY"
47 | };
48 | this.props.createOrder(newOrder);
49 | this.props.removeFirstUser();
50 | this.props.history.push("/");
51 | }
52 |
53 | render() {
54 | let currentUser = this.props.currentUser;
55 | const loader = () => (
56 |
57 |
58 |
59 | );
60 |
61 | const freeStockView = () => (
62 |
63 |

69 |
70 |
71 |
72 | ${this.state.freeStock.initial_price.toFixed(2)}
73 |
74 | {this.state.freeAthlete.name}
75 |
76 |
77 |
78 |
81 |
82 |
83 | );
84 | return (
85 |
86 |
87 |

91 |
99 |
100 | {Object.values(this.state.freeStock).length > 0
101 | ? freeStockView()
102 | : loader()}
103 |
107 |
108 | WE LOVE NEW USERS!
109 |
110 |
111 | To get you started, here's a free stock on us.
112 |
113 |
118 |
123 |
128 |
129 |
130 | );
131 | }
132 | }
133 |
134 | export default withRouter(FreeStock);
135 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/greeting.css:
--------------------------------------------------------------------------------
1 | .fixed-nav-bar {
2 | background-color: white;
3 | height: 70px;
4 | position: fixed;
5 | top: 0;
6 | left: 0;
7 | right: 0;
8 | z-index: 5;
9 | }
10 |
11 | .logo-img {
12 | width: 60px;
13 | height: 60px;
14 | float: left;
15 | margin-left: 40px;
16 | }
17 |
18 | .logo-img:hover {
19 | cursor: pointer;
20 | background-color: black;
21 | opacity: 0.7 !important;
22 | filter: alpha(opacity=70) !important; /* For IE8 and earlier */
23 | box-shadow: 0 0 0px #000000 !important;
24 | }
25 |
26 | .login-signup {
27 | float: right;
28 | vertical-align: middle;
29 | margin-top: 20px;
30 | }
31 |
32 | .login-logout {
33 | margin-right: 35px;
34 | text-decoration: none;
35 | color: #21ce99;
36 | font-family: "Noto Sans", sans-serif;
37 | }
38 |
39 | .login-logout-button:hover {
40 | cursor: pointer;
41 | }
42 |
43 | .login-logout-button:active,
44 | .login-logout-button:focus {
45 | outline: 0;
46 | border: none;
47 | -moz-outline-style: none;
48 | }
49 |
50 | .login-logout:hover {
51 | color: #1ae9aa;
52 | }
53 |
54 | .hero-section {
55 | margin-top: 120px;
56 | display: flex;
57 | justify-content: space-between;
58 | align-content: center;
59 | overflow: hidden;
60 | }
61 |
62 | .hero-text {
63 | margin: 0;
64 | font-family: "Roboto", sans-serif;
65 | font-size: 60px;
66 | }
67 |
68 | .hero-visual {
69 | margin-right: 100px;
70 | }
71 |
72 | .hero-content {
73 | vertical-align: middle;
74 | margin-left: 50px;
75 | margin-top: 100px;
76 | }
77 |
78 | .hero-description {
79 | font-family: "Open Sans", sans-serif;
80 | }
81 |
82 | .hero-button {
83 | margin-top: 30px;
84 | width: 88px;
85 | height: 48px;
86 | color: white;
87 | background-color: #21ce99;
88 | font-family: "Noto Sans", sans-serif;
89 | border-radius: 7px;
90 | font-size: 15px;
91 | border: none;
92 | cursor: pointer;
93 | }
94 |
95 | .hero-button:hover {
96 | background-color: #1ae9aa;
97 | }
98 |
99 | .hero-img {
100 | width: 260px;
101 | height: 520px;
102 | }
103 |
104 | .free-text {
105 | font-family: "Roboto", sans-serif;
106 | font-size: 35px;
107 | }
108 |
109 | .free-content {
110 | margin-top: 75px;
111 | }
112 | .free-description {
113 | margin: 0;
114 | font-family: "Open Sans", sans-serif;
115 | font-size: 16px;
116 | }
117 |
118 | .free-section {
119 | margin-top: 50px;
120 | display: flex;
121 | justify-content: space-around;
122 | overflow: hidden;
123 | }
124 |
125 | .free-img {
126 | height: 520px;
127 | width: 345px;
128 | }
129 |
130 | .design-section {
131 | display: flex;
132 | justify-content: space-around;
133 | overflow: hidden;
134 | }
135 |
136 | .design-img {
137 | width: 800px;
138 | height: 800px;
139 | margin-right: -500px;
140 | }
141 |
142 | .design-content {
143 | margin-top: 100px;
144 | margin-left: 30px;
145 | }
146 |
147 | .design-text {
148 | font-family: "Roboto", sans-serif;
149 | font-size: 35px;
150 | }
151 |
152 | .design-description {
153 | margin: 0;
154 | font-family: "Open Sans", sans-serif;
155 | font-size: 16px;
156 | }
157 |
158 | .design-testimony {
159 | background-image: url("/assets/images/trade_testimony_2.png");
160 | }
161 |
162 | .quote-image {
163 | width: 13px;
164 | height: 10px;
165 | }
166 |
167 | .testimony-text {
168 | font-family: "Open Sans", sans-serif;
169 | font-size: 13px;
170 | color: gray;
171 | }
172 |
173 | .author-name {
174 | font-family: "Open Sans", sans-serif;
175 | font-size: 13px;
176 | color: gray;
177 | font-weight: bolder;
178 | }
179 |
180 | .security-section {
181 | margin-top: 50px;
182 | text-align: center;
183 | height: 800px;
184 | padding-top: 350px;
185 | overflow: hidden;
186 | transition: background-color 0.5s ease;
187 | }
188 |
189 | .security-content {
190 | padding-top: 100px;
191 | padding-bottom: 100px;
192 | }
193 |
194 | .security-text {
195 | font-family: "Roboto", sans-serif;
196 | font-size: 35px;
197 | color: white;
198 | }
199 |
200 | .security-description {
201 | margin: 0;
202 | font-family: "Open Sans", sans-serif;
203 | font-size: 16px;
204 | color: white;
205 | }
206 |
207 | .footer-icon {
208 | max-height: 40px;
209 | margin-top: 40px;
210 | margin-bottom: 40px;
211 | margin-left: 40px;
212 | margin-right: 40px;
213 | }
214 |
215 | footer {
216 | text-align: center;
217 | }
218 |
219 | .footer-text {
220 | margin-top: 40px;
221 | margin-bottom: 40px;
222 | color: gray;
223 | font-family: "Noto Sans", sans-serif;
224 | }
225 |
226 | hr {
227 | width: 70%;
228 | }
229 |
230 | .black {
231 | background-color: rgb(4, 13, 20);
232 | }
233 |
234 | .lock-icon {
235 | max-height: 61px;
236 | }
237 |
238 | .free-content {
239 | visibility: hidden;
240 | }
241 |
242 | #seen {
243 | visibility: visible;
244 | }
245 |
246 | #unseen {
247 | visibility: hidden;
248 | }
249 |
250 | .design-content {
251 | visibility: hidden;
252 | }
253 |
--------------------------------------------------------------------------------
/frontend/components/session_form/signup_form.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { withRouter } from "react-router-dom";
3 |
4 | class SignUpForm extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.state = {
8 | email: "",
9 | password: "",
10 | buying_power: 2000
11 | };
12 | this.handleSubmit = this.handleSubmit.bind(this);
13 | this.loginAsGuest = this.loginAsGuest.bind(this);
14 | }
15 |
16 | componentDidMount() {
17 | this.props.receiveErrors([]);
18 | this.props.receiveFirstUser();
19 | }
20 |
21 | loginAsGuest(e) {
22 | e.preventDefault();
23 | const emailArr = "demo@demo.com".split("");
24 | const passwordArr = "password".split("");
25 | this.setState({ email: "", password: "" }, () =>
26 | this.loginAsGuestHelper(emailArr, passwordArr)
27 | );
28 | }
29 |
30 | randomEmail() {
31 | let chars = "abcdefghijklmnopqrstuvwxyz1234567890";
32 | let string = "";
33 | for (let i = 0; i < 15; i++) {
34 | string += chars[Math.floor(Math.random() * chars.length)];
35 | }
36 | let domain = "";
37 | for (let j = 0; j < 7; j++) {
38 | domain += chars[Math.floor(Math.random() * chars.length)];
39 | }
40 | return string + "@" + domain + ".com";
41 | }
42 |
43 | loginAsGuestHelper(emailArr, passwordArr) {
44 | if (emailArr.length > 0) {
45 | this.setState(
46 | {
47 | email: this.state.email + emailArr.shift()
48 | },
49 | () => {
50 | window.setTimeout(
51 | () => this.loginAsGuestHelper(emailArr, passwordArr),
52 | 70
53 | );
54 | }
55 | );
56 | } else if (passwordArr.length > 0) {
57 | this.setState(
58 | {
59 | password: this.state.password + passwordArr.shift()
60 | },
61 | () => {
62 | window.setTimeout(
63 | () => this.loginAsGuestHelper(emailArr, passwordArr),
64 | 100
65 | );
66 | }
67 | );
68 | } else {
69 | let user = {
70 | email: this.randomEmail(),
71 | first_name: "Demo",
72 | last_name: "Demo",
73 | password: "password",
74 | buying_power: 2000
75 | };
76 | this.props.processForm(user);
77 | }
78 | }
79 |
80 | update(field) {
81 | return e =>
82 | this.setState({
83 | [field]: e.currentTarget.value
84 | });
85 | }
86 |
87 | handleSubmit(e) {
88 | e.preventDefault();
89 | const user = Object.assign({}, this.state);
90 | this.props.processForm(user);
91 | }
92 | renderErrors() {
93 | return (
94 |
95 | {this.props.errors.map((error, i) => (
96 | -
97 | {error}
98 |
99 | ))}
100 |
101 | );
102 | }
103 |
104 | render() {
105 | return (
106 |
107 |
this.props.history.push("/")}
110 | >
111 |

115 |
116 |
117 |
182 |
183 | {this.renderErrors()}
184 |
185 |

190 |
191 |
192 |
193 | );
194 | }
195 | }
196 |
197 | export default withRouter(SignUpForm);
198 |
--------------------------------------------------------------------------------
/frontend/components/home/user_stocks/user_stocks_index.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import UserStocksItem from "./user_stocks_item";
3 | import { fetchAthlete } from "./../../../util/athlete_api_util";
4 | import { withRouter, Redirect } from "react-router-dom";
5 |
6 | class UserStocksIndex extends React.Component {
7 | constructor(props) {
8 | super(props);
9 | this.state = {
10 | normalizedOrders: []
11 | };
12 | this.showMenu = this.showMenu.bind(this);
13 | this.handleClick = this.handleClick.bind(this);
14 | this.findAthlete = this.findAthlete.bind(this);
15 | this.findStock = this.findStock.bind(this);
16 | this.normalizeOrders = this.normalizeOrders.bind(this);
17 | this.findAthleteFromStockId = this.findAthleteFromStockId.bind(this);
18 | this.findStockFromId = this.findStockFromId.bind(this);
19 | }
20 |
21 | showMenu() {
22 | const menu = document.getElementsByClassName("user-stocks-dropdown")[0];
23 | menu.classList.toggle("hidden-menu");
24 | }
25 |
26 | componentDidMount() {
27 | document.addEventListener("mousedown", this.handleClick, false);
28 | document
29 | .getElementsByClassName("user-stocks-dropdown")[0]
30 | .addEventListener("scroll", this.handleClickOutside);
31 | this.user;
32 | }
33 |
34 | componentWillReceiveProps(nextProps) {
35 | this.normalizeOrders();
36 | }
37 |
38 | componentWillUnmount() {
39 | document.removeEventListener("mousedown", this.handleClick, false);
40 | document
41 | .getElementsByClassName("user-stocks-dropdown")[0]
42 | .removeEventListener("scroll", this.handleClickOutside);
43 | }
44 |
45 | handleClick(e) {
46 | const button = document.getElementById("user-stocks-options-btn");
47 | if (
48 | document
49 | .getElementsByClassName("user-stocks-dropdown")[0]
50 | .contains(e.target) ||
51 | button.contains(e.target)
52 | ) {
53 | return;
54 | }
55 |
56 | this.handleClickOutside();
57 | }
58 |
59 | findAthlete(order) {
60 | const stock = this.findStock(order);
61 | const athletes = this.props.athletes;
62 | let athlete = {};
63 | for (let i = 0; i < athletes.length; i++) {
64 | if (athletes[i].id === stock.athlete_id) {
65 | athlete = athletes[i];
66 | }
67 | }
68 | return athlete;
69 | }
70 |
71 | findStock(order) {
72 | const stockId = parseInt(order.stock_id);
73 | const stocks = this.props.stocks;
74 | let stock = {};
75 |
76 | for (let i = 0; i < stocks.length; i++) {
77 | if (stocks[i].id === stockId) {
78 | stock = stocks[i];
79 | }
80 | }
81 | return stock;
82 | }
83 |
84 | normalizeOrders() {
85 | let buyOrders = [];
86 | let sellOrders = [];
87 |
88 | let userAthletes = [];
89 | let normalizedOrders = [];
90 |
91 | for (let i = 0; i < this.props.orders.length; i++) {
92 | let order = this.props.orders[i];
93 | let athlete = this.findAthlete(order);
94 | if (order.order_type === "BUY") {
95 | if (userAthletes.indexOf(athlete) !== -1) {
96 | let index = userAthletes.indexOf(athlete);
97 | normalizedOrders[index].num_share += order.num_share;
98 | } else {
99 | userAthletes.push(athlete);
100 | normalizedOrders.push(order);
101 | }
102 | } else {
103 | let index = userAthletes.indexOf(athlete);
104 | normalizedOrders[index].num_share -= order.num_share;
105 | }
106 | }
107 |
108 | let result = [];
109 | for (let j = 0; j < normalizedOrders.length; j++) {
110 | if (normalizedOrders[j].num_share > 0) {
111 | result.push(normalizedOrders[j]);
112 | }
113 | }
114 | this.setState({
115 | normalizedOrders: result
116 | });
117 | }
118 |
119 | handleClickOutside() {
120 | const menu = document.getElementsByClassName("user-stocks-dropdown")[0];
121 | if (menu.classList.contains("hidden-menu")) {
122 | } else {
123 | menu.classList.toggle("hidden-menu");
124 | }
125 | }
126 |
127 | findStockFromId(id) {
128 | for (let i = 0; i < this.props.stocks.length; i++) {
129 | if (this.props.stocks[i].id === id) {
130 | return this.props.stocks[i];
131 | }
132 | }
133 | return {};
134 | }
135 |
136 | findAthleteFromStockId(id) {
137 | for (let i = 0; i < this.props.athletes.length; i++) {
138 | if (this.props.athletes[i].id === this.findStockFromId(id).athlete_id) {
139 | return this.props.athletes[i];
140 | }
141 | }
142 | return {};
143 | }
144 |
145 | render() {
146 | return (
147 |
148 |
149 | Display
150 |
151 |
152 | - Last Price
153 | - Percent Change
154 | - Your Equity
155 | - Today's Return
156 |
157 |
158 | Stocks
159 |
166 |
167 |
168 | {this.state.normalizedOrders.map(order => {
169 | return (
170 |
175 | );
176 | })}
177 | Watchlist
178 |
179 | {this.props.watchlistItems.map(item => {
180 | return (
181 |
186 | );
187 | })}
188 |
189 |
190 | );
191 | }
192 | }
193 |
194 | export default withRouter(UserStocksIndex);
195 |
--------------------------------------------------------------------------------