Skip to content

Commit

Permalink
Display non-scraped definitions on stats page
Browse files Browse the repository at this point in the history
Showing missing config keys isn't that useful when the row is missing entirely
  • Loading branch information
Earlopain committed Oct 2, 2023
1 parent 3dedd75 commit 2b6af78
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def index
"count(distinct artist_url_id) as url_count",
"count(distinct artist_submission_id) as submission_count",
"count(*) as file_count",
).joins(artist_submission: { artist_url: :artist }).group(:site_type).reorder("").index_by(&:site_type)
).joins(artist_submission: { artist_url: :artist }).group(:site_type).index_by(&:site_type)
@counts.transform_keys! { |id| ArtistUrl.site_types.invert[id] }
@definitions = (Sites.scraper_definitions + [Sites.from_enum("manual")]).sort_by(&:display_name)
end

private
Expand Down
4 changes: 4 additions & 0 deletions app/logical/sites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def definitions
end
end

def scraper_definitions
definitions.select { |s| s.is_a?(ScraperDefinition) }
end

def reset_cache
@definitions = nil
end
Expand Down
13 changes: 7 additions & 6 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
</tr>
</thead>
<tbody>
<% @counts.keys.sort.map { |key| Sites.from_enum(key) }.each do |definition| %>
<% @definitions.each do |definition| %>
<tr>
<td><%= definition.display_name %></td>
<td><%= @counts[definition.enum_value]["artist_count"] %></td>
<td><%= @counts[definition.enum_value]["url_count"] %></td>
<td><%= @counts[definition.enum_value]["submission_count"] %></td>
<td><%= @counts[definition.enum_value]["file_count"] %></td>
<td><%= @counts[definition.enum_value]&.[]("artist_count") || 0 %></td>
<td><%= @counts[definition.enum_value]&.[]("url_count") || 0 %></td>
<td><%= @counts[definition.enum_value]&.[]("submission_count") || 0 %></td>
<td><%= @counts[definition.enum_value]&.[]("file_count") || 0 %></td>
<td>
<% if definition.manually_disabled? %>
Manually disabled
<% elsif definition.missing_config_keys.any? %>
Missing config <%= "key".pluralize(definition.missing_config_keys.count) %>: <%= definition.missing_config_keys.join(", ") %>
Missing config <%= "key".pluralize(definition.missing_config_keys.count) %>:<br>
<%= definition.missing_config_keys.join(", ") %>
<% else %>
Enabled
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion test/logical/scraper/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Scraper
class BaseTest < ActiveSupport::TestCase
Sites.definitions.select { |s| s.is_a?(Sites::ScraperDefinition) }.each do |definition|
Sites.scraper_definitions.each do |definition|
test "#{definition.enum_value} has correct state" do
scraper = stub_scraper_enabled(definition.enum_value) { definition.new_scraper(build(:artist_url)) }
assert_respond_to(scraper.class, :state)
Expand Down

0 comments on commit 2b6af78

Please sign in to comment.