Skip to content

Commit

Permalink
implemented tags/node_tags stats downloading (publiclab#5459)
Browse files Browse the repository at this point in the history
* added routes for tags and node_tags to routes.rb

* added controllers for tags and node_tags

* added tags/node_tags to json/csv download dropdowns

* removed extra carraige return

* second attempt to remove white space from line 107

* 3rd attempt at removing white space

* removed extra colon from retyping code from last commit

* correct misnaming in stats_controller.rb

Co-Authored-By: skilfullycurled <[email protected]>

* corrected route to matching exemplars in lines above

Co-Authored-By: skilfullycurled <[email protected]>

* removed extra <li> tag

Co-Authored-By: skilfullycurled <[email protected]>

* removed additional extra <li> tag

* Update app/controllers/stats_controller.rb

Co-Authored-By: skilfullycurled <[email protected]>

* added extend RawStats to tag model for csv download

* added extend RawStats to node_tag model for csv download

* updated tests for new tags/node_tag downloads
  • Loading branch information
skilfullycurled authored and jywarren committed Apr 18, 2019
1 parent 1c73fe0 commit ee71408
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ def comments
format(data, 'comment')
end

def tags
data = Tag.select(:tid, :name, :parent, :count).all
format(data, 'tag')
end

def node_tags
data = NodeTag.select(:tid, :nid, :uid).where(date: start.to_i...fin.to_i).all
format(data, 'node_tag')
end

def export_as_json(type)
data = Node.published
.where(type: type, created: start.to_i..fin.to_i)
Expand Down
1 change: 1 addition & 0 deletions app/models/node_tag.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class NodeTag < ApplicationRecord
extend RawStats
self.table_name = 'community_tags'
self.primary_keys = :tid, :nid
belongs_to :node, foreign_key: 'nid'
Expand Down
1 change: 1 addition & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Tag < ApplicationRecord
extend RawStats
self.table_name = 'term_data'
self.primary_key = 'tid'

Expand Down
13 changes: 12 additions & 1 deletion app/views/stats/_range.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<li>
<%= link_to "Questions Answered", stats_answers_path(format: 'json', start: params[:start], end: params[:end]) %>
</li>
<li>
<%= link_to "List of Tags", stats_tags_path(format: 'json') %>
</li>
<li>
<%= link_to "Tag Usage", stats_node_tags_path(format: 'json', start: params[:start], end: params[:end])%>
</li>
</ul>
</div>
</div>
Expand All @@ -83,7 +89,6 @@
<li>
<%= link_to "Comments", stats_comments_path(format: 'csv', start: params[:start], end: params[:end]) %>
</li>
<li>
<li>
<%= link_to "Users", stats_users_path(format: 'csv', start: params[:start], end: params[:end]) %>
</li>
Expand All @@ -93,6 +98,12 @@
<li>
<%= link_to "Questions Answered", stats_answers_path(format: 'csv', start: params[:start], end: params[:end]) %>
</li>
<li>
<%= link_to "List of Tags", stats_tags_path(format: 'csv') %>
</li>
<li>
<%= link_to "Tag Usage", stats_node_tags_path(format: 'csv', start: params[:start], end: params[:end])%>
</li>
</ul>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@
get 'stats/questions/:start/:end' => 'stats#questions'
get 'stats/answers' => 'stats#answers'
get 'stats/answers/:start/:end' => 'stats#answers'
get 'stats/tags' => 'stats#tags'
get 'stats/node_tags' => 'stats#node_tags'
get 'stats/node_tags/:start/:end' => 'stats#node_tags'
get 'feed' => 'notes#rss'
get 'rss.xml' => 'legacy#rss'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/stats_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class StatsControllerTest < ActionController::TestCase
def setup
@start = 1.month.ago.to_time
@end = Date.today.to_time
@stats = [:notes, :comments, :users, :wikis, :questions, :answers]
@stats = [:notes, :comments, :users, :wikis, :questions, :answers, :tags, :node_tags]
end

test 'should assign correct value to graph_notes on GET stats' do
Expand Down

0 comments on commit ee71408

Please sign in to comment.