Permalink
Browse files

mapdiff v1

  • Loading branch information...
1 parent e5fc355 commit 72dc2311a5f72e8e7b8bea60adc3245e1d9ba897 @mindbreaker mindbreaker committed Jan 13, 2012
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -1,3 +0,0 @@
-// Place all the styles related to the mapval controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,32 @@
+class MapdiffController < ApplicationController
+ respond_to :json
+
+ def index
+ data = { :map => "diff",
+ :model_name => params[:model],
+ :scenario_name => params[:scenario],
+ :year_a => params[:year_a],
+ :year_b => params[:year_b],
+ :month_a => params[:month_a],
+ :month_b => params[:month_b]
+ }
+
+ if params[:var] == "all"
+ pre = Moment.diff(params[:year_a], params[:month_a], params[:year_b], params[:month_b], Setup::VARIABLES[:pre])
+ tmp = Moment.diff(params[:year_a], params[:month_a], params[:year_b], params[:month_b], Setup::VARIABLES[:tmp])
+ gdd = Moment.diff(params[:year_a], params[:month_a], params[:year_b], params[:month_b], Setup::VARIABLES[:gdd])
+
+ data[:data] = {
+ :pre => pre,
+ :tmp => tmp,
+ :gdd => gdd
+ }
+ else
+ var = params[:var].to_sym
+ values = Moment.diff(params[:year_a], params[:month_a], params[:year_b], params[:month_b], Setup::VARIABLES[var])
+ data[:data] = {var => values}
+ end
+
+ respond_with(data)
+ end
+end
@@ -0,0 +1,2 @@
+module MapdiffHelper
+end
View
@@ -27,6 +27,23 @@ def self.funct(year, variable=1, funct="avg")
render_data data
end
+ def self.diff(year_a, month_a, year_b, month_b, variable=1)
+ data_a = data(year_a, month_a, variable)
+ data_b = data(year_b, month_b, variable)
+
+
+ data_a.each_with_index do |value,x|
+ next if value.nil?
+ value.each_with_index do |v, y|
+ if !data_a[x][y].nil? && !data_b[x][y].nil?
+ data_a[x][y] = data_a[x][y] - data_b[x][y]
+ end
+ end
+ end
+
+ data_a
+ end
+
def self.render_data data
result = Array.new_2d(258, 228)
View
@@ -60,4 +60,7 @@
match "/mapval/:model/:scenario/:year/:month/:var",
:controller => :mapvals, :action => :index
+ match "/mapdiff/:model/:scenario/:year_a/:month_a/:year_b/:month_b/:var",
+ :controller => :mapdiff, :action => :index
+
end
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe MapdiffController do
+
+end

0 comments on commit 72dc231

Please sign in to comment.