-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests (belatedly), web3. Model portfolios - they have "nil" use…
…rs. Beginnings of "copy" functionality. Added BalancerPool model. Added PriceHistory model and seeded with actual price history.
- Loading branch information
1 parent
94fe89d
commit abe6db6
Showing
33 changed files
with
751 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--colour | ||
--format doc | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function render_model_graphs() { | ||
$('.graph_data').each(function(i, obj) { | ||
var row_id = obj.id + "_val"; | ||
var label_id = obj.id + "_label"; | ||
var data = {'data': $('#' + row_id).val(), 'label': $('#' + label_id).val()}; | ||
|
||
jQuery.ajax({url:'/graphs.js', | ||
data: data, | ||
type: "POST", | ||
success: function(data) { | ||
Highcharts.chart(obj.id, JSON.parse(data)); | ||
}, | ||
error: function() { alert('Oh noes!'); }, | ||
async: false}); | ||
}); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class GraphsController < ApplicationController | ||
respond_to :js | ||
|
||
def create | ||
data = Hash.new | ||
data[:chart] = {:type => 'pie'} | ||
data[:title] = {:text => params[:label]} | ||
data[:subtitle] = {:text => ''} | ||
data[:plotOptions] = {:series => {:dataLabels => {:enabled => true, :distance => -30, :format => '{point.name}<br>{point.y:.1f}%'}}} | ||
|
||
sections = [] | ||
|
||
slices = params[:data].split('/') | ||
slices.each do |div| | ||
fields = div.split(':') | ||
yval = fields[1].to_f | ||
if yval > 0 | ||
sections.push({:name => fields[0], :y => yval, :drilldown => nil}) | ||
end | ||
end | ||
|
||
data[:series] = [{:name => '', | ||
:colorByPoint => true, | ||
:data => sections}] | ||
|
||
respond_to do |format| | ||
format.js { render :json => data.to_json.html_safe } | ||
format.html { redirect_to root_path } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,7 @@ class StaticPagesController < ApplicationController | |
|
||
def home | ||
end | ||
|
||
def test | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# == Schema Information | ||
# | ||
# Table name: balancer_pools | ||
# | ||
# id :bigint not null, primary key | ||
# pie_id :bigint | ||
# uma_address :string(42) | ||
# bp_address :string(42) | ||
# uma_expiry :date | ||
# allocation :text | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class BalancerPool < ApplicationRecord | ||
belongs_to :pie | ||
|
||
validates_length_of :uma_address, :bp_address, :is => 42, :allow_nil => true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# == Schema Information | ||
# | ||
# Table name: price_histories | ||
# | ||
# id :bigint not null, primary key | ||
# coin :string(8) not null | ||
# date :date not null | ||
# price :decimal(8, 2) | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class PriceHistory < ApplicationRecord | ||
validates_presence_of :coin, :date, :price | ||
validates_length_of :coin, :maximum => 8 | ||
validates_numericality_of :price, :greater_than => 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%div.graph_data{:id => model, :style => 'width:200px; height:200px;'} | ||
- res = [] | ||
- data.keys.each do |key| | ||
- res.push("#{key}:#{data[key]}") | ||
= hidden_field_tag :graph, res.join("/"), :id => "#{model}_val" | ||
= hidden_field_tag :label, label, :id => "#{model}_label" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
- provide(:title, t('models')) | ||
= render 'layouts/pie_header' | ||
= javascript_include_tag "https://code.highcharts.com/highcharts.js" | ||
= javascript_include_tag "https://code.highcharts.com/modules/data.js" | ||
.c_customer.afclr | ||
.wrapper | ||
.re_main.afclr | ||
.ab_head.afclr | ||
%h1= t('models') | ||
.in_iner_pag.afclr | ||
%table.table.table-striped | ||
%tr | ||
%th Name | ||
%th % Gold | ||
%th % Crypto | ||
%th % Cash | ||
%th % Equities | ||
%th 3m Return | ||
%th 6m Return | ||
%th | ||
- @models.each do |model| | ||
%tr | ||
%td= model.name | ||
%td= model.pct_gold | ||
%td= model.pct_crypto | ||
%td= model.pct_cash | ||
%td= model.pct_equities | ||
%td | ||
%td | ||
%td | ||
= link_to t('copy'), copy_py_path(:id => 1, :src => model.id), :class => 'btn btn-secondary', :method => :put | ||
%tr | ||
%td | ||
%td | ||
- if model.pct_gold > 0 | ||
= render :partial => 'table_graph', :locals => {:model => "#{model.id}_gold", :label => 'Gold', :data => {'PAXG' => 100}} | ||
%td | ||
- if model.pct_crypto > 0 | ||
= render :partial => 'table_graph', :locals => {:model => "#{model.id}_crypto", :label => 'Crypto', :data => {model.crypto.currency_name(0) => model.crypto.pct_curr1, model.crypto.currency_name(1) => model.crypto.pct_curr2, model.crypto.currency_name(2) => model.crypto.pct_curr3}} | ||
%td | ||
- if model.pct_cash > 0 | ||
= render :partial => 'table_graph', :locals => {:model => "#{model.id}_cash", :label => 'Cash', :data => {model.stable_coin.currency_name(0) => model.stable_coin.pct_curr1, model.stable_coin.currency_name(1) => model.stable_coin.pct_curr2, model.stable_coin.currency_name(2) => model.stable_coin.pct_curr3}} | ||
%td | ||
- if model.pct_equities > 0 | ||
= render :partial => 'table_graph', :locals => {:model => "#{model.id}_equity", :label => 'Equity', :data => model.equity_graph_data} | ||
%td | ||
%td | ||
%td | ||
:javascript | ||
$(document).ready(function(e) { | ||
render_model_graphs(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.