aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sources/db/pre.sql8
-rw-r--r--sources/master/master.sql40
-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
10 files changed, 182 insertions, 21 deletions
diff --git a/sources/db/pre.sql b/sources/db/pre.sql
index 9404aaa..0163089 100644
--- a/sources/db/pre.sql
+++ b/sources/db/pre.sql
@@ -43,8 +43,10 @@ CREATE TABLE keys (
users_relations INTEGER DEFAULT 0,
grids INTEGER DEFAULT 0,
in_wiki INTEGER DEFAULT 0,
+ in_wiki_en INTEGER DEFAULT 0,
in_josm INTEGER DEFAULT 0,
in_potlatch INTEGER DEFAULT 0,
+ in_merkaartor INTEGER DEFAULT 0,
prevalent_values TEXT
);
@@ -64,9 +66,13 @@ CREATE TABLE tags (
count_nodes INTEGER DEFAULT 0,
count_ways INTEGER DEFAULT 0,
count_relations INTEGER DEFAULT 0,
+ object_type VARCHAR(1), -- (n)ode, (w)ay, (r)elation
+ object_id INTEGER,
in_wiki INTEGER DEFAULT 0,
+ in_wiki_en INTEGER DEFAULT 0,
in_josm INTEGER DEFAULT 0,
- in_potlatch INTEGER DEFAULT 0
+ in_potlatch INTEGER DEFAULT 0,
+ in_merkaartor INTEGER DEFAULT 0
);
DROP TABLE IF EXISTS keypairs;
diff --git a/sources/master/master.sql b/sources/master/master.sql
index d6d28af..eeaf93a 100644
--- a/sources/master/master.sql
+++ b/sources/master/master.sql
@@ -38,8 +38,9 @@ INSERT INTO master_stats SELECT * FROM db.stats
INSERT INTO db.keys (key) SELECT DISTINCT key FROM wiki.wikipages WHERE key NOT IN (SELECT key FROM db.keys);
INSERT INTO db.keys (key) SELECT DISTINCT k FROM josm.josm_style_rules WHERE k NOT IN (SELECT key FROM db.keys);
-- potlatch XXX
-UPDATE db.keys SET in_wiki=1 WHERE key IN (SELECT key FROM wiki.wikipages);
-UPDATE db.keys SET in_josm=1 WHERE key IN (SELECT k FROM josm.josm_style_rules);
+UPDATE db.keys SET in_wiki=1 WHERE key IN (SELECT distinct key FROM wiki.wikipages);
+UPDATE db.keys SET in_wiki_en=1 WHERE key IN (SELECT distinct key FROM wiki.wikipages WHERE lang='en');
+UPDATE db.keys SET in_josm=1 WHERE key IN (SELECT distinct k FROM josm.josm_style_rules);
-- potlatch XXX
-- too slow, so we drop it for now
@@ -49,20 +50,22 @@ UPDATE db.keys SET in_josm=1 WHERE key IN (SELECT k FROM josm.josm_style_rules);
DROP TABLE IF EXISTS popular_keys;
CREATE TABLE popular_keys (
- key VARCHAR,
- count INTEGER,
- users INTEGER,
- wikipages INTEGER DEFAULT 0,
- in_wiki INTEGER DEFAULT 0,
- in_josm INTEGER DEFAULT 0,
- in_potlatch INTEGER DEFAULT 0,
- scale_count REAL,
- scale_users REAL,
- scale_wiki REAL,
- scale_josm REAL,
- scale_name REAL,
- scale1 REAL,
- scale2 REAL
+ key VARCHAR,
+ count INTEGER,
+ users INTEGER,
+ wikipages INTEGER DEFAULT 0,
+ in_wiki INTEGER DEFAULT 0,
+ in_wiki_en INTEGER DEFAULT 0,
+ in_josm INTEGER DEFAULT 0,
+ in_potlatch INTEGER DEFAULT 0,
+ in_merkaartor INTEGER DEFAULT 0,
+ scale_count REAL,
+ scale_users REAL,
+ scale_wiki REAL,
+ scale_josm REAL,
+ scale_name REAL,
+ scale1 REAL,
+ scale2 REAL
);
INSERT INTO popular_keys (key, count, users)
@@ -71,8 +74,9 @@ INSERT INTO popular_keys (key, count, users)
-- count number of wikipages for each key
UPDATE popular_keys SET wikipages = (SELECT count(*) FROM wiki.wikipages w WHERE w.key=popular_keys.key);
-UPDATE popular_keys SET in_wiki=1 WHERE key IN (SELECT key FROM wiki.wikipages);
-UPDATE popular_keys SET in_josm=1 WHERE key IN (SELECT k FROM josm.josm_style_rules);
+UPDATE popular_keys SET in_wiki=1 WHERE key IN (SELECT distinct key FROM wiki.wikipages);
+UPDATE popular_keys SET in_wiki_en=1 WHERE key IN (SELECT distinct key FROM wiki.wikipages WHERE lang='en');
+UPDATE popular_keys SET in_josm=1 WHERE key IN (SELECT distinct k FROM josm.josm_style_rules);
DROP TABLE IF EXISTS popular_metadata;
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>
+