Class: CrossResult
- Inherits:
-
Object
- Object
- CrossResult
- Defined in:
- app/models/cross_result.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#keynames ⇒ Object
Returns the value of attribute keynames.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#qsetid ⇒ Object
Returns the value of attribute qsetid.
-
#resultids ⇒ Object
Returns the value of attribute resultids.
-
#resulttree ⇒ Object
Returns the value of attribute resulttree.
Instance Method Summary collapse
- #all_covered(slat, slon, elat, elon) ⇒ Object
- #count ⇒ Object
- #get_keyname_list ⇒ Object
- #get_keyvalue_list(keyname) ⇒ Object
- #get_path ⇒ Object
- #get_path_list ⇒ Object
- #get_querysetids(session_id) ⇒ Object
-
#initialize(qsetid) ⇒ CrossResult
constructor
A new instance of CrossResult.
- #partial_covered(slat, slon, elat, elon) ⇒ Object
- #points(slat, slon, elat, elon) ⇒ Object
- #put_results(nodes) ⇒ Object
- #reset_resulttree ⇒ Object
- #resultlist(p) ⇒ Object
Constructor Details
#initialize(qsetid) ⇒ CrossResult
Returns a new instance of CrossResult.
5 6 7 8 9 10 11 12 |
# File 'app/models/cross_result.rb', line 5 def initialize(qsetid) @keynames = Array.new @resulttree=PathNode.new @resulttree.path="/" @resultids = Array.new @nodes=Array.new @qsetid=qsetid end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'app/models/cross_result.rb', line 4 def id @id end |
#keynames ⇒ Object
Returns the value of attribute keynames.
4 5 6 |
# File 'app/models/cross_result.rb', line 4 def keynames @keynames end |
#nodes ⇒ Object
Returns the value of attribute nodes.
4 5 6 |
# File 'app/models/cross_result.rb', line 4 def nodes @nodes end |
#qsetid ⇒ Object
Returns the value of attribute qsetid.
4 5 6 |
# File 'app/models/cross_result.rb', line 4 def qsetid @qsetid end |
#resultids ⇒ Object
Returns the value of attribute resultids.
4 5 6 |
# File 'app/models/cross_result.rb', line 4 def resultids @resultids end |
#resulttree ⇒ Object
Returns the value of attribute resulttree.
4 5 6 |
# File 'app/models/cross_result.rb', line 4 def resulttree @resulttree end |
Instance Method Details
#all_covered(slat, slon, elat, elon) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/cross_result.rb', line 60 def all_covered(slat,slon,elat,elon) tablename="nodes" if @qsetid!=0 then nodelist = "(select distinct ancestor as id from node_lineages where descendant in (#{@resultids.join(',')})) n" if @resultids.length ==0 then return [] end else nodelist = "nodes n" end qstr=<<-EOM select latitude_lb,longitude_lb, latitude_rt, longitude_rt, count(*) as cnt from spatial_and_time_attributes s join #{nodelist} on n.id = s.node_id where s.latitude_lb<#{slat} and s.latitude_rt>#{elat} and s.longitude_lb<#{slon} and s.longitude_rt>#{elon} group by s.latitude_lb,s.longitude_lb, s.latitude_rt, s.longitude_rt EOM return Node.find_by_sql(qstr) end |
#count ⇒ Object
56 57 58 |
# File 'app/models/cross_result.rb', line 56 def count return @resultids.size end |
#get_keyname_list ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/models/cross_result.rb', line 126 def get_keyname_list if @qsetid!=0 then nodelist = "(select distinct ancestor as id from node_lineages where descendant in (#{@resultids.join(',')})) n" if @resultids.length ==0 then return [] end else nodelist = "nodes n" end igr_attrs="" i=0 GFDNAVI_IGNORED_ATTRS.each{ |iga| if i==0 then igr_attrs="'#{iga}'" else igr_attrs="#{igr_attrs},'#{iga}'" end i=i+1 } if GFDNAVI_IGNORED_ATTRS.size>0 then qstr=<<-EOF select k.name as kname,count(distinct n.id) as cnt from keyword_attributes k join #{nodelist} on k.node_id = n.id where not (k.name in (#{igr_attrs})) group by k.name order by cnt DESC EOF else qstr=<<-EOF select k.name as kname,count(distinct n.id) as cnt from keyword_attributes k join #{nodelist} on k.node_id = n.id group by k.name order by cnt DESC EOF end keylist=KeywordAttribute.find_by_sql(qstr) return keylist end |
#get_keyvalue_list(keyname) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'app/models/cross_result.rb', line 199 def get_keyvalue_list(keyname) if @qsetid!=0 then nodelist = "(select distinct ancestor as id from node_lineages where descendant in (#{@resultids.join(',')})) n" else nodelist = "nodes n" end qstr=<<-EOF select k.value as value, k.num_value as num_value, count(distinct n.id) as cnt from #{nodelist} join keyword_attributes k on k.node_id=n.id where k.name='#{keyname}' group by k.value order by cnt DESC EOF keylist=KeywordAttribute.find_by_sql(qstr) return keylist end |
#get_path ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/cross_result.rb', line 166 def get_path if @qsetid>0 then res=QueryHistory.find(:all,:conditions=>["queryset_id=? and querytype='path'",@qsetid]) if res.size>0 then res[0].description=~/[P](.*)/ return $1 end end return "/" end |
#get_path_list ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'app/models/cross_result.rb', line 177 def get_path_list if @qsetid>0 then QueryHistory.find(:all,:conditions=>["queryset_id=? and querytype='path'",@qsetid]) tables="(select v.* from nodes v, gfdnavi_querycache.queryset_#{@qsetid} c where v.id=c.vid)" path=get_path else tables="nodes" path="/" end sql1=<<-EOM select d2.path as dpath, count(distinct v.id) as cnt from nodes d1,nodes d2,#{tables} v where d1.path = ? and d2.parent_id = d1.id and v.path like #{concat("d2.path","'%'")} group by d2.path order by cnt DESC EOM pathlist = Node.find_by_sql([sql1,path]) return pathlist end |
#get_querysetids(session_id) ⇒ Object
216 217 218 219 220 221 222 223 |
# File 'app/models/cross_result.rb', line 216 def get_querysetids(session_id) res=Array.new qhistories=QueryHistory.find_by_sql(["select distinct queryset_id from query_histories where session_id=? order by queryset_id;",session_id]) qhistories.each{ |qh| res.push qh.queryset_id } return res end |
#partial_covered(slat, slon, elat, elon) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/cross_result.rb', line 84 def partial_covered(slat,slon,elat,elon) if @qsetid!=0 then nodelist = "(select distinct ancestor as id from node_lineages where descendant in (#{@resultids.join(',')})) n" if @resultids.length ==0 then return [] end else nodelist = "nodes n" end qstr=<<-EOM select latitude_lb,longitude_lb, latitude_rt, longitude_rt, count(*) as cnt from spatial_and_time_attributes s join #{nodelist} on n.id = s.node_id where not (latitude_lb<#{slat} and latitude_rt>#{elat} and longitude_lb<#{slon} and longitude_rt>#{elon}) and latitude_lb<>latitude_rt and longitude_lb<>longitude_rt group by latitude_lb,longitude_lb, latitude_rt, longitude_rt EOM return Node.find_by_sql(qstr) end |
#points(slat, slon, elat, elon) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/cross_result.rb', line 106 def points(slat,slon,elat,elon) if @qsetid!=0 then nodelist = "(select distinct ancestor as id from node_lineages where descendant in (#{@resultids.join(',')})) n" if @resultids.length ==0 then return [] end else nodelist = "nodes n" end qstr=<<-EOM select latitude_lb,longitude_lb, latitude_rt, longitude_rt, count(*) as cnt from spatial_and_time_attributes s join #{nodelist} on n.id = s.node_id where latitude_lb=latitude_rt and longitude_lb=longitude_rt group by latitude_lb,longitude_lb EOM return Node.find_by_sql(qstr) end |
#put_results(nodes) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/cross_result.rb', line 18 def put_results(nodes) @resultids.clear @nodes.clear @nodes = nodes @nodes.each{ |res| @resultids.push(res.id) } @resultids.uniq! end |
#reset_resulttree ⇒ Object
13 14 15 16 |
# File 'app/models/cross_result.rb', line 13 def reset_resulttree @resulttree=PathNode.new @resulttree.path="/" end |
#resultlist(p) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/cross_result.rb', line 29 def resultlist(p) reset_resulttree dir=Array.new res=Array.new @nodes.each{ |n| if n.node_type==0 then dir.push n else res.push n end } res.each{ |r| flg=0 dir.each{ |d| if r.path=~/#{d.path}/ then flg=1 break end } if flg==0 then @resulttree.addpath(r) end } return res end |