Class: PolarAccesslinkApiGem::Sleep

Inherits:
Object
  • Object
show all
Defined in:
lib/polar-accesslink-api-gem/models/sleep.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Sleep

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 163

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `PolarAccesslinkApiGem::Sleep` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `PolarAccesslinkApiGem::Sleep`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'polar_user')
    self.polar_user = attributes[:'polar_user']
  end

  if attributes.key?(:'date')
    self.date = attributes[:'date']
  end

  if attributes.key?(:'sleep_start_time')
    self.sleep_start_time = attributes[:'sleep_start_time']
  end

  if attributes.key?(:'sleep_end_time')
    self.sleep_end_time = attributes[:'sleep_end_time']
  end

  if attributes.key?(:'device_id')
    self.device_id = attributes[:'device_id']
  end

  if attributes.key?(:'continuity')
    self.continuity = attributes[:'continuity']
  end

  if attributes.key?(:'continuity_class')
    self.continuity_class = attributes[:'continuity_class']
  end

  if attributes.key?(:'light_sleep')
    self.light_sleep = attributes[:'light_sleep']
  end

  if attributes.key?(:'deep_sleep')
    self.deep_sleep = attributes[:'deep_sleep']
  end

  if attributes.key?(:'rem_sleep')
    self.rem_sleep = attributes[:'rem_sleep']
  end

  if attributes.key?(:'unrecognized_sleep_stage')
    self.unrecognized_sleep_stage = attributes[:'unrecognized_sleep_stage']
  end

  if attributes.key?(:'sleep_score')
    self.sleep_score = attributes[:'sleep_score']
  end

  if attributes.key?(:'total_interruption_duration')
    self.total_interruption_duration = attributes[:'total_interruption_duration']
  end

  if attributes.key?(:'sleep_charge')
    self.sleep_charge = attributes[:'sleep_charge']
  end

  if attributes.key?(:'sleep_goal')
    self.sleep_goal = attributes[:'sleep_goal']
  end

  if attributes.key?(:'sleep_rating')
    self.sleep_rating = attributes[:'sleep_rating']
  end

  if attributes.key?(:'short_interruption_duration')
    self.short_interruption_duration = attributes[:'short_interruption_duration']
  end

  if attributes.key?(:'long_interruption_duration')
    self.long_interruption_duration = attributes[:'long_interruption_duration']
  end

  if attributes.key?(:'sleep_cycles')
    self.sleep_cycles = attributes[:'sleep_cycles']
  end

  if attributes.key?(:'group_duration_score')
    self.group_duration_score = attributes[:'group_duration_score']
  end

  if attributes.key?(:'group_solidity_score')
    self.group_solidity_score = attributes[:'group_solidity_score']
  end

  if attributes.key?(:'group_regeneration_score')
    self.group_regeneration_score = attributes[:'group_regeneration_score']
  end

  if attributes.key?(:'hypnogram')
    self.hypnogram = attributes[:'hypnogram']
  end

  if attributes.key?(:'heart_rate_samples')
    self.heart_rate_samples = attributes[:'heart_rate_samples']
  end
end

Instance Attribute Details

#continuityObject

Continuity is an estimate of how continuous the sleep was on a scale of 1.0 – 5.0, where 5.0 reflects uninterrupted sleep. The lower the value the more fragmented the sleep was.



34
35
36
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 34

def continuity
  @continuity
end

#continuity_classObject

Verbal assessments of sleep continuity Very continuous sleep (5) Continuous sleep (4) Fairly continuous sleep (3) Fairly fragmented sleep (2) Fragmented sleep (1)



37
38
39
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 37

def continuity_class
  @continuity_class
end

#dateObject

Result date of the sleep



22
23
24
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 22

def date
  @date
end

#deep_sleepObject

Total time in seconds spent in the deep sleep stage between when you fell asleep and when you woke up. Corresponds to N3 according to AASM classification.



43
44
45
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 43

def deep_sleep
  @deep_sleep
end

#device_idObject

Id of the device the sleep was measured with



31
32
33
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 31

def device_id
  @device_id
end

#group_duration_scoreObject

Sleep score consists of six components that are grouped under three themes. Score for sleep duration theme looks at your sleep time compared to your ‘preferred sleep time’ setting and the age-related duration recommendations. Group duration score ranges from 1.0 to 100.0. It is interpreted as textual feedback: poor, moderate or good amount.



76
77
78
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 76

def group_duration_score
  @group_duration_score
end

#group_regeneration_scoreObject

Sleep score consists of six components that are grouped under three themes. Score for regeneration theme is the average of the scores of REM sleep and deep sleep. Group regeneration score ranges from 1.0 to 100.0. It is interpreted as textual feedback: poor, moderate or good regeneration



82
83
84
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 82

def group_regeneration_score
  @group_regeneration_score
end

#group_solidity_scoreObject

Sleep score consists of six components that are grouped under three themes. Score for sleep solidity theme is the average of the component scores of long interruptions, continuity and actual sleep. Group solidity score ranges from 1.0 to 100.0. It is interpreted as textual feedback: poor, moderate or good solidity.



79
80
81
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 79

def group_solidity_score
  @group_solidity_score
end

#heart_rate_samplesObject

5 min average samples of heart rate from the duration of the sleep. Default time between samples is 5 minutes. There may be periods with samples more often than every 5 minutes. Unit of samples is beats per minute (bpm). You can request access to this data at www.polar.com/en/science/polar-accesslink-api-extended-content



88
89
90
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 88

def heart_rate_samples
  @heart_rate_samples
end

#hypnogramObject

The time span between when you fell asleep and when you woke up is classified into light, deep or REM sleep, or unrecognised or wake in 30-s epochs. 0 = WAKE, 1 = REM, 2 = LIGHTER NON-REM, 3 = LIGHT NON-REM, 4 = DEEP NON-REM, 5 = UNKNOWN (eg. due to bad skin contact). You can request access to this data at www.polar.com/en/science/polar-accesslink-api-extended-content



85
86
87
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 85

def hypnogram
  @hypnogram
end

#light_sleepObject

Total time in seconds spent in light sleep stage between when you fell asleep and when you woke up. Corresponds to N1+ N2 according to AASM classification.



40
41
42
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 40

def light_sleep
  @light_sleep
end

#long_interruption_durationObject

Total time in seconds of long interruptions. Long interruption is interruption in sleep of 90 seconds or more.



70
71
72
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 70

def long_interruption_duration
  @long_interruption_duration
end

#polar_userObject

Absolute link to user owning the sleep



19
20
21
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 19

def polar_user
  @polar_user
end

#rem_sleepObject

Total time in seconds spent in REM sleep stage between when you fell asleep and when you woke up. REM stands for rapid eye movement.



46
47
48
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 46

def rem_sleep
  @rem_sleep
end

#short_interruption_durationObject

Total time in seconds of short interruptions. Short interruption is interruption in sleep of less than 90 seconds.



67
68
69
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 67

def short_interruption_duration
  @short_interruption_duration
end

#sleep_chargeObject

Sleep score compared to your usual level from the past 28 days.Scale: much below usual (1) – below usual (2) – usual (3) – above usual (4) – much above usual(5).



58
59
60
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 58

def sleep_charge
  @sleep_charge
end

#sleep_cyclesObject

Number of sleep cycles.



73
74
75
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 73

def sleep_cycles
  @sleep_cycles
end

#sleep_end_timeObject

End timestamp of the sleep as ISO-8601 datetime string



28
29
30
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 28

def sleep_end_time
  @sleep_end_time
end

#sleep_goalObject

Time goal in seconds for sleep selectedby user. A default value of the setting is based on age-related sleep duration recommendations.



61
62
63
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 61

def sleep_goal
  @sleep_goal
end

#sleep_ratingObject

Numeric value given by user for representing the quality of sleep. Selection scale: Very poorly(1), poorly(2), ok(3), well(4), very well(5). 0 means no value is given.



64
65
66
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 64

def sleep_rating
  @sleep_rating
end

#sleep_scoreObject

Sleep score summarizes the amount and quality of your sleep into a single number on a scale of 1 – 100. Sleep score tells you how well you slept compared to the indicators of a good night’s sleep based on the current sleep science. It consists of six components; sleep time, long interruptions, continuity, actual sleep, REM sleep, and deep sleep.



52
53
54
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 52

def sleep_score
  @sleep_score
end

#sleep_start_timeObject

Start timestamp of the sleep as ISO-8601 datetime string



25
26
27
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 25

def sleep_start_time
  @sleep_start_time
end

#total_interruption_durationObject

The total time in seconds you spent awake between when you fell asleep and when you woke up.



55
56
57
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 55

def total_interruption_duration
  @total_interruption_duration
end

#unrecognized_sleep_stageObject

Total time in seconds spent in unrecognised sleep stage. Sometimes it’s impossible to recognize sleep stages. This might happen when, for example, the wrist strap is not tight enough, or if you sleep on your hand.



49
50
51
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 49

def unrecognized_sleep_stage
  @unrecognized_sleep_stage
end

Class Method Details

.acceptable_attributesObject

Returns all the JSON keys this model knows about



121
122
123
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 121

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 91

def self.attribute_map
  {
    :'polar_user' => :'polar_user',
    :'date' => :'date',
    :'sleep_start_time' => :'sleep_start_time',
    :'sleep_end_time' => :'sleep_end_time',
    :'device_id' => :'device_id',
    :'continuity' => :'continuity',
    :'continuity_class' => :'continuity_class',
    :'light_sleep' => :'light_sleep',
    :'deep_sleep' => :'deep_sleep',
    :'rem_sleep' => :'rem_sleep',
    :'unrecognized_sleep_stage' => :'unrecognized_sleep_stage',
    :'sleep_score' => :'sleep_score',
    :'total_interruption_duration' => :'total_interruption_duration',
    :'sleep_charge' => :'sleep_charge',
    :'sleep_goal' => :'sleep_goal',
    :'sleep_rating' => :'sleep_rating',
    :'short_interruption_duration' => :'short_interruption_duration',
    :'long_interruption_duration' => :'long_interruption_duration',
    :'sleep_cycles' => :'sleep_cycles',
    :'group_duration_score' => :'group_duration_score',
    :'group_solidity_score' => :'group_solidity_score',
    :'group_regeneration_score' => :'group_regeneration_score',
    :'hypnogram' => :'hypnogram',
    :'heart_rate_samples' => :'heart_rate_samples'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



332
333
334
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 332

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_nullableObject

List of attributes with nullable: true



156
157
158
159
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 156

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_typesObject

Attribute type mapping.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 126

def self.openapi_types
  {
    :'polar_user' => :'String',
    :'date' => :'Date',
    :'sleep_start_time' => :'Time',
    :'sleep_end_time' => :'Time',
    :'device_id' => :'String',
    :'continuity' => :'Float',
    :'continuity_class' => :'Integer',
    :'light_sleep' => :'Integer',
    :'deep_sleep' => :'Integer',
    :'rem_sleep' => :'Integer',
    :'unrecognized_sleep_stage' => :'Integer',
    :'sleep_score' => :'Integer',
    :'total_interruption_duration' => :'Integer',
    :'sleep_charge' => :'Integer',
    :'sleep_goal' => :'Integer',
    :'sleep_rating' => :'Integer',
    :'short_interruption_duration' => :'Integer',
    :'long_interruption_duration' => :'Integer',
    :'sleep_cycles' => :'Integer',
    :'group_duration_score' => :'Float',
    :'group_solidity_score' => :'Float',
    :'group_regeneration_score' => :'Float',
    :'hypnogram' => :'Object',
    :'heart_rate_samples' => :'Object'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 288

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      polar_user == o.polar_user &&
      date == o.date &&
      sleep_start_time == o.sleep_start_time &&
      sleep_end_time == o.sleep_end_time &&
      device_id == o.device_id &&
      continuity == o.continuity &&
      continuity_class == o.continuity_class &&
      light_sleep == o.light_sleep &&
      deep_sleep == o.deep_sleep &&
      rem_sleep == o.rem_sleep &&
      unrecognized_sleep_stage == o.unrecognized_sleep_stage &&
      sleep_score == o.sleep_score &&
      total_interruption_duration == o.total_interruption_duration &&
      sleep_charge == o.sleep_charge &&
      sleep_goal == o.sleep_goal &&
      sleep_rating == o.sleep_rating &&
      short_interruption_duration == o.short_interruption_duration &&
      long_interruption_duration == o.long_interruption_duration &&
      sleep_cycles == o.sleep_cycles &&
      group_duration_score == o.group_duration_score &&
      group_solidity_score == o.group_solidity_score &&
      group_regeneration_score == o.group_regeneration_score &&
      hypnogram == o.hypnogram &&
      heart_rate_samples == o.heart_rate_samples
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 362

def _deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = PolarAccesslinkApiGem.const_get(type)
    klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 433

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 339

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.openapi_types.each_pair do |key, type|
    if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
      self.send("#{key}=", nil)
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


319
320
321
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 319

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



325
326
327
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 325

def hash
  [polar_user, date, sleep_start_time, sleep_end_time, device_id, continuity, continuity_class, light_sleep, deep_sleep, rem_sleep, unrecognized_sleep_stage, sleep_score, total_interruption_duration, sleep_charge, sleep_goal, sleep_rating, short_interruption_duration, long_interruption_duration, sleep_cycles, group_duration_score, group_solidity_score, group_regeneration_score, hypnogram, heart_rate_samples].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



275
276
277
278
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 275

def list_invalid_properties
  invalid_properties = Array.new
  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



409
410
411
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 409

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 415

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



403
404
405
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 403

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



282
283
284
# File 'lib/polar-accesslink-api-gem/models/sleep.rb', line 282

def valid?
  true
end