Skip to content

Commit

Permalink
ajusting show values from unity_procon graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLupiano authored and MaxAlmeida committed Nov 28, 2014
1 parent 914c4e1 commit 3179245
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
31 changes: 31 additions & 0 deletions app/controllers/unity_procons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def show
@rating = Rating.new
@ratings = Rating.where("unity_procon_id = ?", params[:id]).order("created_at DESC")
@ratingpie = Rating.where("unity_procon_id = ?", params[:id])
@rating_hash = return_hash

@hash = Gmaps4rails.build_markers(@unity_procon) do |unity_procon, marker|
marker.lat unity_procon.latitude
Expand All @@ -22,6 +23,36 @@ def show

end

def return_hash
hash = Hash.new
all_rating = Rating.where("unity_procon_id = ?", params[:id])

all_rating.each do |rating|

case rating.value_rating
when 1
ratings = Rating.all.select { |m| m.value_rating == rating.value_rating }
hash["Péssimo"] = ratings.count
when 2
ratings = Rating.all.select { |m| m.value_rating == rating.value_rating }
hash["Ruim"] = ratings.count
when 3
ratings = Rating.all.select { |m| m.value_rating == rating.value_rating }
hash["Regular"] = ratings.count
when 4
ratings = Rating.all.select { |m| m.value_rating == rating.value_rating }
hash["Bom"] = ratings.count
when 5
ratings = Rating.all.select { |m| m.value_rating == rating.value_rating }
hash["Ótimo"] = ratings.count
else
#nothing to do
end
end

hash
end

def ranking
@unity_procons = UnityProcon.order(:position_unity_procon)
end
Expand Down
7 changes: 5 additions & 2 deletions app/views/unity_procons/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@
</span>
<br>
<% @ratingpie.order("value_rating") %>
<%= pie_chart @ratingpie.group("value_rating").count, height: "200px", colors: ["#FF0000","#FF8000","#FFFF00","#00FF00","#0040FF"] %>
<%= pie_chart @rating_hash, {library: {tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'

}}} %>
<center><h2>Nota: <%= a.average_pontuation %></h2></center>
<br>

<% end %>
<% end %>
<% if url_for(:back)=="http://0.0.0.0:3000/avaliar" %>
<span style="color:#FFA500">
Expand Down

0 comments on commit 3179245

Please sign in to comment.