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

Store checked_by users for samples #6584

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
20 changes: 19 additions & 1 deletion app/commands/training_data/code_tags_sample/update_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@ class TrainingData::CodeTagsSample::UpdateTags
def call
sample.with_lock do
sample.lock_for_editing!(user)
sample.update!(tags: TrainingData::CodeTagsSample::NormalizeTags.(tags), status:)
sample.update!(
tags: TrainingData::CodeTagsSample::NormalizeTags.(tags),
status:,
community_checked_by:,
admin_checked_by:
)
sample.unlock!
end
end

private
def community_checked_by
return user if status == :community_checked

sample.community_checked_by
end

def admin_checked_by
return user if status == :admin_checked

sample.admin_checked_by
end
end
2 changes: 2 additions & 0 deletions app/models/training_data/code_tags_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class TrainingData::CodeTagsSample < ApplicationRecord
belongs_to :exercise, optional: true
belongs_to :solution, optional: true
belongs_to :locked_by, class_name: "User", optional: true
belongs_to :community_checked_by, class_name: "User", optional: true
belongs_to :admin_checked_by, class_name: "User", optional: true

enum dataset: { training: 0, validation: 1 }
enum status: { untagged: 0, machine_tagged: 1, human_tagged: 2, community_checked: 3, admin_checked: 4 }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddCommunityCheckedByToSamples < ActiveRecord::Migration[7.0]
def change
return if Rails.env.production?

add_reference :training_data_code_tags_samples, :community_checked_by, null: true, foreign_key: { to_table: :users }, index: { name: "index_code_tags_samples_on_community_tagged_by_id" }, if_not_exists: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddAdminCheckedByToSamples < ActiveRecord::Migration[7.0]
def change
return if Rails.env.production?

add_reference :training_data_code_tags_samples, :admin_checked_by, null: true, foreign_key: { to_table: :users }, index: { name: "index_code_tags_samples_on_admin_tagged_by_id" }, if_not_exists: true
end
end
18 changes: 16 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is auto-generated from the current state of the database. Instead
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
Expand All @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_11_24_100011) do
ActiveRecord::Schema[7.0].define(version: 2023_12_01_115917) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down Expand Up @@ -817,6 +817,14 @@
t.index ["user_id"], name: "index_scratchpad_pages_on_user_id"
end

create_table "site_tags", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "tag", null: false
t.string "description", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["tag"], name: "index_site_tags_on_tag", unique: true
end

ErikSchierboom marked this conversation as resolved.
Show resolved Hide resolved
create_table "site_updates", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "type", null: false
t.string "uniqueness_key", null: false
Expand Down Expand Up @@ -1206,6 +1214,10 @@
t.datetime "locked_until"
t.bigint "locked_by_id"
t.text "llm_tags"
t.bigint "community_checked_by_id"
t.bigint "admin_checked_by_id"
t.index ["admin_checked_by_id"], name: "index_code_tags_samples_on_admin_tagged_by_id"
t.index ["community_checked_by_id"], name: "index_code_tags_samples_on_community_tagged_by_id"
t.index ["exercise_id"], name: "index_training_data_code_tags_samples_on_exercise_id"
t.index ["solution_id"], name: "index_training_data_code_tags_samples_on_solution_id"
t.index ["track_id"], name: "index_training_data_code_tags_samples_on_track_id"
Expand Down Expand Up @@ -1684,6 +1696,8 @@
add_foreign_key "track_concept_contributorships", "track_concepts"
add_foreign_key "track_concept_contributorships", "users"
add_foreign_key "track_concepts", "tracks"
add_foreign_key "training_data_code_tags_samples", "users", column: "admin_checked_by_id"
add_foreign_key "training_data_code_tags_samples", "users", column: "community_checked_by_id"
add_foreign_key "user_acquired_badges", "badges"
add_foreign_key "user_acquired_badges", "users"
add_foreign_key "user_activities", "exercises"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,41 @@ class TrainingData::CodeTagsSample::UpdateTagsTest < ActiveSupport::TestCase
refute_nil sample.locked_until
assert_equal lock_user, sample.locked_by
end

%i[machine_tagged human_tagged].each do |status|
test "sets community_checked_by to user when current status is #{status}" do
user = create :user
tags = ['construct:if']
sample = create(:training_data_code_tags_sample, status:, locked_by: nil, locked_until: nil)

TrainingData::CodeTagsSample::UpdateTags.(sample, tags, :community_checked, user)

assert_equal user, sample.community_checked_by
assert_nil sample.admin_checked_by
end
end

test "sets admin_checked_by to user when current status is community_checked" do
user = create :user
community_checked_by_user = create :user
tags = ['construct:if']
sample = create(:training_data_code_tags_sample, status: :community_checked, community_checked_by: community_checked_by_user,
locked_by: nil, locked_until: nil)

TrainingData::CodeTagsSample::UpdateTags.(sample, tags, :admin_checked, user)

assert_equal user, sample.admin_checked_by
end

test "does not change community_checked_by user when setting admin_checked_by user" do
user = create :user
community_checked_by_user = create :user
tags = ['construct:if']
sample = create(:training_data_code_tags_sample, status: :community_checked, community_checked_by: community_checked_by_user,
locked_by: nil, locked_until: nil)

TrainingData::CodeTagsSample::UpdateTags.(sample, tags, :admin_checked, user)

assert_equal community_checked_by_user, sample.community_checked_by
end
end