diff options
author | Jochen Topf <jochen@topf.org> | 2010-11-14 17:26:50 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2010-11-14 17:26:50 +0100 |
commit | 214d1a003f83cee2e1cfa8712e5776a493c4ddbd (patch) | |
tree | 4e9cd1251f016b74ab07bbd6bbf928f689ef5e9f /web/lib | |
parent | e3c67aba97ddd5e729eb967988b898f9c2899143 (diff) | |
download | taginfo-214d1a003f83cee2e1cfa8712e5776a493c4ddbd.tar taginfo-214d1a003f83cee2e1cfa8712e5776a493c4ddbd.tar.gz |
combinations scatterplot test
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/ui/test.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/web/lib/ui/test.rb b/web/lib/ui/test.rb index dd5ff5c..eee4c6e 100644 --- a/web/lib/ui/test.rb +++ b/web/lib/ui/test.rb @@ -28,4 +28,56 @@ class Taginfo < Sinatra::Base erb :'test/wiki_import' end + get %r{^/test/keys/(.*)} do |key| + if params[:key].nil? + @key = key + else + @key = params[:key] + end + + @key_html = escape_html(@key) + @key_uri = escape(@key) + @key_json = @key.to_json + @key_pp = pp_key(@key) + + @title = [@key_html, 'Keys'] + @breadcrumbs << ['Keys', '/keys'] + @breadcrumbs << @key_html + + @filter_type = get_filter() + @sel = Hash.new('') + @sel[@filter_type] = ' selected="selected"' + + @count_all_values = @db.select("SELECT count_#{@filter_type} FROM db.keys").condition('key = ?', @key).get_first_value().to_i + + @desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value IS NULL", @key).get_first_value()) + @desc = '<i>no description in wiki</i>' if @desc == '' + + @prevalent_values = @db.select("SELECT value, count_#{@filter_type} AS count FROM tags"). + condition('key=?', @key). + condition('count > ?', @count_all_values * 0.02). + order_by(:count, 'DESC'). + execute().map{ |row| [{ 'value' => row['value'], 'count' => row['count'].to_i }] } + + # add "(other)" label for the rest of the values + sum = @prevalent_values.inject(0){ |sum, x| sum += x[0]['count'] } + if sum < @count_all_values + @prevalent_values << [{ 'value' => '(other)', 'count' => @count_all_values - sum }] + end + + @wiki_count = @db.count('wiki.wikipages').condition('value IS NULL').condition('key=?', @key).get_first_value().to_i + + (@merkaartor_type, @merkaartor_link, @merkaartor_selector) = @db.select('SELECT tag_type, link, selector FROM merkaartor.keys').condition('key=?', @key).get_columns(:tag_type, :link, :selector) + @merkaartor_images = [:node, :way, :area, :relation].map{ |type| + name = type.to_s.capitalize + '<img src="/img/types/' + (@merkaartor_selector =~ /Type is #{name}/ ? type.to_s : 'none') + '.16.png" alt="' + name + '" title="' + name + '"/>' + }.join(' ') + + @merkaartor_values = @db.select('SELECT value FROM merkaartor.tags').condition('key=?', @key).order_by(:value).execute().map{ |row| row['value'] } + + @merkaartor_desc = @db.select('SELECT lang, description FROM key_descriptions').condition('key=?', @key).order_by(:lang).execute() + + erb :'test/key' + end + end |