mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Add the ability to "rollup" values in a time series (#554)
* Clean up time series models * Add value group rollup class for summarizing hierarchical data * Integrate new classes * Update UI to use new patterns * Update D3 charts to expect new data format * Clean up account model * More cleanup * Money improvements * Use new money fields * Remove invalid fixture data to avoid orphaned accountables * Update time series to work better with collections * Fix tests and UI bugs
This commit is contained in:
parent
0a8518506c
commit
f904d9d062
34 changed files with 687 additions and 391 deletions
32
app/models/time_series/value.rb
Normal file
32
app/models/time_series/value.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
class TimeSeries::Value
|
||||
include Comparable
|
||||
|
||||
attr_accessor :trend
|
||||
attr_reader :value, :date, :original
|
||||
|
||||
def initialize(obj)
|
||||
@original = obj[:original] || obj
|
||||
|
||||
if obj.is_a?(Hash)
|
||||
@date = obj[:date]
|
||||
@value = obj[:value]
|
||||
else
|
||||
@date = obj.date
|
||||
@value = obj.value
|
||||
end
|
||||
|
||||
validate_input
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
result = date <=> other.date
|
||||
result = value <=> other.value if result == 0
|
||||
result
|
||||
end
|
||||
|
||||
private
|
||||
def validate_input
|
||||
raise ArgumentError, "Date is required" unless @date.is_a?(Date)
|
||||
raise ArgumentError, "Money or Numeric value is required" unless @value.is_a?(Money) || @value.is_a?(Numeric)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue