Class: GerbilCharts::Models::MatrixModel

Inherits:
Object
  • Object
show all
Defined in:
lib/gerbilcharts/models/matrix_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ MatrixModel

Create the model group for matrix chart Input = “a”,“b”,1000

{"a","c",1030}
{"b","v",2345}

Output = href="1000,1030,0">a“=>,”b“=>



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gerbilcharts/models/matrix_model.rb', line 17

def initialize(opts)
      @name=opts
      @aend = []
  @zend = []
  @input_values = []
  @arr = []
  @hash = {}
      @sort = []  
      @unsort_value = []
      @multiply_factor = 1.0
      @flag = 1
end

Instance Attribute Details

#aendObject (readonly)

Returns the value of attribute aend.



5
6
7
# File 'lib/gerbilcharts/models/matrix_model.rb', line 5

def aend
  @aend
end

#aendlenObject (readonly)

Returns the value of attribute aendlen.



7
8
9
# File 'lib/gerbilcharts/models/matrix_model.rb', line 7

def aendlen
  @aendlen
end

#aenduniqObject (readonly)

Returns the value of attribute aenduniq.



5
6
7
# File 'lib/gerbilcharts/models/matrix_model.rb', line 5

def aenduniq
  @aenduniq
end

#hashObject (readonly)

Returns the value of attribute hash.



8
9
10
# File 'lib/gerbilcharts/models/matrix_model.rb', line 8

def hash
  @hash
end

#multiply_factorObject (readonly)

Returns the value of attribute multiply_factor.



8
9
10
# File 'lib/gerbilcharts/models/matrix_model.rb', line 8

def multiply_factor
  @multiply_factor
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/gerbilcharts/models/matrix_model.rb', line 6

def name
  @name
end

#sortObject (readonly)

Returns the value of attribute sort.



8
9
10
# File 'lib/gerbilcharts/models/matrix_model.rb', line 8

def sort
  @sort
end

#zendObject (readonly)

Returns the value of attribute zend.



5
6
7
# File 'lib/gerbilcharts/models/matrix_model.rb', line 5

def zend
  @zend
end

#zendlenObject (readonly)

Returns the value of attribute zendlen.



7
8
9
# File 'lib/gerbilcharts/models/matrix_model.rb', line 7

def zendlen
  @zendlen
end

#zenduniqObject (readonly)

Returns the value of attribute zenduniq.



5
6
7
# File 'lib/gerbilcharts/models/matrix_model.rb', line 5

def zenduniq
  @zenduniq
end

Instance Method Details

#add(item1, item2, item3) ⇒ Object

Construct the input values Eg : @input_values = [[“a“,”b“,3000],,[”d“,”r“,4500]]



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gerbilcharts/models/matrix_model.rb', line 32

def add(item1,item2,item3) 
      @aend << item1
      @zend << item2         
      for i in 0...@input_values.count
           if ((@input_values[i][0] == item1) and (@input_values[i][1] == item2))
              @input_values[i][2] = @input_values[i][2] + item3
              @flag = 0 
           end         
      end
      if(@flag==1)
         @input_values << [item1,item2,item3]
      end
      @flag=1    
end

#calc_matrixObject

calculates the conversation matrix based on the raw arrays a/zend



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
# File 'lib/gerbilcharts/models/matrix_model.rb', line 48

def calc_matrix           
    @aenduniq = @aend.uniq
    @zenduniq = @zend.uniq
    @aendlen = @aenduniq.length
    @zendlen = @zenduniq.length

    @input_values.each do |item|
          @unsort_value << item[2]
    end
    @sort = @unsort_value.sort.reverse
    
    @aenduniq.each do |aitem|          
        @zenduniq.each_with_index do |zitem,i|
             @input_values.each do |vitem|
                   if ((vitem[0] == aitem) and (vitem[1] == zitem))
                      @arr << vitem[2]                       
                   end                       
             end
            if @arr[i].nil?
               @arr << 0
            end
        end             
    @hash.store(aitem,@arr)
    @arr = []
    end  
end

#empty?Boolean



79
80
81
# File 'lib/gerbilcharts/models/matrix_model.rb', line 79

def empty?
return false
end

#hasHref?Boolean



75
76
77
# File 'lib/gerbilcharts/models/matrix_model.rb', line 75

def hasHref?
return false
end