Class: GerbilCharts::Models::MatrixModel
- Inherits:
-
Object
- Object
- GerbilCharts::Models::MatrixModel
- Defined in:
- lib/gerbilcharts/models/matrix_model.rb
Instance Attribute Summary collapse
-
#aend ⇒ Object
readonly
Returns the value of attribute aend.
-
#aendlen ⇒ Object
readonly
Returns the value of attribute aendlen.
-
#aenduniq ⇒ Object
readonly
Returns the value of attribute aenduniq.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#multiply_factor ⇒ Object
readonly
Returns the value of attribute multiply_factor.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sort ⇒ Object
readonly
Returns the value of attribute sort.
-
#zend ⇒ Object
readonly
Returns the value of attribute zend.
-
#zendlen ⇒ Object
readonly
Returns the value of attribute zendlen.
-
#zenduniq ⇒ Object
readonly
Returns the value of attribute zenduniq.
Instance Method Summary collapse
-
#add(item1, item2, item3) ⇒ Object
Construct the input values Eg : @input_values = [[“a“,”b“,3000],,[”d“,”r“,4500]].
-
#calc_matrix ⇒ Object
calculates the conversation matrix based on the raw arrays a/zend.
- #empty? ⇒ Boolean
- #hasHref? ⇒ Boolean
-
#initialize(opts) ⇒ MatrixModel
constructor
Create the model group for matrix chart Input = “a”,“b”,1000 “a”,“c”,1030 “b”,“v”,2345.
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
#aend ⇒ Object (readonly)
Returns the value of attribute aend.
5 6 7 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 5 def aend @aend end |
#aendlen ⇒ Object (readonly)
Returns the value of attribute aendlen.
7 8 9 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 7 def aendlen @aendlen end |
#aenduniq ⇒ Object (readonly)
Returns the value of attribute aenduniq.
5 6 7 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 5 def aenduniq @aenduniq end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
8 9 10 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 8 def hash @hash end |
#multiply_factor ⇒ Object (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 |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 6 def name @name end |
#sort ⇒ Object (readonly)
Returns the value of attribute sort.
8 9 10 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 8 def sort @sort end |
#zend ⇒ Object (readonly)
Returns the value of attribute zend.
5 6 7 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 5 def zend @zend end |
#zendlen ⇒ Object (readonly)
Returns the value of attribute zendlen.
7 8 9 |
# File 'lib/gerbilcharts/models/matrix_model.rb', line 7 def zendlen @zendlen end |
#zenduniq ⇒ Object (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_matrix ⇒ Object
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 |