Class: Analysis
- Inherits:
-
ActiveRecord::NoRdbBase
- Object
- Base
- ActiveRecord::NoRdbBase
- Analysis
- Defined in:
- app/models/analysis.rb
Constant Summary collapse
- ACTION_TYPE =
%w( draw analysis )
- DRAW_PROJECTION =
{1 => "rectangular uniform coordinate", 2 => "semi-logarithmic coordinate (y axis)", 3 => "semi-logarithmic coordinate (x axis)", 4 => "logarithmic coordinate", 5 => "polar coordinate", 6 => "bipolar coordinate", # 7 => "elliptic coordinate", 10 => "equidistant cylindrical projection", 11 => "Mercator's projection", 12 => "Mollweide's projection", 13 => "Hammer's projection", 14 => "Eckert VI projection", 15 => "Kitada's elliptic projection", 20 => "equidistant conical projection", 21 => "Lambert's equal-area conical projection", 22 => "Lambert's conformal conical projection", 23 => "Bonne's projection", 30 => "orthographic projection", 31 => "polar stereo projection", 32 => "azimuthal equidistant projection", 33 => "Lambert's azimuthal equal-area projection" }
- DRAW_SIZE =
[[700,700], [550,550], [400,400], [250,250]]
- @@minmaxs =
{ "action_type" => [0, ACTION_TYPE.length-1], "draw_size" => [0, DRAW_SIZE.length-1] }
Class Method Summary collapse
Instance Method Summary collapse
- #diagram_label ⇒ Object
- #dimensions ⇒ Object
- #draw_methods ⇒ Object
- #file_and_variable_names ⇒ Object
- #functions ⇒ Object
- #get_vizshots(basename) ⇒ Object
- #gphyses ⇒ Object
- #index ⇒ Object
- #variable_clear ⇒ Object
- #variables ⇒ Object
- #write_attribute(attr_name, value) ⇒ Object
Methods inherited from ActiveRecord::NoRdbBase
columns, connection, push_column
Class Method Details
.from_vizshot(viz) ⇒ Object
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'app/models/analysis.rb', line 465 def self.from_vizshot(viz) if viz && (par = parse_vizshot(viz)) vars, params = par analysis = Analysis.new vars.each{|var| analysis.variables.push var } analysis.action_type = ACTION_TYPE.index("draw") params.each{|name,val| analysis.send(name+"=", val) } return analysis else return nil end end |
.uri_params_from_vizshot(viz) ⇒ Object
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'app/models/analysis.rb', line 483 def self.uri_params_from_vizshot(viz) if viz && (par = parse_vizshot(viz)) vars, params = par ary = Array.new vars.each{|var| ary.push "variables[#{var.path}]=1" } ary.push "action_type=draw" params.each{|name,val| ary += param_to_str("analysis[#{name}]",val) } # params.collect{|str| str.gsub(/[/,"%5B").gsub(/]/,"%5D")}.join("&") URI.escape( ary.join("&") ) else return nil end end |
Instance Method Details
#diagram_label ⇒ Object
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'app/models/analysis.rb', line 443 def diagram_label label = draw_method.name label += ", #{region[x_axis][:name]}(#{region[x_axis]["min"]}:#{region[x_axis]["max"]})" if draw_method.ndims > 1 label += " vs #{region[y_axis][:name]}(#{region[y_axis]["min"]}:#{region[y_axis]["max"]})" end if draw_method.ndims > 2 label += " vs #{region[z_axis][:name]}(#{region[z_axis]["min"]}:#{region[z_axis]["max"]})" end tmp = Array.new dimensions.each{|dim| name = dim[:name] next if name==x_axis next if draw_method.ndims>1 && name==y_axis next if draw_method.ndims>2 && name==z_axis tmp.push "#{name}=#{region[name]["min"]}" if region[name] } label += " @ "+tmp.join(",") unless tmp.length==0 return label end |
#dimensions ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'app/models/analysis.rb', line 317 def dimensions unless @dimensions axes = Hash.new @dimensions = Array.new self.gphyses.each{|gp| gp.rank.times do |i| ax = gp.axis(i) ax_name = ax.name if axes[ax_name] ind, units, ary = axes[ax_name] pos = ax.pos ary2 = pos.val unless pos.units == units begin factor,offset = Units.new(units).factor_and_offset(Units.new(pos.units)) ary2 = ary*factor + offset rescue end end ary += ary2.to_a ary.sort!.uniq! axes[ax_name] = [ind, units, ary] else pos = ax.pos axes[ax_name] = [axes.length, pos.units, pos.val.to_a] end end axes.each do |name, ary| @dimensions[ary[0]] = {:name => name, :units => ary[1], :ary => ary[2]} end } end return @dimensions end |
#draw_methods ⇒ Object
275 276 277 278 279 280 281 282 283 |
# File 'app/models/analysis.rb', line 275 def draw_methods dm = read_attribute("draw_method") return dm if dm.nil? user_model = user && User.find_by_login(user) unless dm == DrawMethod.find(:first, :conditions=>["id=>",dm.node.id], :user=>user_model) raise "an invalid draw method was set" end return dm end |
#file_and_variable_names ⇒ Object
305 306 307 308 309 |
# File 'app/models/analysis.rb', line 305 def file_and_variable_names variables.collect do |var| [fname, vname] end end |
#functions ⇒ Object
285 286 287 288 289 290 291 292 293 |
# File 'app/models/analysis.rb', line 285 def functions func = read_attribute("function") return func if func.nil? user_model = user && User.find_by_login(user) unless func == Function.find(:first, :conditions=>["id=?",func.id], :user=>user_model) raise "an invalid function was set" end return func end |
#get_vizshots(basename) ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'app/models/analysis.rb', line 396 def get_vizshots(basename) = Hash.new vars = variables nvars = variables.length if nvars == 0 return [false, "at least one variable must be selected"] end dm_nvars = draw_method.nvars if nvars%dm_nvars != 0 return [false, "number of variable must be multiples of #{dm_nvars}"] end ix = get_index_from_name(x_axis) iy = get_index_from_name(y_axis) iz = get_index_from_name(z_axis) [:method] = draw_method.vizshot_method.to_sym .update( ) ["transpose"] = true if draw_method.ndims>1 && ix && iy && ix > iy [:cut] = index size = Analysis::DRAW_SIZE[draw_size] vizs = Array.new nfig = nvars/dm_nvars nfig.times{|n| if dm_nvars == 2 [:variables] = [ vars[draw_variables_order[n][0]].path, vars[draw_variables_order[n][1]].path ] else [:variables] = [ vars[n].path ] end if draw_pileup && vizs[0] viz = vizs[0] else viz = NumRu::VizShot.new(:iwidth => size[0], :iheight => size[1], :basename => basename) viz.set_fig('itr' => draw_projection, 'viewport' => ) unless draw_projection == 5 viz.set_tone('tonf' => true ) end vizs.push viz end viz.plot( .dup ) } return [true, vizs] end |
#gphyses ⇒ Object
311 312 313 314 315 |
# File 'app/models/analysis.rb', line 311 def gphyses variables.collect do |var| var.gphys end end |
#index ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'app/models/analysis.rb', line 352 def index dims = region if region.length == 0 dims = Hash.new dimensions.each{|dim| dims[dim[:name]] = {"min"=>dim[:ary][0], "max"=>dim[:ary][-1]} } end twoD = dimensions.length > 1 threeD = dimensions.length > 2 dim0 = dimensions[0][:name] dim1 = dimensions[1][:name] if twoD dim2 = dimensions[2][:name] if threeD unless x_axis xa = dim0 xa = (twoD && y_axis==xa) ? dim1 : xa xa = (threeD && z_axis==xa) ? dim2 : xa self.x_axis = xa end if twoD && !y_axis ya = dim1 ya = x_axis==ya ? dim0 : ya ya = (threeD && z_axis==ya) ? dim2 : ya self.y_axis = ya end if threeD && !z_axis za = dim2 za = y_axis==za ? dim1 : za za = x_axis==za ? dim0 : za self.z_axis = za end hash = Hash.new dims.each do |name,range| if ACTION_TYPE[action_type]=="analysis" || (name==x_axis || (draw_method.ndims>1&&name==y_axis) || (draw_method.ndims>2&&name==z_axis)) min = range["min"].to_f max = range["max"].to_f hash[name] = min==max ? min : min..max else hash[name] = range["min"].to_f end end return hash end |
#variable_clear ⇒ Object
296 297 298 299 300 301 302 303 |
# File 'app/models/analysis.rb', line 296 def variable_clear @dimensions = nil %w( variables region x_axis y_axis z_axis draw_variables_order function_variables_order ).each{|name| column = column_for_attribute(name) default = column.default self[name] = default } end |
#variables ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 |
# File 'app/models/analysis.rb', line 263 def variables user_model = user && User.find_by_login(user) vars = read_attribute("variables") vars.each{|var| next if var.new_record? unless var.other_mode==4 || ( user_model && (var.rgroups & user_model.groups) ) raise "an invalid variable was set" end } return vars end |
#write_attribute(attr_name, value) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'app/models/analysis.rb', line 164 def write_attribute(attr_name, value) case attr_name.to_s when "function" unless Function === value value = Function.find(:first, :conditions=>["name=?",value], :user=>user) end value = {:class => "function", :name => value && value.name, :user => user} when "draw_method" unless DrawMethod === value value = DrawMethod.find(:first, :conditions=>["name=?",value], :user=>user) end value = {:class => "draw_method", :name => value && value.name, :user => user} when "user" unless User === value value = User.find_by_login(value) end value = {:class => "user", :name => value && value.login} when "draw_variables_order" value = variables_order(value) when "function_variables_order" value = variables_order(value) end value = nil if value == "NULL" super(attr_name, value) if (minmax = @@minmaxs[attr_name.to_s]) val = read_attribute(attr_name) if val < minmax[0] write_attribute(attr_name, minmax[0].to_s) elsif val > minmax[1] write_attribute(attr_name, minmax[1].to_s) end end xa = read_attribute("x_axis") ya = read_attribute("y_axis") za = read_attribute("z_axis") ad = read_attribute("anim") && read_attribute("anim_dim") case attr_name.to_s when "x_axis" =begin if xa if xa == ya write_attribute("y_axis", nil) elsif xa == za write_attribute("z_axis", nil) elsif xa == ad write_attribute("anim_dim", nil) end end =end when "y_axis" =begin if ya if ya == xa write_attribute("x_axis", nil) elsif ya == za write_attribute("z_axis", nil) elsif ya == ad write_attribute("anim_dim", nil) end end =end when "z_axis" =begin if za if za == xa write_attribute("x_axis", nil) elsif za == ya write_attribute("y_axis", nil) elsif ya == ad write_attribute("anim_dim", nil) end end =end when "anim_dim" =begin if ad if ad == xa write_attribute("x_axis", nil) elsif ad == ya write_attribute("x_axis", nil) elsif ad == za write_attribute("z_axis", nil) end end =end when "draw_projection" unless DRAW_PROJECTION[value.to_i] write_attribute("draw_projection", "1") end when "viewport" unless .length==4 write_attribute("viewport", Analysis.columns_hash["viewport"].default) end end end |