Class: Timeline
- Inherits:
-
Object
- Object
- Timeline
- Defined in:
- service/showback.rb
Overview
Class for compiling all history records from all records sources into one readable timeline
Defined Under Namespace
Classes: FinalRecord, InitRecord
Constant Summary collapse
- SOURCES =
Should be generated automaticaly in the future
[ # Should be generated automaticaly in the future Records, SnapshotRecords, TrafficRecords, DiskRecords ]
Instance Attribute Summary collapse
-
#compiled ⇒ Object
readonly
Returns the value of attribute compiled.
-
#etime ⇒ Object
readonly
Returns the value of attribute etime.
-
#group_by_day ⇒ Object
readonly
Returns the value of attribute group_by_day.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#stime ⇒ Object
readonly
Returns the value of attribute stime.
-
#timeline ⇒ Object
readonly
Returns the value of attribute timeline.
-
#vm ⇒ Object
readonly
Returns the value of attribute vm.
Instance Method Summary collapse
-
#compile ⇒ Object
Compiles timeline: obtains events from sources and filters useless events sorts events filters again.
-
#init ⇒ Object
Generates initial state.
-
#initialize(vm, stime, etime, group_by_day = false) ⇒ Timeline
constructor
Initializes timeline - collects record sources(yet staticly) and stores entry vars.
Constructor Details
#initialize(vm, stime, etime, group_by_day = false) ⇒ Timeline
Initializes timeline - collects record sources(yet staticly) and stores entry vars
13 14 15 16 17 |
# File 'service/showback.rb', line 13 def initialize vm, stime, etime, group_by_day = false @vm, @stime, @etime, @group_by_day = vm, stime, etime, group_by_day @sources = SOURCES @compiled = false end |
Instance Attribute Details
#compiled ⇒ Object (readonly)
Returns the value of attribute compiled.
6 7 8 |
# File 'service/showback.rb', line 6 def compiled @compiled end |
#etime ⇒ Object (readonly)
Returns the value of attribute etime.
6 7 8 |
# File 'service/showback.rb', line 6 def etime @etime end |
#group_by_day ⇒ Object (readonly)
Returns the value of attribute group_by_day.
6 7 8 |
# File 'service/showback.rb', line 6 def group_by_day @group_by_day end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
6 7 8 |
# File 'service/showback.rb', line 6 def sources @sources end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'service/showback.rb', line 6 def state @state end |
#stime ⇒ Object (readonly)
Returns the value of attribute stime.
6 7 8 |
# File 'service/showback.rb', line 6 def stime @stime end |
#timeline ⇒ Object (readonly)
Returns the value of attribute timeline.
6 7 8 |
# File 'service/showback.rb', line 6 def timeline @timeline end |
#vm ⇒ Object (readonly)
Returns the value of attribute vm.
6 7 8 |
# File 'service/showback.rb', line 6 def vm @vm end |
Instance Method Details
#compile ⇒ Object
Compiles timeline:
obtains events from sources and filters useless events
sorts events
filters again
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'service/showback.rb', line 23 def compile records = @sources.inject([]) do | r, source | r.concat source.tl_filter( # Filtering useless events(e.g. unfinished TrafficRecord) source.new(@vm.id).find(@stime, @etime).all # Seeking for all events happend between stime and etime ) end records.map! do | rec | # Some of Records need to be processed extra to become sortable and usable # for example SnapshotRecords are holding both creation and deletion time, # so each SnapshotRecord will be splitted into SnapshotCreateRecord and SnapshotDeleteRecord rec.sortable end records.flatten! @timeline = records.sort_by { |rec| rec.sorter } # Sorting records by time sorter(.sorter method returns timestamp to be used as sorter) @timeline.select! { |rec| rec.sorter.between?(@stime, @etime) } # Filtering records again init # Generating initial state init_rec = InitRecord.new @stime, @state @timeline.unshift init_rec @timeline << FinalRecord.new(@etime) @compiled = true self end |
#init ⇒ Object
Generates initial state
53 54 55 56 57 |
# File 'service/showback.rb', line 53 def init @state = @sources.inject({}) do | r, source | r.merge source.new(@vm.id).init_state(@stime) end end |