lib/urbanopt/scenario/default_reports/scenario_report.rb in urbanopt-scenario-0.1.1 vs lib/urbanopt/scenario/default_reports/scenario_report.rb in urbanopt-scenario-0.2.0.pre1

- old
+ new

@@ -76,10 +76,11 @@ @number_of_complete_simulations = hash[:number_of_complete_simulations] @number_of_failed_simulations = hash[:number_of_failed_simulations] @timeseries_csv = TimeseriesCSV.new(hash[:timeseries_csv]) @location = Location.new(hash[:location]) @program = Program.new(hash[:program]) + @distributed_generation = DistributedGeneration.new(hash[:distributed_generation] || {}) @construction_costs = [] hash[:construction_costs].each do |cc| @constructiion_costs << ConstructionCost.new(cc) end @@ -93,12 +94,12 @@ @feature_reports = [] hash[:feature_reports].each do |fr| @feature_reports << FeatureReport.new(fr) end - @distributed_generation = DistributedGeneration.new(hash[:distributed_generation] || {}) @file_name = 'default_scenario_report' + # initialize class variables @@validator and @@schema @@validator ||= Validator.new @@schema ||= @@validator.schema # initialize @@logger @@ -140,14 +141,14 @@ def csv_path File.join(@directory_name, @file_name + '.csv') end ## - # Saves the 'default_feature_report.json' and 'default_scenario_report.csv' files + # Saves the 'default_scenario_report.json' and 'default_scenario_report.csv' files ## # [parameters]: - # +file_name+ - _String_ - Assign a name to the saved scenario results file + # +file_name+ - _String_ - Assign a name to the saved scenario results file without an extension def save(file_name = 'default_scenario_report') # reassign the initialize local variable @file_name to the file name input. @file_name = file_name # save the csv data @@ -179,11 +180,11 @@ end if !old_timeseries_path.nil? @timeseries_csv.path = old_timeseries_path else - @timeseries_csv.path = File.join(@directory_name, 'default_scenario_report.csv') + @timeseries_csv.path = File.join(@directory_name, file_name + '.csv') end return true end ## @@ -241,14 +242,24 @@ ## # [parmeters:] # +feature_report+ - _FeatureReport_ - An object of FeatureReport class. ## def add_feature_report(feature_report) - if @timesteps_per_hour.nil? + # check if the timesteps_per_hour are identical + if @timesteps_per_hour.nil? || @timesteps_per_hour == '' @timesteps_per_hour = feature_report.timesteps_per_hour else - if feature_report.timesteps_per_hour != @timesteps_per_hour + if feature_report.timesteps_per_hour.is_a?(Integer) && feature_report.timesteps_per_hour != @timesteps_per_hour raise "FeatureReport timesteps_per_hour = '#{feature_report.timesteps_per_hour}' does not match scenario timesteps_per_hour '#{@timesteps_per_hour}'" + end + end + + # check if first report_report_datetime are identical. + if @timeseries_csv.first_report_datetime.nil? || @timeseries_csv.first_report_datetime == '' + @timeseries_csv.first_report_datetime = feature_report.timeseries_csv.first_report_datetime + else + if feature_report.timeseries_csv.first_report_datetime != @timeseries_csv.first_report_datetime + raise "first_report_datetime '#{@first_report_datetime}' does not match other.first_report_datetime '#{feature_report.timeseries_csv.first_report_datetime}'" end end # check that we have not already added this feature id = feature_report.id