我有2d数组看起来像这样:
@forecast = [[6,2013,99],[7,2013,64],[8,2013,67],[9,2013,68],[10,2013,49]]
我想获得数据数组的预测值
此视图上的代码:
<% tmp = '-' %>
<% @forecast.each_with_index do |h, index| %>
<tr>
<td><%= is_month?(h[0].to_s) + "-" + h[1].to_s %></td>
<td><%= h[2] %></td>
<td><% if(index == 0) %> - <% elsif(index == 1) %> <%= tmp %> <% @aforecast = tmp %>
<% elsif(index > 1) %> <%= @aaforecast = ((0.1* tmp.to_i)+(0.9 * @aforecast.to_i)).round %> <% @aforecast = @aaforecast %>
<% end %>
</td>
<td><% if(index == 0) %> - <% elsif(index == 1) %> <%= tmp %> <% @bforecast = tmp %>
<% elsif(index > 1) %> <%= @bbforecast = ((0.5* tmp.to_i)+(0.5 * @bforecast.to_i)).round %> <% @bforecast = @bbforecast %>
<% end %>
</td>
<td><% if(index == 0) %> - <% elsif(index == 1) %> <%= tmp %> <% @cforecast = tmp %>
<% elsif(index > 1) %> <%= @ccforecast = ((0.9* tmp.to_i)+(0.1 * @cforecast.to_i)).round %> <% @cforecast = @fccorecast %>
<% end %>
</td>
<td><% if(index == 0) %> - <% elsif (index == 1) %>
<%= h[2].to_i - @aforecast.to_i %>
<% elsif (index > 1) %>
<%= h[2].to_i - @aaforecast.to_i %>
<% end %>
</td>
<td><% if(index == 0) %> - <% elsif (index == 1) %>
<%= h[2].to_i - @bforecast.to_i %>
<% elsif (index > 1) %>
<%= h[2].to_i - @bbforecast.to_i %>
<% end %>
</td>
<td><% if(index == 0) %> - <% elsif (index == 1) %>
<%= h[2].to_i - @cforecast.to_i %>
<% elsif (index > 1) %>
<%= h[2].to_i - @ccforecast.to_i %>
<% end %>
</td>
<% tmp = h[2] %>
</tr>
<% end %>
结果如下:
有没有办法通过调用数组并在视图中计算来解决我的情况?或者我是否有其他模型来存储所有这些并将此模型调用到视图中?
由于