Class: ExplorerResult
- Inherits:
-
Object
- Object
- ExplorerResult
- Defined in:
- app/models/explorer_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_and_keyvalue_list ⇒ Object
- #get_keyname_list ⇒ Object
- #get_keyvalue_list(keyname) ⇒ Object
- #get_path ⇒ Object
- #get_path_list ⇒ Object
- #get_querysetids(session_id) ⇒ Object
-
#initialize(qsetid) ⇒ ExplorerResult
constructor
A new instance of ExplorerResult.
- #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) ⇒ ExplorerResult
Returns a new instance of ExplorerResult.
5 6 7 8 9 10 11 12 |
# File 'app/models/explorer_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/explorer_result.rb', line 4 def id @id end |
#keynames ⇒ Object
Returns the value of attribute keynames.
4 5 6 |
# File 'app/models/explorer_result.rb', line 4 def keynames @keynames end |
#nodes ⇒ Object
Returns the value of attribute nodes.
4 5 6 |
# File 'app/models/explorer_result.rb', line 4 def nodes @nodes end |
#qsetid ⇒ Object
Returns the value of attribute qsetid.
4 5 6 |
# File 'app/models/explorer_result.rb', line 4 def qsetid @qsetid end |
#resultids ⇒ Object
Returns the value of attribute resultids.
4 5 6 |
# File 'app/models/explorer_result.rb', line 4 def resultids @resultids end |
#resulttree ⇒ Object
Returns the value of attribute resulttree.
4 5 6 |
# File 'app/models/explorer_result.rb', line 4 def resulttree @resulttree end |
Instance Method Details
#all_covered(slat, slon, elat, elon) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/explorer_result.rb', line 59 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
55 56 57 |
# File 'app/models/explorer_result.rb', line 55 def count return @resultids.size end |
#get_keyname_and_keyvalue_list ⇒ Object
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 |
# File 'app/models/explorer_result.rb', line 173 def get_keyname_and_keyvalue_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 } GFDNAVI_INVISIBLE_ATTRS.each{ |iva| if i==0 then igr_attrs="#{iga}'" else igr_attrs="#{igr_attrs}, '#{iva}'" end i=i+1 } if GFDNAVI_IGNORED_ATTRS.size>0 then qstr=<<-EOF select k.name as kname,k.value as kvalue, 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})) and k.value IS NOT NULL group by k.name,k.value order by k.name,k.value,cnt DESC EOF else qstr=<<-EOF select k.name as kname,k.value as kvalue, count(distinct n.id) as cnt from keyword_attributes k join #{nodelist} on k.node_id = n.id where k.value IS NOT NULL group by k.name,k.value order by k.name,k.value,cnt DESC EOF end keylist=KeywordAttribute.find_by_sql(qstr) return keylist end |
#get_keyname_list ⇒ Object
124 125 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 165 166 167 168 169 170 171 |
# File 'app/models/explorer_result.rb', line 124 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 } GFDNAVI_INVISIBLE_ATTRS.each{ |iva| if i==0 then igr_attrs="'#{iva}'" else igr_attrs="#{igr_attrs}, '#{iva}'" 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
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'app/models/explorer_result.rb', line 257 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
224 225 226 227 228 229 230 231 232 233 |
# File 'app/models/explorer_result.rb', line 224 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
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'app/models/explorer_result.rb', line 235 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
274 275 276 277 278 279 280 281 |
# File 'app/models/explorer_result.rb', line 274 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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/explorer_result.rb', line 82 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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/explorer_result.rb', line 104 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 |
# File 'app/models/explorer_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/explorer_result.rb', line 13 def reset_resulttree @resulttree=PathNode.new @resulttree.path="/" end |
#resultlist(p) ⇒ Object
28 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 |
# File 'app/models/explorer_result.rb', line 28 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 |