Class: LWAC::Sample

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_filesizeObject

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

#idObject (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_idObject

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

#pendingObject

Returns the value of attribute pending.



208
209
210
# File 'lib/lwac/shared/data_types.rb', line 208

def pending
  @pending
end

#progressObject (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_timeObject

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_timeObject (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

#sizeObject (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_sampleObject



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?

Returns:

  • (Boolean)


239
240
241
# File 'lib/lwac/shared/data_types.rb', line 239

def complete?
  @progress >= @size
end


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?

Returns:

  • (Boolean)


244
245
246
# File 'lib/lwac/shared/data_types.rb', line 244

def open?
  @permit_sampling
end

#open_sampleObject

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

#remainingObject



253
254
255
# File 'lib/lwac/shared/data_types.rb', line 253

def remaining
  @size - @progress
end

#to_sObject

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