mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 21:15:19 +02:00
Add Live Data to Account Page (#464)
* Add trends, time series, seed data * Remove test data * Replace old view values with helpers * Fix tooltip bugs in D3 chart * Fix tests * Fix smoke test * Add CRUD actions for valuations * Scaffold out inline editing with Turbo
This commit is contained in:
parent
298b50a909
commit
b5b2d335fd
28 changed files with 512 additions and 167 deletions
26
app/models/trend.rb
Normal file
26
app/models/trend.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
class Trend
|
||||
attr_reader :current, :previous
|
||||
|
||||
def initialize(current, previous)
|
||||
@current = current
|
||||
@previous = previous
|
||||
end
|
||||
|
||||
def direction
|
||||
return "flat" unless @previous
|
||||
return "up" if @current > @previous
|
||||
return "down" if @current < @previous
|
||||
"flat"
|
||||
end
|
||||
|
||||
def amount
|
||||
return 0 if @previous.nil?
|
||||
@current - @previous
|
||||
end
|
||||
|
||||
def percent
|
||||
return 0 if @previous.nil?
|
||||
return Float::INFINITY if @previous == 0
|
||||
((@current - @previous).abs / @previous.to_f * 100).round(1)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue