Skip to content

Commit

Permalink
Make single hash for ALL_FIELDS work
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Mar 4, 2024
1 parent f81e8a4 commit 5e23dd8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
7 changes: 2 additions & 5 deletions app/helpers/user_stats_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ module UserStatsHelper
# Rows are roughly in decreasing order of importance.
def user_stats_rows(show_user, user_data)
rows = []
# omit sequence stuff because it has no weight
(SiteData::ALL_FIELDS -
SiteData::SITE_WIDE_FIELDS -
[:sequences, :sequenced_observations]).each do |field|
SiteData.user_fields_with_weight.keys.each do |field|
rows << {
field: field,
label: :"user_stats_#{field}".t,
count: (count = user_data[field].to_i),
weight: (weight = SiteData::FIELD_WEIGHTS[field]),
weight: (weight = SiteData::ALL_FIELDS[field][:weight]),
points: count * weight
}
end
Expand Down
14 changes: 7 additions & 7 deletions app/views/controllers/contributors/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ add_tab_set(contributors_index_tabs)
<div class="list-group-item">

<%= :users_by_contribution_1.tp %>
<% SiteData::ALL_FIELDS.select { |f| SiteData::FIELD_WEIGHTS[f] > 0}.each do |field| %>
<% SiteData.fields_with_weight.keys.each do |field| %>
<div class="row">
<div class="col-xs-8 col-xs-push-1"><%= "user_stats_#{field}".to_sym.t %> </div>
<div class="col-xs-2"><%= SiteData::FIELD_WEIGHTS[field] %></div>
<div class="col-xs-2"><%= SiteData::ALL_FIELDS[field][:weight] %></div>
</div><!--.row-->
<% end %>
<p class="pt-3"><%= :users_by_contribution_2.t %></p>
<%
v1 = SiteData::FIELD_WEIGHTS[:images]
v2 = SiteData::FIELD_WEIGHTS[:name_description_editors]
v3 = SiteData::FIELD_WEIGHTS[:observations]
v4 = SiteData::FIELD_WEIGHTS[:namings]
v5 = SiteData::FIELD_WEIGHTS[:votes]
v1 = SiteData::ALL_FIELDS[:images][:weight]
v2 = SiteData::ALL_FIELDS[:name_description_editors][:weight]
v3 = SiteData::ALL_FIELDS[:observations][:weight]
v4 = SiteData::ALL_FIELDS[:namings][:weight]
v5 = SiteData::ALL_FIELDS[:votes][:weight]
%>
<div class="row">
<div class="col-xs-3 col-xs-push-1">&nbsp; &nbsp;3 * <%= v1 %></div>
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/names_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ def test_create_name_authored_group_unauthored_exists
assert_flash_success
assert_redirected_to(name_path(authored_name.id))
assert(Name.exists?(name.id))
assert_equal(old_contribution + SiteData::FIELD_WEIGHTS[:names],
assert_equal(old_contribution + SiteData::ALL_FIELDS[:names][:weight],
rolf.reload.contribution)
end

Expand Down
6 changes: 4 additions & 2 deletions test/controllers/observations/namings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ def test_update_observation_approved_new_name
assert_equal(new_name, nam.text_name)
assert_not_equal(old_name, nam.text_name)
assert_not(nam.name.deprecated)
assert_equal(old_contribution + (SiteData::FIELD_WEIGHTS[:names] * 2) + 2,
rolf.reload.contribution)
assert_equal(
old_contribution + (SiteData::ALL_FIELDS[:names][:weight] * 2) + 2,
rolf.reload.contribution
)
end

def test_update_observation_multiple_match
Expand Down
2 changes: 1 addition & 1 deletion test/models/localization_files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_description_source_translations
end

def test_site_data_translations
tags = SiteData::ALL_FIELDS.map do |field|
tags = SiteData::ALL_FIELDS.keys.map do |field|
[
:"user_stats_#{field}",
:"site_stats_#{field}"
Expand Down
4 changes: 2 additions & 2 deletions test/models/name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3259,10 +3259,10 @@ def test_merge_editors
names(:lichen).merge(old_name)

assert_equal(
old_contribution - SiteData::FIELD_WEIGHTS[:name_versions],
old_contribution - SiteData::ALL_FIELDS[:name_versions][:weight],
user.reload.contribution,
"Merging a Name edited by a user should reduce user's contribution " \
"by #{SiteData::FIELD_WEIGHTS[:name_versions]}"
"by #{SiteData::ALL_FIELDS[:name_versions][:weight]}"
)
end

Expand Down

0 comments on commit 5e23dd8

Please sign in to comment.