Skip to content

Commit

Permalink
download stats with month ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
cesswairimu committed Feb 5, 2019
1 parent 1523829 commit da19418
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 25 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,10 @@ div.note.moderated h4 {
opacity: 0.6;
background-color: #e3f2fd;
}
textarea, input {
padding:10px;
font-family: FontAwesome, "Open Sans", Verdana, sans-serif;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
}
20 changes: 15 additions & 5 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,35 @@ def stats_json
end

def notes
export_as_json('note')
time
export_as_json(@start, @end, 'note')
end

def wikis
export_as_json('wiki')
time
export_as_json(@start, @end, 'page')
end

def comments
data = Comment.where(status: 1).all.to_json
time
data = Comment.select(%i(status timestamp)).where(status: 1, timestamp: @start.to_i...@end.to_i).all.to_json
send_data data, :type => 'application/json; header=present', :disposition => "attachment; filename=comment.json"
end

private

def export_as_json(type)
data = Node.where(type: type, status: 1).all.to_json
def export_as_json(starting, ending, type)
data = Node.select(%i(status created type))
.where(type: type, status: 1, created: starting.to_i..ending.to_i)
.all.to_json
send_data data, :type => 'application/json; header=present', :disposition => "attachment; filename=#{type}.json"
end

def time
@start = params[:start] ? Time.parse(params[:start].to_s) : Time.now - 1.month
@end = params[:end] ? Time.parse(params[:end].to_s) : Time.now
end

def to_keyword(param)
1.send(param.downcase)
end
Expand Down
58 changes: 38 additions & 20 deletions app/views/stats/stats_json.html.erb
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
<h2 align="center"> Stats in Json </h2>
<hr>
<div class="row">
<div class="col-md-6">
<%= form_tag request.url, method: :get do %>
<h5>Choose dates to download raw data of content created within that period</h5>
<br>
<input data-provide="datepicker" data-date="<%= Date.today.strftime("%d-%m-%Y") %>" data-date-format="dd-mm-yyyy" data-date-max-view-mode="years" data-date-min-view-mode="months" tabindex="1" class="form-control input-lg" type="text" name="start" placeholder="&#xf133; Select start date">
<br>
<input data-provide="datepicker" data-date="<%= Date.today.strftime("%d-%m-%Y") %>" data-date-format="dd-mm-yyyy" data-date-max-view-mode="years" data-date-min-view-mode="months" tabindex="1" class="form-control input-lg" type="text" name="end" placeholder="&#xf133; Select end date">
<br>
<%= submit_tag "Go", class: 'btn btn-secondary' %>
<% end %>
<br>
</div>
</div>
<br>
<h5>Stats from From <%= params[:start] %> to <%= params[:end] %></h5>
<br>
<div class="btn-group" align="center" role="group" aria-label="Basic example">
<a href= "/stats">
<button type="button" class="btn btn-primary" title=" Back to Stats">
<i class="fa fa-arrow-left fa-2x" style="color:#fff;"> </i>
</button>
</a>
<a href= "/stats/notes">
<button type="button" class="btn-lg btn-primary" title="Download notes">
Download notes as Json
</button>
</a>
<a href= "/stats/notes">
<%= link_to stats_path do %>
<button type="button" class="btn btn-secondary" title=" Back to Stats">
<i class="fa fa-arrow-left fa-2x" style="color:#0088cc;"> </i>
</button>
<button type="button" class="btn-lg btn-primary" title="Download wikis">
Download wikis as Json
<% end %>

<%= link_to stats_notes_path(start: params[:start], end: params[:end]) do %>
<button type="button" class="btn-lg btn-secondary" title="Download notes">
Download notes
</button>
</a>
<a href= "/stats/comments">
<% end %>

<%= link_to stats_wikis_path(start: params[:start], end: params[:end]) do %>
<button type="button" class="btn-lg btn-secondary" title="Download wikis">
Download wikis
</button>
<button type="button" class="btn-lg btn-primary" title="Download wikis">
Download comments as Json
<% end %>

<%= link_to stats_comments_path(start: params[:start], end: params[:end]) do %>
<button type="button" class="btn-lg btn-secondary" title="Download wikis">
Download comments
</button>
</a>
<% end %>
</div>
<br> <br>
<% @hash.each do |k,v| %>
<p><b><%= k %> </b></p>
<p><%= v %> </p>
<p><b><%= k %> </b></p>
<p><%= v %> </p>
<% end %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@
get 'stats/range/:start/:end' => 'stats#range'
get 'stats/subscriptions' => 'stats#subscriptions'
get 'stats/notes' => 'stats#notes'
get 'stats/notes/:start/:end' => 'stats#notes'
get 'stats/wikis' => 'stats#wikis'
get 'stats/wikis/:start/:end' => 'stats#wikis'
get 'stats/comments' => 'stats#comments'
get 'stats/comments/:start/:end' => 'stats#comments'
get 'stats/json' => 'stats#stats_json'
get 'feed' => 'notes#rss'
get 'rss.xml' => 'legacy#rss'
Expand Down

0 comments on commit da19418

Please sign in to comment.