Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There is a whole new relations section which gives information about different relation types. There is a list of all relation types and there is a page for each relation type which currently contains an empty overview tab and a roles tab with a list of roles used with this relation type. There is currently no link that leads to this section as it is not finished yet.
- Loading branch information
Showing
11 changed files
with
409 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# web/lib/api/v4/relation.rb | ||
|
||
class Taginfo < Sinatra::Base | ||
|
||
api(4, 'relation/roles', { | ||
:description => 'Member role statistics for a relation of given type.', | ||
:parameters => { | ||
:type => 'Relation type (required).', | ||
:query => 'Only show results where the role matches this query (substring match, optional).' | ||
}, | ||
:paging => :optional, | ||
:sort => %w( role count_all_members count_node_members count_way_members count_relation_members ), | ||
:result => paging_results([ | ||
[:relation_type, :STRING, 'Relation type'], | ||
[:role, :STRING, 'Relation member role.'], | ||
[:count_all_members, :INT, 'Number of members with this role.'], | ||
[:count_all_members_fraction, :FLOAT, 'Number of members with this role devided by all members.'], | ||
[:count_node_members, :INT, 'Number of members of type node with this role.'], | ||
[:count_node_members_fraction, :FLOAT, 'Number of members of type node with this role devided by all members of type node.'], | ||
[:count_way_members, :INT, 'Number of members of type way with this role.'], | ||
[:count_way_members_fraction, :FLOAT, 'Number of members of type way with this role devided by all members of type way.'], | ||
[:count_relation_members, :INT, 'Number of members of type relation with this role.'], | ||
[:count_relation_members_fraction, :FLOAT, 'Number of members of type relation with this role devided by all members of type relation.'] | ||
]), | ||
:example => { :role => 'multipolygon', :page => 1, :rp => 10 }, | ||
:ui => '/reports/relation_types#roles' | ||
}) do | ||
rtype = params[:type] | ||
|
||
relation_type_info = @db.select('SELECT * FROM relation_types'). | ||
condition("rtype=?", rtype). | ||
execute()[0] | ||
|
||
total = @db.count('relation_roles'). | ||
condition("rtype=?", rtype). | ||
condition_if("role LIKE '%' || ? || '%'", params[:query]). | ||
get_first_value().to_i | ||
|
||
res = @db.select('SELECT * FROM relation_roles'). | ||
condition("rtype=?", rtype). | ||
condition_if("role LIKE '%' || ? || '%'", params[:query]). | ||
order_by(@ap.sortname, @ap.sortorder) { |o| | ||
o.role | ||
o.count_all_members :count_all | ||
o.count_node_members :count_nodes | ||
o.count_way_members :count_ways | ||
o.count_relation_members :count_relations | ||
}. | ||
paging(@ap). | ||
execute() | ||
|
||
return { | ||
:page => @ap.page, | ||
:rp => @ap.results_per_page, | ||
:total => total, | ||
:data => res.map{ |row| { | ||
:relation_type => row['rtype'], | ||
:role => row['role'], | ||
:count_all_members => row['count_all'].to_i, | ||
:count_all_members_fraction => (row['count_all'].to_f / relation_type_info['members_all'].to_i).round_to(4), | ||
:count_node_members => row['count_nodes'].to_i, | ||
:count_node_members_fraction => (row['count_nodes'].to_f / relation_type_info['members_nodes'].to_i).round_to(4), | ||
:count_way_members => row['count_ways'].to_i, | ||
:count_way_members_fraction => (row['count_ways'].to_f / relation_type_info['members_ways'].to_i).round_to(4), | ||
:count_relation_members => row['count_relations'].to_i, | ||
:count_relation_members_fraction => (row['count_relations'].to_f / relation_type_info['members_relations'].to_i).round_to(4), | ||
} } | ||
}.to_json | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# web/lib/api/v4/relations.rb | ||
|
||
class Taginfo < Sinatra::Base | ||
|
||
api(4, 'relations/all', { | ||
:description => 'Information about the different relation types.', | ||
:parameters => { | ||
:query => 'Only show results where the relation type matches this query (substring match, optional).' | ||
}, | ||
:paging => :optional, | ||
:sort => %w( relation_type count ), | ||
:result => paging_results([ | ||
[:relation_type, :STRING, 'Relation type'], | ||
[:count, :INT, 'Number of relations with this type.'], | ||
[:count_fraction, :INT, 'Number of relations with this type divided by the overall number of relations.'], | ||
[:prevalent_roles, :ARRAY, 'Prevalent member roles.', [ | ||
[:role, :STRING, 'Member role'], | ||
[:count, :INT, 'Number of members with this role.'], | ||
[:fraction, :FLOAT, 'Number of members with this role divided by all members.'] | ||
]] | ||
]), | ||
:notes => "prevalent_roles can be null if taginfo doesn't have role information for this relation type, or an empty array when there are no roles with more than 1% of members", | ||
:example => { :page => 1, :rp => 10 }, | ||
:ui => '/reports/relation_types#types' | ||
}) do | ||
total = @db.count('relation_types'). | ||
condition_if("rtype LIKE '%' || ? || '%'", params[:query]). | ||
get_first_value().to_i | ||
|
||
res = @db.select('SELECT * FROM relation_types'). | ||
condition_if("rtype LIKE '%' || ? || '%'", params[:query]). | ||
order_by(@ap.sortname, @ap.sortorder) { |o| | ||
o.relation_type :rtype | ||
o.count | ||
}. | ||
paging(@ap). | ||
execute() | ||
|
||
all_relations = @db.stats('relations') | ||
|
||
prevroles = @db.select('SELECT rtype, role, count, fraction FROM db.prevalent_roles'). | ||
condition("rtype IN (#{ res.map{ |row| "'" + SQLite3::Database.quote(row['rtype']) + "'" }.join(',') })"). | ||
order_by([:count], 'DESC'). | ||
execute() | ||
|
||
pr = {} | ||
res.each do |row| | ||
pr[row['rtype']] = [] | ||
end | ||
|
||
prevroles.each do |pv| | ||
rtype = pv['rtype'] | ||
pv.delete_if{ |k,v| k.is_a?(Integer) || k == 'rtype' } | ||
pv['count'] = pv['count'].to_i | ||
pv['fraction'] = pv['fraction'].to_f | ||
pr[rtype] << pv | ||
end | ||
|
||
return { | ||
:page => @ap.page, | ||
:rp => @ap.results_per_page, | ||
:total => total, | ||
:data => res.map{ |row| { | ||
:relation_type => row['rtype'], | ||
:count => row['count'].to_i, | ||
:count_fraction => row['count'].to_i / all_relations, | ||
:prevalent_roles => row['members_all'] ? pr[row['rtype']][0,10] : nil | ||
} } | ||
}.to_json | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# web/lib/ui/relations.rb | ||
class Taginfo < Sinatra::Base | ||
|
||
get %r{^/relations/(.*)} do |rtype| | ||
if params[:rtype].nil? | ||
@rtype = rtype | ||
else | ||
@rtype = params[:rtype] | ||
end | ||
|
||
@title = [escape_html(@rtype), t.osm.relations] | ||
section :relations | ||
|
||
@desc = 'XXX' | ||
|
||
javascript "#{ r18n.locale.code }/relation" | ||
erb :relation | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="pre"> | ||
<h1><%= t.pages.relation.name %> '<%= pp_rtype(@rtype) %>'</h1> | ||
<p><%= @desc %></p> | ||
</div> | ||
<div id="tabs"> | ||
<ul> | ||
<li><a href="#overview"><%= t.pages.relation.overview.tab %></a></li> | ||
<li><a href="#roles"><%= t.pages.relation.roles.tab %></a></li> | ||
</ul> | ||
<div id="overview"> | ||
<h2><%= t.pages.relation.overview.title %></h2> | ||
</div> | ||
<div id="roles"> | ||
<h2><%= t.pages.relation.roles.title %></h2> | ||
<table id="grid-roles"> | ||
</table> | ||
</div> | ||
</div> | ||
<% javascript do | ||
JS.raw(<<"JAVASCRIPT") | ||
function page_init2() { | ||
init_tabs([#{ @rtype.to_json }]); | ||
} | ||
JAVASCRIPT | ||
end | ||
%> |
Oops, something went wrong.