diff options
-rw-r--r-- | web/i18n/de.yml | 1 | ||||
-rw-r--r-- | web/i18n/en.yml | 1 | ||||
-rw-r--r-- | web/lib/ui/key_comparison.rb | 46 | ||||
-rw-r--r-- | web/public/css/taginfo.css | 46 | ||||
-rwxr-xr-x | web/taginfo.rb | 1 | ||||
-rw-r--r-- | web/views/key_comparison.erb | 87 | ||||
-rw-r--r-- | web/viewsjs/key_comparison.js.erb | 8 |
7 files changed, 190 insertions, 0 deletions
diff --git a/web/i18n/de.yml b/web/i18n/de.yml index eb66b35..8c37489 100644 --- a/web/i18n/de.yml +++ b/web/i18n/de.yml @@ -44,6 +44,7 @@ taginfo: relations: Relations combinations: Kombinationen key_combinations: Kombinationen + key_comparison: Key-Vergleich overview: Übersicht data_from: Daten vom uses_data_from: | diff --git a/web/i18n/en.yml b/web/i18n/en.yml index cf6b581..dbd0015 100644 --- a/web/i18n/en.yml +++ b/web/i18n/en.yml @@ -45,6 +45,7 @@ taginfo: relations: Relations combinations: Combinations key_combinations: Combinations + key_comparison: Key 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 new file mode 100644 index 0000000..f130e5e --- /dev/null +++ b/web/lib/ui/key_comparison.rb @@ -0,0 +1,46 @@ +# 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 = [] + + @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_all AS count FROM tags"). + condition('key=?', key). + condition('count > ?', @count_all[num] * 0.02). + order_by([:count], 'DESC'). + execute().map{ |row| { 'value' => row['value'], 'count' => row['count'].to_i } } + @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 + + end + + @img_width = TaginfoConfig.get('geodistribution.width') + @img_height = TaginfoConfig.get('geodistribution.height') + + javascript "#{ r18n.locale.code }/key_comparison" + erb :key_comparison + end + +end + diff --git a/web/public/css/taginfo.css b/web/public/css/taginfo.css index 6de687c..7dd4e2f 100644 --- a/web/public/css/taginfo.css +++ b/web/public/css/taginfo.css @@ -426,6 +426,52 @@ table.list th.tr, table.list td.tr { /* ========== */ +table.comparison { + border-spacing: 10px 1px; + margin-left: -10px; + margin-right: -10px; +} + +table.comparison td.data h2 { + margin-top: 4px; + margin-bottom: 8px; +} + +table.comparison th.data, table.comparison td.data { + padding: 10px; + background-color: #e8e8e4; + vertical-align: top; + text-align: center; +} + +table.comparison td.first { + border-radius: 10px 10px 0 0; +} + +table.comparison td.last { + border-radius: 0 0 10px 10px; +} + +/* ========== */ + +table.compstat { + width: 100%; +} + +table.compstat th { + white-space: nowrap; + text-align: left; + width: 25%; +} + +table.compstat td { + white-space: nowrap; + text-align: right; + width: 25%; +} + +/* ========== */ + table.drilldown { border-collapse: separate; border-spacing: 10px; diff --git a/web/taginfo.rb b/web/taginfo.rb index 64523d1..d1b5050 100755 --- a/web/taginfo.rb +++ b/web/taginfo.rb @@ -218,6 +218,7 @@ class Taginfo < Sinatra::Base # user interface load 'lib/ui/embed.rb' load 'lib/ui/help.rb' + load 'lib/ui/key_comparison.rb' load 'lib/ui/keys.rb' load 'lib/ui/relation.rb' load 'lib/ui/reports.rb' diff --git a/web/views/key_comparison.erb b/web/views/key_comparison.erb new file mode 100644 index 0000000..2e89c2e --- /dev/null +++ b/web/views/key_comparison.erb @@ -0,0 +1,87 @@ +<div class="pre"> + <h1 class="section"><%= h(t.taginfo.key_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 %>%"> + <h2></h2> + <p><%= @desc[num] %></p> + </td> + <% end %> + </tr> + <tr> + <% @keys.each_with_index do |key, num| %> + <td class="data key<%= 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> + <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> + <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> + <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> + <td class="spacer"></td> + </tr> + </table> + </td> + <% end %> + </tr> + <tr> + <% @keys.each_with_index do |key, num| %> + <td class="data key<%= num %>"> + <p><b><%= h(t.misc.prevalent_values) %>:</b></p> + <%= @prevalent_values[num].map{ |pv| "#{ pv['value'] } (#{ pv['count'].to_s_with_ts })" }.join(' • ') %> + </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(' ') %> + </td> + <% end %> + </tr> + <tr> + <% @keys.each_with_index do |key, num| %> + <td class="data key<%= num %>"> + <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 %>"/> + </div> + </td> + <% end %> + </tr> + <tr> + <% @keys.each do |key| %> + <td class="data last"></td> + <% end %> + </tr> +</table> +<% javascript do + JS.raw(<<"JAVASCRIPT") +function page_init2() { + var keys = #{ @keys.to_json }; + jQuery.each(keys, function(index, key) { + jQuery('.key' + index + ' h2').html(link_to_key(key)); + }); +} +JAVASCRIPT +end +%> diff --git a/web/viewsjs/key_comparison.js.erb b/web/viewsjs/key_comparison.js.erb new file mode 100644 index 0000000..52dfbc3 --- /dev/null +++ b/web/viewsjs/key_comparison.js.erb @@ -0,0 +1,8 @@ +<% + osm = @trans.t.osm + misc = @trans.t.misc + %> +function page_init() { + up = function() { window.location = '/'; } + page_init2(); +} |