Class: URBANopt::RNM::ReportScenario

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/rnm/scenario_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reopt) ⇒ ReportScenario

Returns a new instance of ReportScenario.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/urbanopt/rnm/scenario_report.rb', line 11

def initialize(reopt)
  @reopt = reopt
  @hour_index_max_res = hour_index_max_res
  @hour_index_min_res = hour_index_min_res
  @peak_hour_max_res = peak_hour_max_res
  @peak_hour_min_res = peak_hour_min_res
  @hour_index_max_comm = hour_index_max_comm
  @hour_index_min_comm = hour_index_min_comm
  @peak_hour_max_comm = peak_hour_max_comm
  @peak_hour_min_comm = peak_hour_min_comm
  @res_consumption = []
  @commercial_consumption = []
  @time = []
end

Instance Attribute Details

#hour_index_max_commObject

Returns the value of attribute hour_index_max_comm.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def hour_index_max_comm
  @hour_index_max_comm
end

#hour_index_max_resObject

Returns the value of attribute hour_index_max_res.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def hour_index_max_res
  @hour_index_max_res
end

#hour_index_min_commObject

Returns the value of attribute hour_index_min_comm.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def hour_index_min_comm
  @hour_index_min_comm
end

#hour_index_min_resObject

Returns the value of attribute hour_index_min_res.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def hour_index_min_res
  @hour_index_min_res
end

#peak_hour_max_commObject

Returns the value of attribute peak_hour_max_comm.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def peak_hour_max_comm
  @peak_hour_max_comm
end

#peak_hour_max_resObject

Returns the value of attribute peak_hour_max_res.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def peak_hour_max_res
  @peak_hour_max_res
end

#peak_hour_min_commObject

Returns the value of attribute peak_hour_min_comm.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def peak_hour_min_comm
  @peak_hour_min_comm
end

#peak_hour_min_resObject

Returns the value of attribute peak_hour_min_res.



9
10
11
# File 'lib/urbanopt/rnm/scenario_report.rb', line 9

def peak_hour_min_res
  @peak_hour_min_res
end

Instance Method Details

#aggregate_consumption(file_csv, file_json, n_feature) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/urbanopt/rnm/scenario_report.rb', line 78

def aggregate_consumption(file_csv, file_json, n_feature)
  feature_type = file_json['program']['building_types'][0]['building_type']
  # residential_building_types = "Single-Family Detached" #add the other types
  residential_building_types = ['Single-Family Detached', 'Single-Family Attached', 'Multifamily', 'Single-Family', 'Multifamily Detached (2 to 4 units)', 'Multifamily Detached (5 or more units)'] # add the other types
  puts feature_type
  j = 0
  CSV.foreach(file_csv, headers: true) do |power|
    @time[j] = power['Datetime']
    if n_feature == 0
      @res_consumption[j] = 0
      @commercial_consumption[j] = 0
    end
    if @reopt
      if residential_building_types.include? feature_type
        @res_consumption[j] += power['REopt:Electricity:Load:Total(kw)'].to_i + power['REopt:Electricity:Grid:ToBattery(kw)'].to_i + power['REopt:ElectricityProduced:PV:ToBattery(kw)'].to_i + power['REopt:ElectricityProduced:Wind:ToBattery(kw)'].to_i + power['REopt:ElectricityProduced:Generator:ToBattery(kw)'].to_i - power['REopt:Electricity:Storage:ToLoad(kw)'].to_i - power['REopt:Electricity:Storage:ToGrid(kw)'].to_i - power['REopt:ElectricityProduced:Total(kw)'].to_i
        j += 1
      else
        @commercial_consumption[j] += power['REopt:Electricity:Load:Total(kw)'].to_i + power['REopt:Electricity:Grid:ToBattery(kw)'].to_i + power['REopt:ElectricityProduced:PV:ToBattery(kw)'].to_i + power['REopt:ElectricityProduced:Wind:ToBattery(kw)'].to_i + power['REopt:ElectricityProduced:Generator:ToBattery(kw)'].to_i - power['REopt:Electricity:Storage:ToLoad(kw)'].to_i - power['REopt:Electricity:Storage:ToGrid(kw)'].to_i - power['REopt:ElectricityProduced:Total(kw)'].to_i
        j += 1
      end
    else
      if residential_building_types.include? feature_type
        @res_consumption[j] += power['Electricity:Facility Power(kW)'].to_i
        j += 1
      else
        @commercial_consumption[j] += power['Electricity:Facility Power(kW)'].to_i
        j += 1
      end
    end
  end
end

#scenario_report_resultsObject

creating a method passing the GEOjson file from URBANopt as the argument to define streets and building (customers) coordinates and returning the street coordinates array, the building coordinates array and the tot number of buildings in the project



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/urbanopt/rnm/scenario_report.rb', line 29

def scenario_report_results
  max_net_load_res = 0
  max_net_load_comm = 0
  min_net_load_res = 500000
  min_net_load_comm = 500000
  # j = 0
  # insert scenario path
  # if include reopt getting 2 most-stressing days in the year (max net load & min net load)
  if @reopt
    (0..@commercial_consumption.length - 1).each do |j|
      if @commercial_consumption[j] > max_net_load_comm
        max_net_load_comm = @commercial_consumption[j]
        @peak_hour_max_comm = (@time[j].split(' ')[1]) # defined the most-stressing scenario
        @hour_index_max_comm = j
      end
      if @commercial_consumption[j] < min_net_load_comm
        min_net_load_comm = @commercial_consumption[j]
        @peak_hour_min_comm = (@time[j].split(' ')[1]) # defined the most-stressing scenario
        @hour_index_min_comm = j
      end

      if @res_consumption[j] > max_net_load_res
        max_net_load_res = @res_consumption[j]
        @peak_hour_max_res = (@time[j].split(' ')[1]) # defined the most-stressing scenario
        @hour_index_max_res = j
      end
      if @res_consumption[j] < min_net_load_res
        min_net_load_res = @res_consumption[j]
        @peak_hour_min_res = (@time[j].split(' ')[1]) # defined the most-stressing scenario
        @hour_index_min_res = j
      end
    end

  else # case when reopt is not run and there is only a consumption scenario, without DG generation
    (0..@commercial_consumption.length - 1).each do |j|
      if @commercial_consumption[j] > max_net_load_comm
        max_net_load_comm = @commercial_consumption[j]
        @peak_hour_max_comm = (@time[j].split(' ')[1]) # defined the most-stressing scenario
        @hour_index_max_comm = j
      end
      if @res_consumption[j] > max_net_load_res
        max_net_load_res = @res_consumption[j]
        @peak_hour_max_res = (@time[j].split(' ')[1]) # defined the most-stressing scenario
        @hour_index_max_res = j
      end
    end
  end
end