Skip to content

Commit

Permalink
Merge pull request #97 from NREL/rakefile_updates
Browse files Browse the repository at this point in the history
Addresses #96.
  • Loading branch information
shorowit committed Sep 27, 2017
2 parents c3e4f48 + 4b0b04a commit 8901f62
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 71 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ resources/grid_prop.csv
docs/build
node_modules/

test/reports
test/reports

/master.zip
/master
47 changes: 41 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,46 @@ desc 'Copy measures/osms from OpenStudio-BEopt repo'
task :copy_beopt_files do
require 'fileutils'
require 'openstudio'
require 'net/http'
require 'openssl'

# TODO: Should really grab latest from https://github.com/NREL/OpenStudio-BEopt/archive/master.zip
beopt_measures_dir = File.join(File.dirname(__FILE__), "..", "OpenStudio-BEopt", "measures")
buildstock_resource_measures_dir = File.join(File.dirname(__FILE__), "resources", "measures")
if not Dir.exist?(beopt_measures_dir)
puts "Cannot find OpenStudio-BEopt measures dir at #{beopt_measures_dir}."
if File.exists? File.join(File.dirname(__FILE__), "master.zip")
FileUtils.rm(File.join(File.dirname(__FILE__), "master.zip"))
end

url = URI.parse('https://codeload.github.com/NREL/OpenStudio-BEopt/zip/master')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

params = { 'User-Agent' => 'curl/7.43.0', 'Accept-Encoding' => 'identity' }
request = Net::HTTP::Get.new(url.path, params)
request.content_type = 'application/zip, application/octet-stream'

http.request request do |response|
total = response.header["Content-Length"].to_i
size = 0
progress = 0
open 'master.zip', 'wb' do |io|
response.read_body do |chunk|
io.write chunk
size += chunk.size
new_progress = (size * 100) / total
unless new_progress == progress
puts "Downloading %s (%3d%%) " % [url.path, new_progress]
end
progress = new_progress
end
end
end

puts "Extracting latest residential measures..."
unzip_file = OpenStudio::UnzipFile.new(File.join(File.dirname(__FILE__), "master.zip"))
unzip_file.extractAllFiles(OpenStudio::toPath(File.join(File.dirname(__FILE__), "master")))

beopt_measures_dir = File.join(File.dirname(__FILE__), "master", "OpenStudio-BEopt-master", "measures")
buildstock_resource_measures_dir = File.join(File.dirname(__FILE__), "resources", "measures")

# Copy seed osm and other needed resource files
project_dir_names = get_all_project_dir_names()
extra_files = [
Expand All @@ -26,7 +58,7 @@ task :copy_beopt_files do
]
extra_files.each do |extra_file|
puts "Copying #{extra_file}..."
beopt_file = File.join(File.dirname(__FILE__), "..", "OpenStudio-BEopt", extra_file)
beopt_file = File.join(File.dirname(__FILE__), "master", "OpenStudio-BEopt-master", extra_file)
if extra_file.start_with?("seeds") # Distribute to all projects
project_dir_names.each do |project_dir_name|
buildstock_file = File.join(File.dirname(__FILE__), project_dir_name, extra_file)
Expand Down Expand Up @@ -92,6 +124,9 @@ task :copy_beopt_files do
end
end
end

FileUtils.rm_rf(File.join(File.dirname(__FILE__), "master"))

end

def remove_items_from_zip_file(dir, zip_file_name, items)
Expand Down
57 changes: 12 additions & 45 deletions measures/TimeseriesCSVExport/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def energyPlusOutputRequests(runner, user_arguments)
# Request the output for each variable
if inc_output_variables
output_vars.each do |output_var|
result << OpenStudio::IdfObject.load("Output:Variable,#{output_var},#{reporting_frequency},*;").get
result << OpenStudio::IdfObject.load("Output:Variable,#{output_var},#{reporting_frequency};").get
end
end

return result
end

Expand All @@ -148,6 +148,12 @@ def run(runner, user_arguments)
end
model = model.get
epw_file = OpenStudio::EpwFile.new(File.expand_path(model.getWeatherFile.path.get.to_s))

# Convert time stamp format to be more readable
year_description = model.getYearDescription
unless epw_file.startDateActualYear.empty?
year_description.setCalendarYear(epw_file.startDateActualYear.get)
end

sql = runner.lastEnergyPlusSqlFile
if sql.empty?
Expand Down Expand Up @@ -272,7 +278,7 @@ def to_JSTime(os_time, year_description)
end
end
end

# Create a new series like this
# for each condition series we want to plot
# {"name" : "series 1",
Expand Down Expand Up @@ -312,16 +318,10 @@ def to_JSTime(os_time, year_description)
end
y_vals = y_timeseries.values

# Convert time stamp format to be more readable
year_description = model.getYearDescription
unless epw_file.startDateActualYear.empty?
year_description.setCalendarYear(epw_file.startDateActualYear.get)
end

js_date_times = []
y_timeseries.dateTimes.each do |date_time|
js_date_times << to_JSTime(date_time, year_description)
end
end

# Store the timeseries data to hash for later
# export to the HTML file
Expand Down Expand Up @@ -357,6 +357,7 @@ def to_JSTime(os_time, year_description)
point["time"] = time_i
data << point
end
next if data.all? {|x| x["y"] == 0}
series["data"] = data
all_series << series

Expand Down Expand Up @@ -384,7 +385,7 @@ def to_JSTime(os_time, year_description)
data_col = [col_name]
#data_col << units
data.each do |entry|
data_col << entry['y'].round(3)
data_col << entry['y'].round(2)
end
cols << data_col
end
Expand All @@ -399,40 +400,6 @@ def to_JSTime(os_time, year_description)
end
csv_path = File.absolute_path(csv_path)
runner.registerFinalCondition("CSV file saved to <a href='file:///#{csv_path}'>enduse_timeseries.csv</a>.")

# # Convert all_series to JSON.
# # This JSON will be substituted
# # into the HTML file.
# require 'json'
# all_series = all_series.to_json

# # read in template
# html_in_path = "#{File.dirname(__FILE__)}/resources/report.html.erb"
# if File.exist?(html_in_path)
# html_in_path = html_in_path
# else
# html_in_path = "#{File.dirname(__FILE__)}/report.html.erb"
# end
# html_in = ""
# File.open(html_in_path, 'r') do |file|
# html_in = file.read
# end

# # configure template with variable values
# renderer = ERB.new(html_in)
# html_out = renderer.result(binding)

# # write html file
# html_out_path = "./report.html"
# File.open(html_out_path, 'w') do |file|
# file << html_out
# # make sure data is written to the disk one way or the other
# begin
# file.fsync
# rescue
# file.flush
# end
# end

# close the sql file
sql.close()
Expand Down
38 changes: 19 additions & 19 deletions measures/TimeseriesCSVExport/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<schema_version>3.0</schema_version>
<name>timeseries_csv_export</name>
<uid>2a3442c1-944d-4e91-9e11-11e0cf368c64</uid>
<version_id>7b0a0c3f-bbb9-4123-a75a-eea8d6ed6247</version_id>
<version_modified>20170923T120627Z</version_modified>
<version_id>448f9531-f64a-4330-a9ae-cbd64b89614e</version_id>
<version_modified>20170925T201636Z</version_modified>
<xml_checksum>15BF4E57</xml_checksum>
<class_name>TimeseriesCSVExport</class_name>
<display_name>Timeseries CSV Export</display_name>
Expand Down Expand Up @@ -76,29 +76,12 @@
</attribute>
</attributes>
<files>
<file>
<version>
<software_program>OpenStudio</software_program>
<identifier>2.0.5</identifier>
<min_compatible>2.0.5</min_compatible>
</version>
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>DA21C8B9</checksum>
</file>
<file>
<filename>timeseries_csv_export_test.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>91DAD6DD</checksum>
</file>
<file>
<filename>DuPage_17043_725300_880860.epw</filename>
<filetype>epw</filetype>
<usage_type>test</usage_type>
<checksum>AD5BB8D6</checksum>
</file>
<file>
<filename>SFD_Successful_EnergyPlus_Run_AMY.osm</filename>
<filetype>osm</filetype>
Expand All @@ -117,5 +100,22 @@
<usage_type>test</usage_type>
<checksum>E23378AA</checksum>
</file>
<file>
<version>
<software_program>OpenStudio</software_program>
<identifier>2.0.5</identifier>
<min_compatible>2.0.5</min_compatible>
</version>
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>0FF88521</checksum>
</file>
<file>
<filename>DuPage_17043_725300_880860.epw</filename>
<filetype>epw</filetype>
<usage_type>test</usage_type>
<checksum>335AE046</checksum>
</file>
</files>
</measure>

0 comments on commit 8901f62

Please sign in to comment.