Class: LWAC::Sample
- Inherits:
-
Object
- Object
- LWAC::Sample
- Defined in:
- lib/lwac/shared/data_types.rb
Overview
Holds all data on a given sample, which covers:
* A list of Links that are in the sample
* Sample start/end times
Will throw errors if one tries to edit it whilst closed.
Instance Attribute Summary collapse
-
#approx_filesize ⇒ Object
Returns the value of attribute approx_filesize.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_dp_id ⇒ Object
Returns the value of attribute last_dp_id.
-
#pending ⇒ Object
Returns the value of attribute pending.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#sample_end_time ⇒ Object
Returns the value of attribute sample_end_time.
-
#sample_start_time ⇒ Object
readonly
Returns the value of attribute sample_start_time.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #close_sample ⇒ Object
-
#complete? ⇒ Boolean
Has this sample got any links pending?.
-
#initialize(id, size, start_id = 0, pending_links = Set.new, permit_sampling = false, sample_start_time = Time.now) ⇒ Sample
constructor
A new instance of Sample.
- #link_complete(filesize) ⇒ Object
-
#open? ⇒ Boolean
Has the sample been opened?.
-
#open_sample ⇒ Object
Start sampling.
- #remaining ⇒ Object
-
#to_s ⇒ Object
Nicer output.
Constructor Details
#initialize(id, size, start_id = 0, pending_links = Set.new, permit_sampling = false, sample_start_time = Time.now) ⇒ Sample
Returns a new instance of Sample.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/lwac/shared/data_types.rb', line 210 def initialize(id, size, start_id=0, pending_links=Set.new, permit_sampling=false, sample_start_time=Time.now) @id = id @size = size.to_i # Number of datapoints in sample (read from db) @progress = 0 # How many links have been done in total @pending = pending_links # links read from db non-contiguously and simply not used yet @last_dp_id = start_id # Where to start reading next IDs # cumulative filesize of all data in sample @approx_filesize = 0 @permit_sampling = permit_sampling @sample_start_time = sample_start_time @sample_end_time = nil end |
Instance Attribute Details
#approx_filesize ⇒ Object
Returns the value of attribute approx_filesize.
208 209 210 |
# File 'lib/lwac/shared/data_types.rb', line 208 def approx_filesize @approx_filesize end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
207 208 209 |
# File 'lib/lwac/shared/data_types.rb', line 207 def id @id end |
#last_dp_id ⇒ Object
Returns the value of attribute last_dp_id.
208 209 210 |
# File 'lib/lwac/shared/data_types.rb', line 208 def last_dp_id @last_dp_id end |
#pending ⇒ Object
Returns the value of attribute pending.
208 209 210 |
# File 'lib/lwac/shared/data_types.rb', line 208 def pending @pending end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
207 208 209 |
# File 'lib/lwac/shared/data_types.rb', line 207 def progress @progress end |
#sample_end_time ⇒ Object
Returns the value of attribute sample_end_time.
208 209 210 |
# File 'lib/lwac/shared/data_types.rb', line 208 def sample_end_time @sample_end_time end |
#sample_start_time ⇒ Object (readonly)
Returns the value of attribute sample_start_time.
207 208 209 |
# File 'lib/lwac/shared/data_types.rb', line 207 def sample_start_time @sample_start_time end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
207 208 209 |
# File 'lib/lwac/shared/data_types.rb', line 207 def size @size end |
Instance Method Details
#close_sample ⇒ Object
233 234 235 236 |
# File 'lib/lwac/shared/data_types.rb', line 233 def close_sample @permit_sampling = false @sample_end_time = Time.now end |
#complete? ⇒ Boolean
Has this sample got any links pending?
239 240 241 |
# File 'lib/lwac/shared/data_types.rb', line 239 def complete? @progress >= @size end |
#link_complete(filesize) ⇒ Object
248 249 250 251 |
# File 'lib/lwac/shared/data_types.rb', line 248 def link_complete(filesize) @approx_filesize += (filesize || 0) @progress += 1 end |
#open? ⇒ Boolean
Has the sample been opened?
244 245 246 |
# File 'lib/lwac/shared/data_types.rb', line 244 def open? @permit_sampling end |
#open_sample ⇒ Object
Start sampling.
228 229 230 231 |
# File 'lib/lwac/shared/data_types.rb', line 228 def open_sample @permit_sampling = true @sample_start_time = Time.now end |
#remaining ⇒ Object
253 254 255 |
# File 'lib/lwac/shared/data_types.rb', line 253 def remaining @size - @progress end |
#to_s ⇒ Object
Nicer output
258 259 260 |
# File 'lib/lwac/shared/data_types.rb', line 258 def to_s "<Sample #{@id}, #{@progress}/#{@size} [#{open? ? "open":"closed"}, #{complete? ? "complete":"incomplete"}]>" end |