Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem 'sidekiq'
gem 'carrierwave', '~> 1.0'
gem 'slim'
gem 'aasm'
gem 'chartkick'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ GEM
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
chartkick (2.2.4)
coderay (1.1.1)
concurrent-ruby (1.0.5)
connection_pool (2.2.1)
Expand Down Expand Up @@ -257,6 +258,7 @@ DEPENDENCIES
binding_of_caller
byebug
carrierwave (~> 1.0)
chartkick
dry-struct
dry-validation
jbuilder (~> 2.5)
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
//
//= require rails-ujs
//= require_tree .
//= require highcharts
//= require chartkick
14 changes: 14 additions & 0 deletions app/controllers/api/charts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Api
class ChartsController < ApplicationController
def games_summary
@user = User.find(params[:user_id])

total_profit = 0
result = @user.games.order_by(:started_at).map do |g|
total_profit += g.current_profit
total_profit
end
render json: [{ name: 'All Games', data: result }]
end
end
end
2 changes: 1 addition & 1 deletion app/forms/user/create_new_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_tourn_summaries
end

def run_tourn_parser_worker(tourn_summary_id)
Tournament::ParseWorker.perform_async(tourn_summary_id: tourn_summary_id)
Tournament::ParseWorker.perform_async(tourn_summary_id)
end
end
end
17 changes: 17 additions & 0 deletions app/helpers/api/charts_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Api
module ChartsHelper
def games_summary_chart
line_chart games_summary_api_charts_path(user_id: @user.id), library: {
title: { text: 'Profit' },
yAxis: {
crosshair: true,
title: { text: 'Profit value' }
},
xAxis: {
crosshair: true,
title: { text: 'Number of games' }
}
}
end
end
end
8 changes: 8 additions & 0 deletions app/models/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@
class Game < ApplicationRecord
belongs_to :tourn_summary
belongs_to :user

def total_buy_in
buy_in + rake
end

def current_profit
reward - total_buy_in
end
end
8 changes: 5 additions & 3 deletions app/views/users/show.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
h1
| Hello
= @user.nickname
h1
| Hello
= @user.nickname
.content
= games_summary_chart
12 changes: 7 additions & 5 deletions app/workers/tournament/parse_worker.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class ParseWorker
include Sidekiq::Worker
module Tournament
class ParseWorker
include Sidekiq::Worker

def perform(tourn_summary_id)
tourn_summary = TournSummary.find(tourn_summary_id)
Tournament::Processor.new(tourn_summary).call
def perform(tourn_summary_id)
tourn_summary = TournSummary.find(tourn_summary_id)
Tournament::Processor.new(tourn_summary).call
end
end
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
mount Sidekiq::Web => '/sidekiq'

resources :users, only: [:new, :create, :show]
namespace :api do
resource :charts, only: [] do
get :games_summary
end
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

root to: 'users#new'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prop-types": "^15.5.10",
"rails-erb-loader": "^5.0.2",
"react": "^15.6.1",
"react-bootstrap": "^0.31.3",
"react-dom": "^15.6.1",
"resolve-url-loader": "^2.1.0",
"sass-loader": "^6.0.6",
Expand Down
402 changes: 402 additions & 0 deletions vendor/assets/javascripts/highcharts.js

Large diffs are not rendered by default.

77 changes: 75 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,13 @@ babel-register@^6.24.1:
mkdirp "^0.5.1"
source-map-support "^0.4.2"

babel-runtime@^6.11.6:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.11.0"

babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b"
Expand Down Expand Up @@ -1080,6 +1087,10 @@ clap@^1.0.9:
dependencies:
chalk "^1.1.3"

classnames@^2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d"

cliui@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1"
Expand Down Expand Up @@ -1565,6 +1576,10 @@ dns-txt@^2.0.2:
dependencies:
buffer-indexof "^1.0.0"

dom-helpers@^3.2.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.2.1.tgz#3203e07fed217bd1f424b019735582fc37b2825a"

domain-browser@^1.1.1:
version "1.1.7"
resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc"
Expand Down Expand Up @@ -2292,7 +2307,7 @@ interpret@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.3.tgz#cbc35c62eeee73f19ab7b10a801511401afc0f90"

invariant@^2.2.0, invariant@^2.2.2:
invariant@^2.1.0, invariant@^2.2.0, invariant@^2.2.1, invariant@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360"
dependencies:
Expand Down Expand Up @@ -2564,6 +2579,10 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.3.6"

keycode@^2.1.2:
version "2.1.9"
resolved "https://registry.yarnpkg.com/keycode/-/keycode-2.1.9.tgz#964a23c54e4889405b4861a5c9f0480d45141dfa"

kind-of@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-2.0.1.tgz#018ec7a4ce7e3a86cb9141be519d24c8faa981b5"
Expand Down Expand Up @@ -3779,7 +3798,13 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.10:
prop-types-extra@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/prop-types-extra/-/prop-types-extra-1.0.1.tgz#a57bd4810e82d27a3ff4317ecc1b4ad005f79a82"
dependencies:
warning "^3.0.0"

prop-types@^15.5.10, prop-types@^15.5.8:
version "15.5.10"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154"
dependencies:
Expand Down Expand Up @@ -3883,6 +3908,22 @@ rc@^1.1.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-bootstrap@^0.31.3:
version "0.31.3"
resolved "https://registry.yarnpkg.com/react-bootstrap/-/react-bootstrap-0.31.3.tgz#db2b7d45b00b5dac1ab8b6de3dd97feb3091b849"
dependencies:
babel-runtime "^6.11.6"
classnames "^2.2.5"
dom-helpers "^3.2.0"
invariant "^2.2.1"
keycode "^2.1.2"
prop-types "^15.5.10"
prop-types-extra "^1.0.1"
react-overlays "^0.7.0"
react-prop-types "^0.4.0"
uncontrollable "^4.1.0"
warning "^3.0.0"

react-dom@^15.6.1:
version "15.6.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.1.tgz#2cb0ed4191038e53c209eb3a79a23e2a4cf99470"
Expand All @@ -3892,6 +3933,22 @@ react-dom@^15.6.1:
object-assign "^4.1.0"
prop-types "^15.5.10"

react-overlays@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/react-overlays/-/react-overlays-0.7.0.tgz#531898ff566c7e5c7226ead2863b8cf9fbb5a981"
dependencies:
classnames "^2.2.5"
dom-helpers "^3.2.0"
prop-types "^15.5.8"
react-prop-types "^0.4.0"
warning "^3.0.0"

react-prop-types@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/react-prop-types/-/react-prop-types-0.4.0.tgz#f99b0bfb4006929c9af2051e7c1414a5c75b93d0"
dependencies:
warning "^3.0.0"

react@^15.6.1:
version "15.6.1"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.1.tgz#baa8434ec6780bde997cdc380b79cd33b96393df"
Expand Down Expand Up @@ -3973,6 +4030,10 @@ regenerator-runtime@^0.10.0:
version "0.10.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"

regenerator-runtime@^0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1"

[email protected]:
version "0.9.11"
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.9.11.tgz#3a7d067520cb7b7176769eb5ff868691befe1283"
Expand Down Expand Up @@ -4636,6 +4697,12 @@ uid-number@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"

uncontrollable@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/uncontrollable/-/uncontrollable-4.1.0.tgz#e0358291252e1865222d90939b19f2f49f81c1a9"
dependencies:
invariant "^2.1.0"

uniq@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
Expand Down Expand Up @@ -4728,6 +4795,12 @@ [email protected]:
dependencies:
indexof "0.0.1"

warning@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
dependencies:
loose-envify "^1.0.0"

watchpack@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.4.0.tgz#4a1472bcbb952bd0a9bb4036801f954dfb39faac"
Expand Down