summaryrefslogtreecommitdiff
path: root/web/lib
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2011-12-30 13:59:56 +0100
committerJochen Topf <jochen@topf.org>2011-12-30 13:59:56 +0100
commit56a53d12ecb0737bcfb2549904a244026665a336 (patch)
treebbedcc665ba75a6c6d402a27d1028d4c25805761 /web/lib
parent0fb5e28869f2853f6e46f6500321fb0aac9bfba1 (diff)
downloadtaginfo-56a53d12ecb0737bcfb2549904a244026665a336.tar
taginfo-56a53d12ecb0737bcfb2549904a244026665a336.tar.gz
Add tags overview page.
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/api/db.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/web/lib/api/db.rb b/web/lib/api/db.rb
index 0a6e339..17d8887 100644
--- a/web/lib/api/db.rb
+++ b/web/lib/api/db.rb
@@ -137,6 +137,63 @@ class Taginfo < Sinatra::Base
}.to_json
end
+ api(2, 'db/tags', {
+ :description => 'Get list of most often used tags.',
+ :parameters => { :query => 'Only show tags matching this query (substring match in key and value, optional).' },
+ :paging => :optional,
+ :sort => %w( tag count_all count_nodes count_ways count_relations ),
+ :result => {
+ :key => :STRING,
+ :value => :STRING,
+ :count_all => :INT,
+ :count_all_fraction => :FLOAT,
+ :count_nodes => :INT,
+ :count_nodes_fraction => :FLOAT,
+ :count_ways => :INT,
+ :count_ways_fraction => :FLOAT,
+ :count_relations => :INT,
+ :count_relations_fraction => :FLOAT,
+ },
+ :example => { :page => 1, :rp => 10, :sortname => 'tag', :sortorder => 'asc' },
+ :ui => '/tags'
+ }) do
+
+ total = @db.count('db.selected_tags').
+ condition_if("(skey LIKE '%' || ? || '%') OR (svalue LIKE '%' || ? || '%')", params[:query], params[:query]).
+ get_first_value().to_i
+
+ res = @db.select('SELECT * FROM db.selected_tags').
+ condition_if("(skey LIKE '%' || ? || '%') OR (svalue LIKE '%' || ? || '%')", params[:query], params[:query]).
+ order_by(params[:sortname], params[:sortorder]) { |o|
+ o.tag :skey
+ o.tag :svalue
+ o.count_all
+ o.count_nodes
+ o.count_ways
+ o.count_relations
+ }.
+ paging(params[:rp], params[:page]).
+ execute()
+
+ return {
+ :page => params[:page].to_i,
+ :rp => params[:rp].to_i,
+ :total => total,
+ :data => res.map{ |row| {
+ :key => row['skey'],
+ :value => row['svalue'],
+ :count_all => row['count_all'].to_i,
+ :count_all_fraction => row['count_all'].to_f / @db.stats('objects'),
+ :count_nodes => row['count_nodes'].to_i,
+ :count_nodes_fraction => row['count_nodes'].to_f / @db.stats('nodes_with_tags'),
+ :count_ways => row['count_ways'].to_i,
+ :count_ways_fraction => row['count_ways'].to_f / @db.stats('ways'),
+ :count_relations => row['count_relations'].to_i,
+ :count_relations_fraction => row['count_relations'].to_f / @db.stats('relations'),
+ } }
+ }.to_json
+ end
+
api(2, 'db/keys/overview', {
:description => 'Show statistics for nodes, ways, relations and total for this key.',
:parameters => { :key => 'Tag key (required).' },