diff options
-rw-r--r-- | web/i18n/de.yml | 2 | ||||
-rw-r--r-- | web/i18n/en.yml | 2 | ||||
-rw-r--r-- | web/lib/ui/key_comparison.rb | 92 | ||||
-rw-r--r-- | web/views/key_comparison.erb | 74 | ||||
-rw-r--r-- | web/viewsjs/key_comparison.js.erb | 4 |
5 files changed, 101 insertions, 73 deletions
diff --git a/web/i18n/de.yml b/web/i18n/de.yml index 8c37489..b3ae308 100644 --- a/web/i18n/de.yml +++ b/web/i18n/de.yml @@ -44,7 +44,7 @@ taginfo: relations: Relations combinations: Kombinationen key_combinations: Kombinationen - key_comparison: Key-Vergleich + comparison: Key/Tag-Vergleich overview: Übersicht data_from: Daten vom uses_data_from: | diff --git a/web/i18n/en.yml b/web/i18n/en.yml index dbd0015..c8356a3 100644 --- a/web/i18n/en.yml +++ b/web/i18n/en.yml @@ -45,7 +45,7 @@ taginfo: relations: Relations combinations: Combinations key_combinations: Combinations - key_comparison: Key Comparison + comparison: Key/Tag Comparison overview: Overview data_from: Data from uses_data_from: | diff --git a/web/lib/ui/key_comparison.rb b/web/lib/ui/key_comparison.rb index 5a0fcfa..9ec2fa2 100644 --- a/web/lib/ui/key_comparison.rb +++ b/web/lib/ui/key_comparison.rb @@ -1,40 +1,66 @@ # web/lib/ui/key_comparison.rb class Taginfo < Sinatra::Base - get %r{^/key_comparison/} do - @keys = params[:key][0..5] # allow to compare maximum of 5 keys - - @count_all = [] - @count_nodes = [] - @count_ways = [] - @count_relations = [] - @desc = [] - @prevalent_values = [] - @wiki_pages = [] - @has_map = [] - - @keys.each_with_index do |key, num| - @count_all << @db.select("SELECT count_all FROM db.keys").condition('key = ?', key).get_first_value().to_i - @count_nodes << @db.select("SELECT count_nodes FROM db.keys").condition('key = ?', key).get_first_value().to_i - @count_ways << @db.select("SELECT count_ways FROM db.keys").condition('key = ?', key).get_first_value().to_i - @count_relations << @db.select("SELECT count_relations FROM db.keys").condition('key = ?', key).get_first_value().to_i - - desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang=? AND key=? AND value IS NULL", r18n.locale.code, key).get_first_value()) - desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value IS NULL", key).get_first_value()) if desc == '' - @desc << desc - - prevalent_values = @db.select("SELECT value, count, fraction FROM db.prevalent_values"). - condition('key=?', key). - order_by([:count], 'DESC'). - execute().map{ |row| { 'value' => row['value'], 'count' => row['count'].to_i, 'fraction' => row['fraction'].to_f } } - @prevalent_values << prevalent_values - - wiki_pages = @db.select("SELECT DISTINCT lang FROM wiki.wikipages WHERE key=? AND value IS NULL ORDER BY lang", key). - execute().map{ |row| row['lang'] } - @wiki_pages << wiki_pages - - @has_map << (@db.count('tag_distributions').condition('key = ?', key).get_first_value().to_i > 0) + get %r{^/key_comparison/(.*)} do |items| + @data = [] + if !items.nil? + items.split('/').each do |item| + kv = item.split('=') + @data << { :key => kv[0], :value => kv[1] } + end + end + + if params[:key].is_a?(Array) + params[:key].each_with_index do |key, index| + @data << { + :key => key, + :value => (params[:value].is_a?(Array) ? params[:value][index] : nil) + } + end + end + + @data = @data[0..4] # allow to compare maximum of 5 items + + @data.each_with_index do |data, num| + key = data[:key] + value = data[:value] + + if value.nil? + data[:count_all] = @db.select("SELECT count_all FROM db.keys").condition('key = ?', key).get_first_value().to_i + data[:count_nodes] = @db.select("SELECT count_nodes FROM db.keys").condition('key = ?', key).get_first_value().to_i + data[:count_ways] = @db.select("SELECT count_ways FROM db.keys").condition('key = ?', key).get_first_value().to_i + data[:count_relations] = @db.select("SELECT count_relations FROM db.keys").condition('key = ?', key).get_first_value().to_i + + desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang=? AND key=? AND value IS NULL", r18n.locale.code, key).get_first_value()) + desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value IS NULL", key).get_first_value()) if desc == '' + data[:desc] = desc + + prevalent_values = @db.select("SELECT value, count, fraction FROM db.prevalent_values"). + condition('key=?', key). + order_by([:count], 'DESC'). + execute().map{ |row| { 'value' => row['value'], 'count' => row['count'].to_i, 'fraction' => row['fraction'].to_f } } + data[:prevalent_values] = prevalent_values + + data[:wiki_pages] = @db.select("SELECT DISTINCT lang FROM wiki.wikipages WHERE key=? AND value IS NULL ORDER BY lang", key).execute().map{ |row| row['lang'] } + + data[:has_map] = data[:count_all] > 0 + else + data[:count_all] = @db.select("SELECT count_all FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i + data[:count_nodes] = @db.select("SELECT count_nodes FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i + data[:count_ways] = @db.select("SELECT count_ways FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i + data[:count_relations] = @db.select("SELECT count_relations FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i + + desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang=? AND key=? AND value=?", r18n.locale.code, key, value).get_first_value()) + desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value=?", key, value).get_first_value()) if desc == '' + data[:desc] = desc + + data[:prevalent_values] = [] + + data[:wiki_pages] = @db.select("SELECT DISTINCT lang FROM wiki.wikipages WHERE key=? AND value=? ORDER BY lang", key, value).execute().map{ |row| row['lang'] } + + data[:has_map] = (@db.count('tag_distributions').condition('key = ?', key).condition('value = ?', value).get_first_value().to_i > 0) + end end @img_width = TaginfoConfig.get('geodistribution.width') diff --git a/web/views/key_comparison.erb b/web/views/key_comparison.erb index a113c42..6bce915 100644 --- a/web/views/key_comparison.erb +++ b/web/views/key_comparison.erb @@ -1,41 +1,41 @@ <div class="pre"> - <h1 class="section"><%= h(t.taginfo.key_comparison) %></h1> + <h1 class="section"><%= h(t.taginfo.comparison) %></h1> </div> <table class="comparison"> <tr> - <% (0..@keys.size-1).each do |num| %> - <td class="data first key<%= num %>" style="width: <%= 100/@keys.size %>%"> + <% @data.each_with_index do |data, num| %> + <td class="data first item<%= num %>" style="width: <%= 100/@data.size %>%"> <h2></h2> - <p><%= @desc[num] %></p> + <p><%= data[:desc] %></p> </td> <% end %> </tr> <tr> - <% @keys.each_with_index do |key, num| %> - <td class="data key<%= num %>"> + <% @data.each_with_index do |data, num| %> + <td class="data item<%= num %>"> <table class="compstat"> <tr> <td class="spacer"></td> - <th><img width="16" height="16" title="All" alt="" src="/img/types/all.16.png"/> <%= h(t.osm.all) %></th> - <td><%= @count_all[num].to_s_with_ts %></td> + <th><img width="16" height="16" alt="" src="/img/types/all.16.png"/> <%= h(t.osm.all) %></th> + <td><%= data[:count_all].to_s_with_ts %></td> <td class="spacer"></td> </tr> <tr> <td class="spacer"></td> - <th><img width="16" height="16" title="Node" alt="" src="/img/types/node.16.png"/> <%= h(t.osm.nodes) %></th> - <td><%= @count_nodes[num].to_s_with_ts %></td> + <th><img width="16" height="16" alt="" src="/img/types/node.16.png"/> <%= h(t.osm.nodes) %></th> + <td><%= data[:count_nodes].to_s_with_ts %></td> <td class="spacer"></td> </tr> <tr> <td class="spacer"></td> - <th><img width="16" height="16" title="Way" alt="" src="/img/types/way.16.png"/> <%= h(t.osm.ways) %></th> - <td><%= @count_ways[num].to_s_with_ts %></td> + <th><img width="16" height="16" alt="" src="/img/types/way.16.png"/> <%= h(t.osm.ways) %></th> + <td><%= data[:count_ways].to_s_with_ts %></td> <td class="spacer"></td> </tr> <tr> <td class="spacer"></td> - <th><img width="16" height="16" title="Relation" alt="" src="/img/types/relation.16.png"/> <%= h(t.osm.relations) %></th> - <td><%= @count_relations[num].to_s_with_ts %></td> + <th><img width="16" height="16" alt="" src="/img/types/relation.16.png"/> <%= h(t.osm.relations) %></th> + <td><%= data[:count_relations].to_s_with_ts %></td> <td class="spacer"></td> </tr> </table> @@ -43,35 +43,36 @@ <% end %> </tr> <tr> - <% @keys.each_with_index do |key, num| %> - <td class="data key<%= num %>"> - <p><b><%= h(t.misc.prevalent_values) %>:</b></p> - <div class="prevalent_values"></div> + <% @data.each_with_index do |data, num| %> + <td class="data item<%= num %> prevalent_values"> + <p><b></b></p> + <div></div> </td> <% end %> </tr> <tr> - <% @keys.each_with_index do |key, num| %> - <td class="data key<%= num %>"> - <p><b><%= h(t.pages.key.wiki_pages.title) %>:</b></p> - <%= @wiki_pages[num].map{ |lang| '<span class="lang" title="' + ::Language[lang].native_name + '">' + lang + '</span>' }.join(' ') %> + <% @data.each_with_index do |data, num| %> + <td class="data item<%= num %> wiki"> + <p><b><%= data[:value].nil? ? h(t.pages.key.wiki_pages.title) : h(t.pages.tag.wiki_pages.title) %>:</b></p> + <%= data[:wiki_pages].map{ |lang| '<span class="lang" title="' + ::Language[lang].native_name + '">' + lang + '</span>' }.join(' ') %> </td> <% end %> </tr> <tr> - <% @keys.each_with_index do |key, num| %> - <td class="data key<%= num %>"> - <% if @has_map[num] %> + <% @data.each_with_index do |data, num| %> + <td class="data item<%= num %> map"> + <% if data[:has_map] %> <div style="background-image: url(<%= TaginfoConfig.get('geodistribution.background_image') %>); background-repeat: no-repeat; background-position: center 4px; background-size: <%= @img_width %>px <%= @img_height %>px; position: relative;"/> - <img class="map" src="/api/4/key/distribution/nodes?key=<%= key %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>" style="position: absolute;"/> - <img class="map" src="/api/4/key/distribution/ways?key=<%= key %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>"/> + <% key_or_tag = data[:value].nil? ? 'key' : 'tag' %> + <img class="map" src="/api/4/<%= key_or_tag %>/distribution/nodes?key=<%= data[:key] %><%= data[:value].nil? ? '' : ('&value=' + data[:value]) %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>" style="position: absolute;"/> + <img class="map" src="/api/4/<%= key_or_tag %>/distribution/ways?key=<%= data[:key] %><%= data[:value].nil? ? '' : ('&value=' + data[:value]) %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>"/> </div> <% end %> </td> <% end %> </tr> <tr> - <% @keys.each do |key| %> + <% @data.each_with_index do |data, num| %> <td class="data last"></td> <% end %> </tr> @@ -79,13 +80,18 @@ <% javascript do JS.raw(<<"JAVASCRIPT") function page_init2() { - var keys = #{ @keys.to_json }, - prevalent_values = #{ @prevalent_values.to_json }; - jQuery.each(keys, function(index, key) { - jQuery('.key' + index + ' h2').html(link_to_key(key)); - jQuery('.key' + index + ' div.prevalent_values').html(fmt_prevalent_value_list(key, prevalent_values[index])); + var data = #{ @data.to_json }; + jQuery.each(data, function(index, data) { + if (data.value) { + jQuery('.item' + index + ' h2').html(link_to_tag(data.key, data.value)); + } else { + jQuery('.item' + index + ' h2').html(link_to_key(data.key)); + jQuery('.item' + index + '.prevalent_values p b').html('#{ h(t.misc.prevalent_values)}:'); + jQuery('.item' + index + '.prevalent_values div').html(fmt_prevalent_value_list(data.key, data.prevalent_values)); + } }); - jQuery('div.prevalent_values a').tipsy({ opacity: 1, delayIn: 500, gravity: 'e' }); + jQuery('div.prevalent_values a').tipsy({ opacity: 1, delayIn: 500, gravity: 'w' }); + jQuery('span.lang').tipsy({ opacity: 1, delayIn: 500, gravity: 'n' }); } JAVASCRIPT end diff --git a/web/viewsjs/key_comparison.js.erb b/web/viewsjs/key_comparison.js.erb index 52dfbc3..a0044f7 100644 --- a/web/viewsjs/key_comparison.js.erb +++ b/web/viewsjs/key_comparison.js.erb @@ -1,7 +1,3 @@ -<% - osm = @trans.t.osm - misc = @trans.t.misc - %> function page_init() { up = function() { window.location = '/'; } page_init2(); |