Class: BuildingSync::TimeSeries

Inherits:
Object
  • Object
show all
Includes:
Helper, XmlGetSet
Defined in:
lib/buildingsync/time_series.rb

Overview

TimeSeries class

Instance Method Summary collapse

Methods included from XmlGetSet

#get_prefix, #xget_attribute_for_element, #xget_element, #xget_id, #xget_idrefs, #xget_linked_premises, #xget_name, #xget_or_create, #xget_plurals_text_value, #xget_text, #xget_text_as_bool, #xget_text_as_date, #xget_text_as_dt, #xget_text_as_float, #xget_text_as_integer, #xset_or_create, #xset_text

Methods included from Helper

#help_calculate_hours, #help_convert, #help_count_number_of_days, #help_element_class_type_check, #help_get_attribute_value, #help_get_default_schedule_set, #help_get_duration, #help_get_end_time, #help_get_end_time_sat, #help_get_end_time_sun, #help_get_end_time_weekday, #help_get_or_create, #help_get_schedule_rule_set_from_schedule, #help_get_start_time, #help_get_start_time_sat, #help_get_start_time_sun, #help_get_start_time_weekday, #help_get_text_value, #help_get_text_value_as_bool, #help_get_text_value_as_date, #help_get_text_value_as_datetime, #help_get_text_value_as_float, #help_get_text_value_as_integer, #help_get_zone_name_list, #help_load_doc, #help_print_all_schedules, #help_print_schedule, #help_write_profile

Constructor Details

#initialize(base_xml, ns) ⇒ TimeSeries

initialize

Parameters:

  • @base_xml (REXML::Element)
  • ns (String)


47
48
49
50
51
52
53
54
# File 'lib/buildingsync/time_series.rb', line 47

def initialize(base_xml, ns)
  @base_xml = base_xml
  @ns = ns
  help_element_class_type_check(base_xml, 'TimeSeries')

  # translates to: 2020-01-01T00:00:00
  @timestamp_format = '%FT%T'
end

Instance Method Details

#set_monthly_energy_reading(start_date_time, interval_reading_value, resource_use_id) ⇒ Object

Parameters:

  • start_date_time (DateTime)

    should be the zeroth second of the month, i.e. 2020-01-01T00:00:00

  • interval_reading_value (Numeric)

    the value to use for IntervalReading

  • resource_use_id (String)

    the ID of the ResourceUse to point to



75
76
77
78
79
80
81
82
83
# File 'lib/buildingsync/time_series.rb', line 75

def set_monthly_energy_reading(start_date_time, interval_reading_value, resource_use_id)
  xset_or_create('ReadingType', 'Total')
  xset_or_create('TimeSeriesReadingQuantity', 'Energy')
  set_start_and_end_timestamps_monthly(start_date_time)
  xset_or_create('IntervalFrequency', 'Month')
  xset_or_create('IntervalReading', interval_reading_value)
  ru_id_element = xget_or_create('ResourceUseID')
  ru_id_element.add_attribute('IDref', resource_use_id)
end

#set_start_and_end_timestamps_monthly(start_date_time) ⇒ Object

Creates monthly start and end times for the element.

Parameters:

  • start_date_time (DateTime)

    should be the zeroth second of the month, i.e. 2020-01-01T00:00:00



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/buildingsync/time_series.rb', line 58

def set_start_and_end_timestamps_monthly(start_date_time)
  xset_or_create('StartTimestamp', start_date_time.strftime(@timestamp_format))

  # >>= shifts a datetime by 1 month
  end_date = start_date_time >>= 1

  # += shifts a datetime by 1 day.  the following shifts it by negative 1 minute
  end_date += - Rational(1, 24.0 * 60)

  # Always sets to last minute of the month:
  # 2020-01-31T23:59:00
  xset_or_create('EndTimestamp', end_date.strftime(@timestamp_format))
end