From 5e3f6af734717ed1ee5177a674fa7108c91454e8 Mon Sep 17 00:00:00 2001 From: ddecollo Date: Fri, 15 Dec 2023 11:22:16 -0500 Subject: [PATCH 1/2] Convert variable type for "hours" to decimal type --- app/importers/com_data/com_effort_populate_db.rb | 2 +- ...231214203515_change_hours_data_type_in_com_efforts.rb | 9 +++++++++ db/schema.rb | 2 +- spec/importers/com_data/com_effort_populate_db_spec.rb | 4 ++-- spec/importers/com_data/com_effort_xml_builder_spec.rb | 8 ++++---- .../ai_integration/com_effort_integration_spec.rb | 4 ++-- spec/models/com_effort_spec.rb | 2 +- 7 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20231214203515_change_hours_data_type_in_com_efforts.rb diff --git a/app/importers/com_data/com_effort_populate_db.rb b/app/importers/com_data/com_effort_populate_db.rb index 703d50f..3171b99 100644 --- a/app/importers/com_data/com_effort_populate_db.rb +++ b/app/importers/com_data/com_effort_populate_db.rb @@ -24,7 +24,7 @@ def populate faculty:) com_effort.hours ||= 0 - com_effort.hours += row['UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_'].to_f + com_effort.hours += row['UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_'].to_d com_effort.save! rescue ActiveRecord::RecordNotUnique diff --git a/db/migrate/20231214203515_change_hours_data_type_in_com_efforts.rb b/db/migrate/20231214203515_change_hours_data_type_in_com_efforts.rb new file mode 100644 index 0000000..d2f644c --- /dev/null +++ b/db/migrate/20231214203515_change_hours_data_type_in_com_efforts.rb @@ -0,0 +1,9 @@ +class ChangeHoursDataTypeInComEfforts < ActiveRecord::Migration[7.0] + def up + change_column :com_efforts, :hours, :decimal, precision: 10, scale: 2 + end + + def down + change_column :com_efforts, :hours, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index beaac06..691acc4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -28,7 +28,7 @@ t.string "event_type" t.string "faculty_name" t.string "event" - t.integer "hours" + t.decimal "hours", precision: 10, scale: 2 t.bigint "faculty_id" t.string "event_date" t.index ["com_id", "course", "event", "event_date"], name: "index_com_efforts_on_com_id_and_course_and_event_and_event_date", unique: true, length: { course: 50, event: 50 } diff --git a/spec/importers/com_data/com_effort_populate_db_spec.rb b/spec/importers/com_data/com_effort_populate_db_spec.rb index d9a61c1..e6e9380 100644 --- a/spec/importers/com_data/com_effort_populate_db_spec.rb +++ b/spec/importers/com_data/com_effort_populate_db_spec.rb @@ -9,7 +9,7 @@ arr_of_hashes = [] keys = headers data_arr << ['lskywalker', 'Skywalker Luke', 'the Force', '1976-1977', 'Lecture', - 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '5/25/77 10:00', 2] + 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '5/25/77 10:00', 2.5] data_arr << ['lskywalker', 'Skywalker Luke', 'the Force', '1976-1977', 'Lecture', 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '5/25/77 1:00', 4] data_arr << ['hgranger', 'Granger Hermione', 'Potions', '1997-1998', 'Sm Grp Facilitation', @@ -52,7 +52,7 @@ expect(ComEffort.find_by(com_id: 'hgranger').hours).to eq(8) expect(ComEffort.find_by(com_id: 'hgranger').event_type).to eq('Sm Grp Facilitation') expect(ComEffort.find_by(com_id: 'hgranger').event).to eq('FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid') - expect(ComEffort.find_by(com_id: 'lskywalker').hours).to eq(6) + expect(ComEffort.find_by(com_id: 'lskywalker').hours).to eq(6.5) expect(ComEffort.find_by(com_id: 'lskywalker').event_type).to eq('Lecture') expect(ComEffort.find_by(com_id: 'lskywalker').faculty).to eq(faculty2) end diff --git a/spec/importers/com_data/com_effort_xml_builder_spec.rb b/spec/importers/com_data/com_effort_xml_builder_spec.rb index fa704c6..a31ed1f 100644 --- a/spec/importers/com_data/com_effort_xml_builder_spec.rb +++ b/spec/importers/com_data/com_effort_xml_builder_spec.rb @@ -9,7 +9,7 @@ 'EVENT_TYPE' => 'Lecture', 'EVENT' => 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', 'EVENT_DATE' => '5/25/77', - 'UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_' => 2 }, + 'UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_' => 2.5 }, { 'FACULTY_USERNAME' => 'hgranger', 'FACULTY_NAME' => 'Granger Hermione', 'COURSE' => 'Potions', @@ -17,7 +17,7 @@ 'EVENT_TYPE' => 'Sm Grp Facilitation', 'EVENT' => 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', 'EVENT_DATE' => '6/26/97', - 'UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_' => 7 }, + 'UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_' => 7.25 }, { 'FACULTY_USERNAME' => 'notCOM', 'FACULTY_NAME' => 'Not MD', 'COURSE' => 'test', @@ -61,7 +61,7 @@ May 25 1977 - 2 + 2.5 @@ -73,7 +73,7 @@ June 26 1997 - 7 + 7.25 diff --git a/spec/integration/ai_integration/com_effort_integration_spec.rb b/spec/integration/ai_integration/com_effort_integration_spec.rb index 753fc81..bdb671d 100644 --- a/spec/integration/ai_integration/com_effort_integration_spec.rb +++ b/spec/integration/ai_integration/com_effort_integration_spec.rb @@ -79,14 +79,14 @@ def effort_body "FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid\n " + "Sm Grp Facilitation\n " + "June\n 26\n " + - "1997\n 7\n " + + "1997\n 7.0\n " + "\n \n \n \n " + "1976-1977\n " + "the Force\n " + "FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid\n " + "Lecture\n May\n " + "25\n 1977\n " + - "2\n \n \n\n" + "2.0\n \n \n\n" end def error_message diff --git a/spec/models/com_effort_spec.rb b/spec/models/com_effort_spec.rb index 42ff9d3..6095ff4 100644 --- a/spec/models/com_effort_spec.rb +++ b/spec/models/com_effort_spec.rb @@ -10,7 +10,7 @@ it { is_expected.to have_db_column(:faculty_name).of_type(:string) } it { is_expected.to have_db_column(:event).of_type(:string) } it { is_expected.to have_db_column(:event).of_type(:string) } - it { is_expected.to have_db_column(:hours).of_type(:integer) } + it { is_expected.to have_db_column(:hours).of_type(:decimal) } it { is_expected.to have_db_index(%i[com_id course event event_date]).unique(true) } it { is_expected.to have_db_index([:faculty_id]) } From 1f714c56e5333f4c6212be254ab9564941ef21fb Mon Sep 17 00:00:00 2001 From: ddecollo Date: Fri, 15 Dec 2023 13:41:52 -0500 Subject: [PATCH 2/2] event_date years are input as 4 digits not 2 --- app/importers/com_data/com_effort_xml_builder.rb | 2 +- spec/fixtures/ume_faculty_effort.csv | 4 ++-- .../com_data/com_effort_populate_db_spec.rb | 8 ++++---- .../com_data/com_effort_xml_builder_spec.rb | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/importers/com_data/com_effort_xml_builder.rb b/app/importers/com_data/com_effort_xml_builder.rb index 499e02f..4cbd9ad 100644 --- a/app/importers/com_data/com_effort_xml_builder.rb +++ b/app/importers/com_data/com_effort_xml_builder.rb @@ -18,7 +18,7 @@ def build_xml_effort(batch) batch.each do |faculty| xml.Record('PennStateHealthUsername' => faculty.com_id) do faculty.com_efforts.each do |com_effort| - event_date = Date.strptime(com_effort.event_date, '%m/%d/%y') + event_date = Date.strptime(com_effort.event_date, '%m/%d/%Y') xml.INSTRUCT_TAUGHT do xml.COURSE_YEAR_ com_effort.course_year, access: 'READ_ONLY' xml.COURSE_TITLE_ com_effort.course, access: 'READ_ONLY' diff --git a/spec/fixtures/ume_faculty_effort.csv b/spec/fixtures/ume_faculty_effort.csv index 1532f70..1403ae6 100644 --- a/spec/fixtures/ume_faculty_effort.csv +++ b/spec/fixtures/ume_faculty_effort.csv @@ -1,3 +1,3 @@ FACULTY_USERNAME,FACULTY_NAME,COURSE,COURSE_YEAR,EVENT_TYPE,EVENT,EVENT_DATE,UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_ -lskywalker,Skywalker Luke,the Force,1976-1977,Lecture,FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid,5/25/77 10:00,2 -hgranger,Granger Hermione,Potions,1997-1998,Sm Grp Facilitation,FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid,6/26/97 9:45,7 +lskywalker,Skywalker Luke,the Force,1976-1977,Lecture,FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid,5/25/1977 10:00,2 +hgranger,Granger Hermione,Potions,1997-1998,Sm Grp Facilitation,FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid,6/26/1997 9:45,7 diff --git a/spec/importers/com_data/com_effort_populate_db_spec.rb b/spec/importers/com_data/com_effort_populate_db_spec.rb index e6e9380..ccaacb5 100644 --- a/spec/importers/com_data/com_effort_populate_db_spec.rb +++ b/spec/importers/com_data/com_effort_populate_db_spec.rb @@ -9,13 +9,13 @@ arr_of_hashes = [] keys = headers data_arr << ['lskywalker', 'Skywalker Luke', 'the Force', '1976-1977', 'Lecture', - 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '5/25/77 10:00', 2.5] + 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '5/25/1977 10:00', 2.5] data_arr << ['lskywalker', 'Skywalker Luke', 'the Force', '1976-1977', 'Lecture', - 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '5/25/77 1:00', 4] + 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '5/25/1977 1:00', 4] data_arr << ['hgranger', 'Granger Hermione', 'Potions', '1997-1998', 'Sm Grp Facilitation', - 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '6/26/97 9:45', 7] + 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '6/26/1997 9:45', 7] data_arr << ['hgranger', 'Granger Hermione', 'Dark Arts', '2001-2002', 'Sm Grp Facilitation', - 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '11/1/01 12:00', 8] + 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', '11/1/2001 12:00', 8] data_arr.each { |a| arr_of_hashes << keys.zip(a).to_h } arr_of_hashes end diff --git a/spec/importers/com_data/com_effort_xml_builder_spec.rb b/spec/importers/com_data/com_effort_xml_builder_spec.rb index a31ed1f..afdff09 100644 --- a/spec/importers/com_data/com_effort_xml_builder_spec.rb +++ b/spec/importers/com_data/com_effort_xml_builder_spec.rb @@ -8,15 +8,15 @@ 'COURSE_YEAR' => '1976-1977', 'EVENT_TYPE' => 'Lecture', 'EVENT' => 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', - 'EVENT_DATE' => '5/25/77', + 'EVENT_DATE' => '5/25/1977', 'UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_' => 2.5 }, { 'FACULTY_USERNAME' => 'hgranger', 'FACULTY_NAME' => 'Granger Hermione', 'COURSE' => 'Potions', - 'COURSE_YEAR' => '1997-1998', + 'COURSE_YEAR' => '2022-2023', 'EVENT_TYPE' => 'Sm Grp Facilitation', 'EVENT' => 'FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid', - 'EVENT_DATE' => '6/26/97', + 'EVENT_DATE' => '6/26/2023', 'UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_' => 7.25 }, { 'FACULTY_USERNAME' => 'notCOM', 'FACULTY_NAME' => 'Not MD', @@ -24,7 +24,7 @@ 'COURSE_YEAR' => '2022-2023', 'EVENT_TYPE' => 'Lacture', 'EVENT' => 'Test Event for employee not in College of Medicine', - 'EVENT_DATE' => '1/1/23', + 'EVENT_DATE' => '1/1/2023', 'UME_CALCULATED_TEACHING_WHILE_NON_BILLING_EFFORT__HRS_' => 1 }] end @@ -66,13 +66,13 @@ - 1997-1998 + 2022-2023 Potions FTF REQ Various Rooms 10-12 PBL - EndoRepro PBL 1402 - Thyroid Sm Grp Facilitation June 26 - 1997 + 2023 7.25