Skip to content
New issue

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

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

Already on GitHub? # to your account

Copy exported schedules to generated files dir, #204

Merged
merged 3 commits into from
May 26, 2021
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
16 changes: 16 additions & 0 deletions lib/measures/from_honeybee_model/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

require 'to_openstudio'

require 'fileutils'
require 'pathname'

# start the measure
class FromHoneybeeModel < OpenStudio::Measure::ModelMeasure
# human readable name
Expand Down Expand Up @@ -96,6 +99,7 @@ def run(model, runner, user_arguments)
honeybee_model = Honeybee::Model.read_from_disk(model_json)

if schedule_csv_dir && !schedule_csv_dir.empty?
schedule_csv_dir = Pathname.new(schedule_csv_dir).cleanpath
if !Dir.exist?(schedule_csv_dir)
runner.registerError("Directory for exported CSV Schedules does not exist '#{schedule_csv_dir}'")
return false
Expand All @@ -106,6 +110,18 @@ def run(model, runner, user_arguments)
STDOUT.flush
honeybee_model.to_openstudio_model(model)
STDOUT.flush

generated_files_dir = "#{runner.workflow.absoluteRootDir}/generated_files"
if schedule_csv_dir && !schedule_csv_dir.empty?
if Dir.exist?(schedule_csv_dir)
runner.registerInfo("Copying exported schedules from '#{schedule_csv_dir}' to '#{generated_files_dir}'")
FileUtils.mkdir_p(generated_files_dir)
Dir.glob("#{schedule_csv_dir}/*.csv").each do |file|
FileUtils.cp(file, generated_files_dir)
end
end
end

return true
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/to_openstudio/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def self.write_schedule_csv(schedule_csv_dir, schedule_csv)
end
file.puts row.join(',')
end

# make sure data is written to the disk one way or the other
begin
file.fsync
rescue
file.flush
end
end
end
end
Expand Down