summaryrefslogtreecommitdiff
path: root/web/lib/ui
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2014-05-15 20:49:20 +0200
committerJochen Topf <jochen@topf.org>2014-05-15 20:49:20 +0200
commit8addee3d7b3e1f745a75f3dbdcf278277801835a (patch)
tree57e1927a6996093e07d6bb8deddd1c80b967dfcc /web/lib/ui
parent13dc9ce483faecb945000ae8d8510a962cce93c3 (diff)
downloadtaginfo-8addee3d7b3e1f745a75f3dbdcf278277801835a.tar
taginfo-8addee3d7b3e1f745a75f3dbdcf278277801835a.tar.gz
Add Key Comparison page.
This allows comparing of two or more (up to five) keys on one page. No link currently points to this page.
Diffstat (limited to 'web/lib/ui')
-rw-r--r--web/lib/ui/key_comparison.rb46
1 files changed, 46 insertions, 0 deletions
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
+