summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2010-11-01 18:26:05 +0100
committerJochen Topf <jochen@topf.org>2010-11-01 18:29:33 +0100
commit94748c28692398b953a385a3316162a3b141f5d8 (patch)
tree264e317f3ef4af1eba8f5c94f7c6c523fc9d17e9 /web
parent1dc5013314a56a830a6d0f439866e7b18a217d5a (diff)
downloadtaginfo-94748c28692398b953a385a3316162a3b141f5d8.tar
taginfo-94748c28692398b953a385a3316162a3b141f5d8.tar.gz
Added reports
Added infrastructure for reports and the first report (not finished yet) Preparation for better wiki and merkaartor source inclusion
Diffstat (limited to 'web')
-rw-r--r--web/lib/api/reports.rb36
-rw-r--r--web/lib/ui/reports.rb23
-rw-r--r--web/public/js/taginfo.js4
-rwxr-xr-xweb/taginfo.rb4
-rw-r--r--web/views/key.erb11
-rw-r--r--web/views/reports/characters_in_keys.erb4
-rw-r--r--web/views/reports/frequently_used_keys_without_wiki_page.erb59
-rw-r--r--web/views/reports/index.erb14
8 files changed, 153 insertions, 2 deletions
diff --git a/web/lib/api/reports.rb b/web/lib/api/reports.rb
new file mode 100644
index 0000000..c16d85b
--- /dev/null
+++ b/web/lib/api/reports.rb
@@ -0,0 +1,36 @@
+# lib/api/reports.rb
+
+class Taginfo < Sinatra::Base
+
+ get '/api/2/reports/frequently_used_keys_without_wiki_page' do
+ min_count = params[:min_count].to_i || 10000
+ total = @db.count('db.keys').
+ condition('count_all > ?', min_count).
+ condition('in_wiki = 0').
+ condition_if("key LIKE '%' || ? || '%'", params[:query]).
+ get_first_value().to_i
+
+ res = @db.select('SELECT * FROM db.keys').
+ condition('count_all > ?', min_count).
+ condition('in_wiki = 0').
+ condition_if("key LIKE '%' || ? || '%'", params[:query]).
+ order_by([:key, :count_all, :values_all, :users_all], params[:sortname], params[:sortorder]).
+ 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['key'],
+ :count_all => row['count_all'].to_i,
+ :count_all_fraction => row['count_all'].to_f / @stats['objects'],
+ :values_all => row['values_all'].to_i,
+ :users_all => row['users_all'].to_i,
+ :prevalent_values => (row['prevalent_values'] || '').split('|').map{ |pv| pv }
+ } }
+ }.to_json
+ end
+
+end
diff --git a/web/lib/ui/reports.rb b/web/lib/ui/reports.rb
new file mode 100644
index 0000000..612ecd0
--- /dev/null
+++ b/web/lib/ui/reports.rb
@@ -0,0 +1,23 @@
+# lib/ui/reports.rb
+
+class Taginfo < Sinatra::Base
+
+ get '/reports/?' do
+ @title = 'Reports'
+ @breadcrumbs << @title
+ erb :'reports/index'
+ end
+
+ #--------------------------------------------------------------------------
+
+ ['Frequently Used Keys Without Wiki Page', 'Characters in Keys'].each do |title|
+ name = title.gsub(/ /, '_').downcase
+ get '/reports/' + name do
+ @title = title
+ @breadcrumbs << [ 'Reports', '/reports' ]
+ @breadcrumbs << title
+ erb ('reports/' + name).to_sym
+ end
+ end
+
+end
diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js
index 15d10af..b563315 100644
--- a/web/public/js/taginfo.js
+++ b/web/public/js/taginfo.js
@@ -4,6 +4,10 @@ function print_wiki_link(title) {
return '&rarr; <a class="wikilink" href="http://wiki.openstreetmap.org/wiki/' + title + '">' + title + '</a>';
}
+function print_wiki_edit_link(title) {
+ return '&rarr; <a class="wikilink" href="http://wiki.openstreetmap.org/w/index.php?action=edit&title=' + title + '">' + title + '</a>';
+}
+
function print_language(code, lang) {
return '<span class="lang" title="' + lang + '">' + code + '</span> ' + lang;
}
diff --git a/web/taginfo.rb b/web/taginfo.rb
index a9adcdd..0980c5f 100755
--- a/web/taginfo.rb
+++ b/web/taginfo.rb
@@ -170,6 +170,8 @@ class Taginfo < Sinatra::Base
@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
+
erb :key
end
@@ -308,6 +310,8 @@ class Taginfo < Sinatra::Base
load 'lib/api/db.rb'
load 'lib/api/wiki.rb'
load 'lib/api/josm.rb'
+ load 'lib/api/reports.rb'
+ load 'lib/ui/reports.rb'
load 'lib/test.rb'
# run application
diff --git a/web/views/key.erb b/web/views/key.erb
index 4d23cfd..8b8fbe7 100644
--- a/web/views/key.erb
+++ b/web/views/key.erb
@@ -53,8 +53,13 @@
</div>
<div id="tabs-wiki">
<h2>Wiki pages about this key</h2>
- <table id="wiki-langs">
- </table>
+ <% if @wiki_count > 0 %>
+ <table id="wiki-langs">
+ </table>
+ <% else %>
+ <p><i>No wiki page available for this key.</i></p>
+ <p>[<a href="http://wiki.openstreetmap.org/w/index.php?action=edit&title=<%= @key_uri %>">Create wiki page</a>]</p>
+ <% end %>
</div>
<div id="tabs-josm">
<h2>JOSM style rules with this key</h2>
@@ -194,6 +199,7 @@
}
});
+<% if @wiki_count > 0 %>
jQuery('#wiki-langs').flexigrid({
url: '/api/2/wiki/keys?key=<%= @key_uri %>',
method: 'GET',
@@ -236,6 +242,7 @@
};
}
});
+<% end %>
});
</script>
<script type="text/javascript+protovis">
diff --git a/web/views/reports/characters_in_keys.erb b/web/views/reports/characters_in_keys.erb
new file mode 100644
index 0000000..1396ae9
--- /dev/null
+++ b/web/views/reports/characters_in_keys.erb
@@ -0,0 +1,4 @@
+<h1><%= @title %></h1>
+
+<p>Any valid Unicode character can appear in an OSM key but usually only lower case latin letters (a-z) and the underscore (_) are used.</p>
+
diff --git a/web/views/reports/frequently_used_keys_without_wiki_page.erb b/web/views/reports/frequently_used_keys_without_wiki_page.erb
new file mode 100644
index 0000000..d5dd3ae
--- /dev/null
+++ b/web/views/reports/frequently_used_keys_without_wiki_page.erb
@@ -0,0 +1,59 @@
+<h1><%= @title %></h1>
+
+<p>This table shows keys that appear more than 10&thinsp;000 times in the OSM
+database but have no wiki page describing them. If you know anything about one
+of these keys, please create the wiki page by clicking on the link in the
+leftmost column and describe the key. Sometimes it might make sense to create a
+redirect to a different wiki page instead. To do this put just one line with
+<tt style="background-color: #f0f0f0; padding: 0 2px;">#REDIRECT [[<i>page name</i>]]</tt>
+in the wiki page.</p>
+
+<form>
+ <input type="checkbox" name="english" id="english" value="0"/> Also show keys that have no English language wiki page but a page in some other language.
+</form>
+<p></p>
+
+<table id="keys">
+</table>
+
+<script type="text/javascript">
+ jQuery(document).ready(function() {
+ jQuery('#keys').flexigrid({
+ url: '/api/2/reports/frequently_used_keys_without_wiki_page',
+ method: 'GET',
+ dataType: 'json',
+ colModel: [
+ { display: 'Create Wiki Page...', name: 'create_wiki_page', width: 200, sortable: false, align: 'left' },
+ { display: 'Key', name: 'key', width: 180, sortable: true, align: 'left' },
+ { display: '<span title="Number of objects with this key">Total</span>', name: 'count_all', width: 70, sortable: true, align: 'right' },
+ { display: 'Users', name: 'users_all', width: 44, sortable: true, align: 'right' },
+ { display: '<span title="Number of different values for this key">Values</span>', name: 'values_all', width: 70, sortable: true, align: 'right' },
+ { display: 'Prevalent Values', name: 'prevalent_values', width: 500, sortable: true, align: 'left' }
+ ],
+ searchitems: [
+ { display: 'Key', name: 'key' }
+ ],
+ sortname: 'count_all',
+ sortorder: 'desc',
+ showToggleBtn: false,
+ usepager: true,
+ useRp: true,
+ rp: 15,
+ rpOptions: [10,15,20,25,50,100],
+ height: 420,
+ preProcess: function(data) {
+ data.rows = jQuery.map(data.data, function(row, i) {
+ return { 'cell': [
+ print_wiki_edit_link('Key:' + row.key),
+ link_to_key(row.key),
+ print_with_ts(row.count_all),
+ print_with_ts(row.users_all),
+ print_with_ts(row.values_all),
+ print_tag_list(row.key, row.prevalent_values)
+ ] };
+ });
+ return data;
+ }
+ });
+ });
+</script>
diff --git a/web/views/reports/index.erb b/web/views/reports/index.erb
new file mode 100644
index 0000000..401bdd6
--- /dev/null
+++ b/web/views/reports/index.erb
@@ -0,0 +1,14 @@
+<h1>Reports</h1>
+
+<h2>Database</h2>
+
+<ul>
+ <li><a href="/reports/characters_in_keys">Characters in keys</a></li>
+</ul>
+
+<h2>Wiki</h2>
+
+<ul>
+ <li><a href="/reports/frequently_used_keys_without_wiki_page">Frequently used keys without wiki page</a></li>
+</ul>
+