From 149c5f60b7b0e7ff7109ce513e020e4067dd8e68 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Sun, 18 May 2014 06:24:16 +0200 Subject: Rename /comparison page to /compare. --- web/lib/ui/compare.rb | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ web/lib/ui/comparison.rb | 74 ------------------------------------------------ 2 files changed, 74 insertions(+), 74 deletions(-) create mode 100644 web/lib/ui/compare.rb delete mode 100644 web/lib/ui/comparison.rb (limited to 'web/lib') diff --git a/web/lib/ui/compare.rb b/web/lib/ui/compare.rb new file mode 100644 index 0000000..4c08741 --- /dev/null +++ b/web/lib/ui/compare.rb @@ -0,0 +1,74 @@ +# web/lib/ui/compare.rb +class Taginfo < Sinatra::Base + + get %r{^/compare/(.*)} 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 : 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_i + data[:count_nodes] = @db.select("SELECT count_nodes FROM db.keys").condition('key = ?', key).get_first_i + data[:count_ways] = @db.select("SELECT count_ways FROM db.keys").condition('key = ?', key).get_first_i + data[:count_relations] = @db.select("SELECT count_relations FROM db.keys").condition('key = ?', key).get_first_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=? AND value=?', key, value).get_first_i + data[:count_nodes] = @db.select("SELECT count_nodes FROM db.tags").condition('key=? AND value=?', key, value).get_first_i + data[:count_ways] = @db.select("SELECT count_ways FROM db.tags").condition('key=? AND value=?', key, value).get_first_i + data[:count_relations] = @db.select("SELECT count_relations FROM db.tags").condition('key=? AND value=?', key, value).get_first_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=? AND value=?', key, value).get_first_i > 0) + end + end + + @img_width = TaginfoConfig.get('geodistribution.width') + @img_height = TaginfoConfig.get('geodistribution.height') + + javascript "#{ r18n.locale.code }/compare" + erb :compare + end + +end + diff --git a/web/lib/ui/comparison.rb b/web/lib/ui/comparison.rb deleted file mode 100644 index 936071e..0000000 --- a/web/lib/ui/comparison.rb +++ /dev/null @@ -1,74 +0,0 @@ -# web/lib/ui/comparison.rb -class Taginfo < Sinatra::Base - - get %r{^/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 : 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_i - data[:count_nodes] = @db.select("SELECT count_nodes FROM db.keys").condition('key = ?', key).get_first_i - data[:count_ways] = @db.select("SELECT count_ways FROM db.keys").condition('key = ?', key).get_first_i - data[:count_relations] = @db.select("SELECT count_relations FROM db.keys").condition('key = ?', key).get_first_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=? AND value=?', key, value).get_first_i - data[:count_nodes] = @db.select("SELECT count_nodes FROM db.tags").condition('key=? AND value=?', key, value).get_first_i - data[:count_ways] = @db.select("SELECT count_ways FROM db.tags").condition('key=? AND value=?', key, value).get_first_i - data[:count_relations] = @db.select("SELECT count_relations FROM db.tags").condition('key=? AND value=?', key, value).get_first_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=? AND value=?', key, value).get_first_i > 0) - end - end - - @img_width = TaginfoConfig.get('geodistribution.width') - @img_height = TaginfoConfig.get('geodistribution.height') - - javascript "#{ r18n.locale.code }/comparison" - erb :comparison - end - -end - -- cgit v1.2.3