Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts BuildResScheduleFile methods to ruby constants #1814

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions BuildResidentialScheduleFile/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>build_residential_schedule_file</name>
<uid>f770b2db-1a9f-4e99-99a7-7f3161a594b1</uid>
<version_id>27a369c7-3136-4a71-9ecd-af6392b6c251</version_id>
<version_modified>2024-08-21T20:28:58Z</version_modified>
<version_id>c51b1eff-b508-42dd-a77e-671265e526ab</version_id>
<version_modified>2024-08-28T16:06:34Z</version_modified>
<xml_checksum>03F02484</xml_checksum>
<class_name>BuildResidentialScheduleFile</class_name>
<display_name>Schedule File Builder</display_name>
Expand Down Expand Up @@ -169,7 +169,7 @@
<filename>constants.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>962DC751</checksum>
<checksum>27E808FB</checksum>
</file>
<file>
<filename>cooking_consumption_dist.csv</filename>
Expand Down Expand Up @@ -229,7 +229,7 @@
<filename>schedules.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>23F6E830</checksum>
<checksum>1E6EB1B1</checksum>
</file>
<file>
<filename>shower_cluster_size_probability.csv</filename>
Expand Down
185 changes: 24 additions & 161 deletions BuildResidentialScheduleFile/resources/constants.rb
Original file line number Diff line number Diff line change
@@ -1,165 +1,28 @@
# frozen_string_literal: true

# TODO
# Collection of constants.
module Constants
# TODO
#
# @return [String] TODO
def self.OccupancyTypesProbabilities
return '0.381, 0.297, 0.165, 0.157'
end

# TODO
#
# @return [String] TODO
def self.SinkDurationProbability
return '0.901242, 0.076572, 0.01722, 0.003798, 0.000944, 0.000154, 4.6e-05, 2.2e-05, 2.0e-06'
end

# TODO
#
# @return [String] TODO
def self.SinkEventsPerClusterProbs
return '0.62458, 0.18693, 0.08011, 0.0433, 0.02178, 0.01504, 0.0083, 0.00467, 0.0057, 0.00285, 0.00181, 0.00233, 0.0013, 0.00104, 0.00026'
end

# TODO
#
# @return [String] TODO
def self.SinkHourlyOnsetProb
return '0.007, 0.018, 0.042, 0.062, 0.066, 0.062, 0.054, 0.05, 0.049, 0.045, 0.041, 0.043, 0.048, 0.065, 0.075, 0.069, 0.057, 0.048, 0.04, 0.027, 0.014, 0.007, 0.005, 0.005'
end

# TODO
#
# @return [Integer] TODO
def self.SinkAvgSinkClustersPerHH
return 6657
end

# TODO
#
# @return [Integer] TODO
def self.SinkMinutesBetweenEventGap
return 2
end

# TODO
#
# @return [Double] TODO
def self.SinkFlowRateMean
return 1.14
end

# TODO
#
# @return [Double] TODO
def self.SinkFlowRateStd
return 0.61
end

# TODO
#
# @return [Integer] TODO
def self.ShowerMinutesBetweenEventGap
return 30
end

# TODO
#
# @return [Double] TODO
def self.ShowerFlowRateMean
return 2.25
end

# TODO
#
# @return [Double] TODO
def self.ShowerFlowRateStd
return 0.68
end

# TODO
#
# @return [Double] TODO
def self.BathBathToShowerRatio
return 0.078843
end

# TODO
#
# @return [Double] TODO
def self.BathDurationMean
return 5.65
end

# TODO
#
# @return [Double] TODO
def self.BathDurationStd
return 2.09
end

# TODO
#
# @return [Double] TODO
def self.BathFlowRateMean
return 4.4
end

# TODO
#
# @return [Double] TODO
def self.BathFlowRateStd
return 1.17
end

# TODO
#
# @return [Double] TODO
def self.HotWaterDishwasherFlowRateMean
return 1.39
end

# TODO
#
# @return [Double] TODO
def self.HotWaterDishwasherFlowRateStd
return 0.2
end

# TODO
#
# @return [Integer] TODO
def self.HotWaterDishwasherMinutesBetweenEventGap
return 10
end

# TODO
#
# @return [Double] TODO
def self.HotWaterClothesWasherFlowRateMean
return 2.2
end

# TODO
#
# @return [Double] TODO
def self.HotWaterClothesWasherFlowRateStd
return 0.62
end

# TODO
#
# @return [Integer] TODO
def self.HotWaterClothesWasherMinutesBetweenEventGap
return 4
end

# TODO
#
# @return [String] TODO
def self.HotWaterClothesWasherLoadSizeProbability
return '0.682926829, 0.227642276, 0.056910569, 0.032520325'
end
BathToShowerRatio = 0.078843
BathDurationMean = 5.65
BathDurationStd = 2.09
BathFlowRateMean = 4.4
BathFlowRateStd = 1.17
HotWaterDishwasherFlowRateMean = 1.39
HotWaterDishwasherFlowRateStd = 0.2
HotWaterDishwasherMinutesBetweenEventGap = 10
HotWaterClothesWasherFlowRateMean = 2.2
HotWaterClothesWasherFlowRateStd = 0.62
HotWaterClothesWasherMinutesBetweenEventGap = 4
HotWaterClothesWasherLoadSizeProbability = '0.682926829, 0.227642276, 0.056910569, 0.032520325'
OccupancyTypesProbabilities = '0.381, 0.297, 0.165, 0.157'
ShowerMinutesBetweenEventGap = 30
ShowerFlowRateMean = 2.25
ShowerFlowRateStd = 0.68
SinkDurationProbability = '0.901242, 0.076572, 0.01722, 0.003798, 0.000944, 0.000154, 4.6e-05, 2.2e-05, 2.0e-06'
SinkEventsPerClusterProbs = '0.62458, 0.18693, 0.08011, 0.0433, 0.02178, 0.01504, 0.0083, 0.00467, 0.0057, 0.00285, 0.00181, 0.00233, 0.0013, 0.00104, 0.00026'
SinkHourlyOnsetProb = '0.007, 0.018, 0.042, 0.062, 0.066, 0.062, 0.054, 0.05, 0.049, 0.045, 0.041, 0.043, 0.048, 0.065, 0.075, 0.069, 0.057, 0.048, 0.04, 0.027, 0.014, 0.007, 0.005, 0.005'
SinkAvgSinkClustersPerHH = 6657
SinkMinutesBetweenEventGap = 2
SinkFlowRateMean = 1.14
SinkFlowRateStd = 0.61
end
60 changes: 30 additions & 30 deletions BuildResidentialScheduleFile/resources/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create_stochastic_schedules(args:,
# States are: 'sleeping', 'shower', 'laundry', 'cooking', 'dishwashing', 'absent', 'nothingAtHome'
# if geometry_num_occupants = 2, period_in_a_year = 35040, num_of_states = 7, then
# shape of all_simulated_values is [2, 35040, 7]
occupancy_types_probabilities = Schedule.validate_values(Constants.OccupancyTypesProbabilities, 4, 'occupancy types probabilities')
occupancy_types_probabilities = Schedule.validate_values(Constants::OccupancyTypesProbabilities, 4, 'occupancy types probabilities')
for _n in 1..args[:geometry_num_occupants]
occ_type_id = weighted_random(prng, occupancy_types_probabilities)
init_prob_file_weekday = args[:resources_path] + "/weekday/mkv_chain_initial_prob_cluster_#{occ_type_id}.csv"
Expand Down Expand Up @@ -154,7 +154,7 @@ def create_stochastic_schedules(args:,
# repeat the same activity for the duration times
simulated_values << state_vector
j += 1
if j >= @mkc_ts_per_day then break end # break as soon as we have filled acitivities for the day
if j >= @mkc_ts_per_day then break end # break as soon as we have filled activities for the day
end
if j >= @mkc_ts_per_day then break end # break as soon as we have filled activities for the day

Expand Down Expand Up @@ -246,17 +246,17 @@ def create_stochastic_schedules(args:,
end
end

sink_duration_probs = Schedule.validate_values(Constants.SinkDurationProbability, 9, 'sink_duration_probability')
events_per_cluster_probs = Schedule.validate_values(Constants.SinkEventsPerClusterProbs, 15, 'sink_events_per_cluster_probs')
hourly_onset_prob = Schedule.validate_values(Constants.SinkHourlyOnsetProb, 24, 'sink_hourly_onset_prob')
sink_duration_probs = Schedule.validate_values(Constants::SinkDurationProbability, 9, 'sink_duration_probability')
events_per_cluster_probs = Schedule.validate_values(Constants::SinkEventsPerClusterProbs, 15, 'sink_events_per_cluster_probs')
hourly_onset_prob = Schedule.validate_values(Constants::SinkHourlyOnsetProb, 24, 'sink_hourly_onset_prob')
# Lookup avg_sink_clusters_per_hh from constants
avg_sink_clusters_per_hh = Constants.SinkAvgSinkClustersPerHH
avg_sink_clusters_per_hh = Constants::SinkAvgSinkClustersPerHH
# Adjust avg_sink_clusters_per_hh for number of occupants in household
total_clusters = avg_sink_clusters_per_hh * (0.29 * args[:geometry_num_occupants] + 0.26) # Eq based on cluster scaling in Building America DHW Event Schedule Generator (fewer sink draw clusters for larger households)
sink_minutes_between_event_gap = Constants.SinkMinutesBetweenEventGap
sink_minutes_between_event_gap = Constants::SinkMinutesBetweenEventGap
cluster_per_day = (total_clusters / @total_days_in_year).to_i
sink_flow_rate_mean = Constants.SinkFlowRateMean
sink_flow_rate_std = Constants.SinkFlowRateStd
sink_flow_rate_mean = Constants::SinkFlowRateMean
sink_flow_rate_std = Constants::SinkFlowRateStd
sink_flow_rate = gaussian_rand(prng, sink_flow_rate_mean, sink_flow_rate_std)
@total_days_in_year.times do |day|
for _n in 1..cluster_per_day
Expand Down Expand Up @@ -299,14 +299,14 @@ def create_stochastic_schedules(args:,
# b. Fill in the mkc personal hygiene slot with the bath duration and flow rate.
# TODO If there is room in the mkc personal hygiene slot, shift uniform randomly
# 6. Repeat process 2-6 for each occupant
shower_minutes_between_event_gap = Constants.ShowerMinutesBetweenEventGap
shower_flow_rate_mean = Constants.ShowerFlowRateMean
shower_flow_rate_std = Constants.ShowerFlowRateStd
bath_ratio = Constants.BathBathToShowerRatio
bath_duration_mean = Constants.BathDurationMean
bath_duration_std = Constants.BathDurationStd
bath_flow_rate_mean = Constants.BathFlowRateMean
bath_flow_rate_std = Constants.BathFlowRateStd
shower_minutes_between_event_gap = Constants::ShowerMinutesBetweenEventGap
shower_flow_rate_mean = Constants::ShowerFlowRateMean
shower_flow_rate_std = Constants::ShowerFlowRateStd
bath_ratio = Constants::BathToShowerRatio
bath_duration_mean = Constants::BathDurationMean
bath_duration_std = Constants::BathDurationStd
bath_flow_rate_mean = Constants::BathFlowRateMean
bath_flow_rate_std = Constants::BathFlowRateStd
m = 0
shower_activity_sch = [0] * mins_in_year
bath_activity_sch = [0] * mins_in_year
Expand Down Expand Up @@ -369,9 +369,9 @@ def create_stochastic_schedules(args:,
# (it's typically composed of multiple water draw events)
# 4. For each event, sample the event duration
# 5. Fill in the dishwasher/clothes washer time slot using those water draw events
dw_flow_rate_mean = Constants.HotWaterDishwasherFlowRateMean
dw_flow_rate_std = Constants.HotWaterDishwasherFlowRateStd
dw_minutes_between_event_gap = Constants.HotWaterDishwasherMinutesBetweenEventGap
dw_flow_rate_mean = Constants::HotWaterDishwasherFlowRateMean
dw_flow_rate_std = Constants::HotWaterDishwasherFlowRateStd
dw_minutes_between_event_gap = Constants::HotWaterDishwasherMinutesBetweenEventGap
dw_activity_sch = [0] * mins_in_year
m = 0
dw_flow_rate = gaussian_rand(prng, dw_flow_rate_mean, dw_flow_rate_std)
Expand Down Expand Up @@ -408,11 +408,11 @@ def create_stochastic_schedules(args:,
step += step_jump
end

cw_flow_rate_mean = Constants.HotWaterClothesWasherFlowRateMean
cw_flow_rate_std = Constants.HotWaterClothesWasherFlowRateStd
cw_minutes_between_event_gap = Constants.HotWaterClothesWasherMinutesBetweenEventGap
cw_flow_rate_mean = Constants::HotWaterClothesWasherFlowRateMean
cw_flow_rate_std = Constants::HotWaterClothesWasherFlowRateStd
cw_minutes_between_event_gap = Constants::HotWaterClothesWasherMinutesBetweenEventGap
cw_activity_sch = [0] * mins_in_year # this is the clothes_washer water draw schedule
cw_load_size_probability = Schedule.validate_values(Constants.HotWaterClothesWasherLoadSizeProbability, 4, 'hot_water_clothes_washer_load_size_probability')
cw_load_size_probability = Schedule.validate_values(Constants::HotWaterClothesWasherLoadSizeProbability, 4, 'hot_water_clothes_washer_load_size_probability')
m = 0
cw_flow_rate = gaussian_rand(prng, cw_flow_rate_mean, cw_flow_rate_std)
# States are: 'sleeping','shower','laundry','cooking', 'dishwashing', 'absent', 'nothingAtHome'
Expand Down Expand Up @@ -694,7 +694,7 @@ def read_appliance_power_dist(resources_path:)

# TODO
#
# @param prng [TODO] TODO
# @param prng [Random] Random number generator object
# @param power_dist_map [TODO] TODO
# @param appliance_name [TODO] TODO
# @return [TODO] TODO
Expand Down Expand Up @@ -778,7 +778,7 @@ def read_activity_duration_prob(resources_path:)

# TODO
#
# @param prng [TODO] TODO
# @param prng [Random] Random number generator object
# @param cluster_size_prob_map [TODO] TODO
# @param activity_type_name [TODO] TODO
# @return [TODO] TODO
Expand All @@ -789,7 +789,7 @@ def sample_activity_cluster_size(prng, cluster_size_prob_map, activity_type_name

# TODO
#
# @param prng [TODO] TODO
# @param prng [Random] Random number generator object
# @param duration_probabilites_map [TODO] TODO
# @param event_type [TODO] TODO
# @return [TODO] TODO
Expand All @@ -801,7 +801,7 @@ def sample_event_duration(prng, duration_probabilites_map, event_type)

# TODO
#
# @param prng [TODO] TODO
# @param prng [Random] Random number generator object
# @param activity_duration_prob_map [TODO] TODO
# @param occ_type_id [TODO] TODO
# @param activity [TODO] TODO
Expand Down Expand Up @@ -864,7 +864,7 @@ def export(schedules_path:)

# TODO
#
# @param prng [TODO] TODO
# @param prng [Random] Random number generator object
# @param mean [TODO] TODO
# @param std [TODO] TODO
# @param min [TODO] TODO
Expand Down Expand Up @@ -940,7 +940,7 @@ def get_value_from_daily_sch(weekday_sch, weekend_sch, monthly_multiplier, month

# TODO
#
# @param prng [TODO] TODO
# @param prng [Random] Random number generator object
# @param weights [TODO] TODO
# @return [TODO] TODO
def weighted_random(prng, weights)
Expand Down