Class: Flukso::UTCReading

Inherits:
Object
  • Object
show all
Defined in:
lib/flukso/reading.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(utc_timestamp, value) ⇒ UTCReading

Returns a new instance of UTCReading.

Raises:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/flukso/reading.rb', line 27

def initialize(utc_timestamp, value)
  # sanity checks.
  raise Flukso::General, "Invalid reading timestamp: #{utc_timestamp}" if utc_timestamp < 0; 
  #raise Flukso::General, "Invalid reading value: #{value}" if value.class != Fixnum || value < 0;
  @utc_timestamp = utc_timestamp.to_i;
  if value =~ /^nan$/i
    @value=0.0/0.0  # Workaround: Ruby does not allow to assign NaN directly.
  else
    @value = value
  end
end

Instance Attribute Details

#utc_timestampObject

Returns the value of attribute utc_timestamp.



26
27
28
# File 'lib/flukso/reading.rb', line 26

def utc_timestamp
  @utc_timestamp
end

#valueObject

Returns the value of attribute value.



26
27
28
# File 'lib/flukso/reading.rb', line 26

def value
  @value
end

Instance Method Details

#dayOfWeekObject



47
48
49
50
# File 'lib/flukso/reading.rb', line 47

def dayOfWeek
  currenttime=Time.at(@utc_timestamp);
  return currenttime.strftime("%a");
end

#isOnDay?(day, month, year) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
# File 'lib/flukso/reading.rb', line 51

def isOnDay?(day,month,year)
  starttime=Time.mktime(year, month, day, 0, 0);
  endtime=Time.mktime(year, month, day, 23, 59);
  event=Time.at(@utc_timestamp);
  if ((starttime <= event) and (event <= endtime))
    return true
  else
    return false
  end
end

#nan?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/flukso/reading.rb', line 38

def nan?
  return (value*1.0).nan?
end

#periodObject



61
62
63
64
65
# File 'lib/flukso/reading.rb', line 61

def period
  currenttime=Time.at(@utc_timestamp);
  period=(currenttime.hour * 4) + (currenttime.min / 15);
  return period
end

#timeObject



44
45
46
# File 'lib/flukso/reading.rb', line 44

def time
  return Time.at(@utc_timestamp);
end

#to_sObject



41
42
43
# File 'lib/flukso/reading.rb', line 41

def to_s
  return "#{@utc_timestamp} -> #{@value}"
end