Skip to content

Commit

Permalink
Add summary data
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan8902 committed Feb 20, 2024
1 parent b72cfd5 commit 00075b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 13 additions & 11 deletions app/controllers/pub_thursday_audit_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ def index
response = JSON.parse(RestClient.get(url).body)
documents.concat response["documents"]

next_page = "#{url}&pageToken=#{response["nextPageToken"]}"
response = JSON.parse(RestClient.get(next_page).body)
documents.concat response["documents"]

next_page = "#{url}&pageToken=#{response["nextPageToken"]}"
response = JSON.parse(RestClient.get(next_page).body)
documents.concat response["documents"]

next_page = "#{url}&pageToken=#{response["nextPageToken"]}"
response = JSON.parse(RestClient.get(next_page).body)
documents.concat response["documents"]
4.times do
next_page = "#{url}&pageToken=#{response["nextPageToken"]}"
response = JSON.parse(RestClient.get(next_page).body)
documents.concat response["documents"]
end

documents.each do |session|
ref = session["fields"]["userRef"]["referenceValue"]
Expand Down Expand Up @@ -83,6 +77,14 @@ def index
v[:illegal].nil?
end

@worst_offenders = []
@users.each do |key, user|
hours = user[:sessions].map { |session| session[:end].to_i - session[:start].to_i }.sum.to_f / 60 / 60
@worst_offenders << { user: user.except(:sessions), number: user[:sessions].length, hours: hours.round(2) }
end

@worst_offenders.sort! { |a, b| b[:hours] <=> a[:hours] }

respond_to do |format|
format.html # index.html.erb
format.json { render json: @users, callback: params[:callback] }
Expand Down
15 changes: 14 additions & 1 deletion app/views/pub_thursday_audit/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@
Here is an audit of sessions where they overlap another.
</p>

<h3>Worst Offenders</h2>
<table class="table">
<% @worst_offenders.each do |offender| %>
<tr>
<td><img width="25" height="25" class="img-circle" src="<%= offender[:user][:photo] %>"></td>
<td><%= offender[:user][:name] %></td>
<td><%= offender[:number] %> dodgy sessions</td>
<td><%= offender[:hours] %> dodgy hours</td>
</tr>
<% end %>
</table>

<h3>Raw Data</h3>
<section class="row">
<% @users.each do |key, user| %>
<article class="col-md-4">
<h2>
<img alt="Gravatar" width="50" height="50" class="img-circle" src="<%= user[:photo] %>">
<img width="50" height="50" class="img-circle" src="<%= user[:photo] %>">
<%= user[:name] %>
</h2>
<% user[:sessions].each do |session| %>
Expand Down

0 comments on commit 00075b9

Please sign in to comment.