Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-5558: Downgrade based on last_seen, not created_at; add better logging #2110

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions app/models/bot/alegre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,17 @@ def self.set_relationship_type(pm, pm_id_scores, parent)
settings = tbi.nil? ? {} : tbi.alegre_settings
date_threshold = Time.now - settings['similarity_date_threshold'].to_i.months unless settings['similarity_date_threshold'].blank?
relationship_type = pm_id_scores[parent.id][:relationship_type]
if settings['date_similarity_threshold_enabled'] && !date_threshold.blank? && parent.created_at.to_i < date_threshold.to_i
relationship_type = Relationship.suggested_type
else
length_threshold = settings.blank? ? CheckConfig.get('text_length_matching_threshold').to_f : settings['text_length_matching_threshold'].to_f
relationship_type = Relationship.suggested_type if self.is_text_too_short?(pm, length_threshold)
if relationship_type != Relationship.suggested_type
if settings['date_similarity_threshold_enabled'] && !date_threshold.blank? && parent.last_seen.to_i < date_threshold.to_i
Rails.logger.info("[Alegre Bot] [ProjectMedia ##{pm.id}] [Relationships 6/6] Downgrading to suggestion due to parent age")
relationship_type = Relationship.suggested_type
else
length_threshold = settings.blank? ? CheckConfig.get('text_length_matching_threshold').to_f : settings['text_length_matching_threshold'].to_f
if self.is_text_too_short?(pm, length_threshold)
Rails.logger.info("[Alegre Bot] [ProjectMedia ##{pm.id}] [Relationships 6/6] Downgrading to suggestion due short text")
relationship_type = Relationship.suggested_type
end
end
end
relationship_type
end
Expand Down
22 changes: 15 additions & 7 deletions test/models/bot/alegre_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,32 @@ def teardown
}
]
})
# Set the TeamBotInstallation (tbi) for Alegre so that a query
# matched to an item seen more than 1 month ago is downgraded to suggestion
tbi = Bot::Alegre.get_alegre_tbi(@team.id)
tbi.set_date_similarity_threshold_enabled = true
tbi.set_similarity_date_threshold("1")
tbi.save!

# First verify a confirmed_type relationship is not downgraded.
# because last_seen will be now and not more than one month ago.
assert_difference 'Relationship.count' do
result = Bot::Alegre.relate_project_media_to_similar_items(pm2)
end
r = Relationship.last
assert_equal Relationship.confirmed_type, r.relationship_type
pm1.created_at = Time.now - 2.months
pm1.save!
tbi = Bot::Alegre.get_alegre_tbi(@team.id)
tbi.set_date_similarity_threshold_enabled = true
tbi.set_similarity_date_threshold("1")
tbi.save!
r.destroy
r.destroy!

# Now stub last_seen so that confirmed_type is downgraded to suggest_type
# because it is more than tbi.similarity_date_threshold months old
ProjectMedia.any_instance.stubs(:last_seen).returns(Time.now - 2.months)
assert_difference 'Relationship.count' do
result = Bot::Alegre.relate_project_media_to_similar_items(pm2)
end
r = Relationship.last
assert_equal Relationship.suggested_type, r.relationship_type
Bot::Alegre.unstub(:request)
ProjectMedia.any_instance.unstub(:last_seen)
end

test "should index report data" do
Expand Down
Loading