CSC/ECE 517 Spring 2017/oss E1729: Difference between revisions
Line 246: | Line 246: | ||
expect(generated_csv).to eq(expected_csv) | expect(generated_csv).to eq(expected_csv) | ||
end | end | ||
'''The expected CSV file is read in as a text file to simplify string comparison with generated CSV string.''' | |||
The assignment details and all field headers should be displayed with one answer. | The assignment details and all field headers should be displayed with one answer. |
Revision as of 18:39, 23 March 2017
Introduction
This project was an addendum to the bigger Expertiza project. The Expertiza project is software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages.
The requirement for this OSS project was to 'Export Scores In Detail'
Deployment Link
Branch on Git
The branch on which we developed this project on is called 'exportdetail'
Problem Statement
Expertiza provides a the ability for an instructor to export scores for an assignment. Whenever a user fill out teammate reviews, peer reviews, feedback reviews, and etc. the scores for each question on those reviews is stored in the database. Currently however Expertiza only exports a csv with aggregated scores which are computed as weighted averages of the scores given in reviews. This is not the most helpful for visualizing the score data by question, individual team/user, reviewer. So it was our assignment to implement the ability to export a more detailed csv that contained all the scores for each question for each review and review type within a specific assignment.
After talking with our project contact, Ferry, it was decided that the csv would be organized by round and within each round by response type. Part of the implementation was to also include the ability to choose the delimiter for the csv and specify which columns they wanted to include.
Design
Implementation
Files Updated
- app/controllers/export_file_controller.rb
- app/models/assignment.rb
- app/views/export_file/start.html.erb
Files Added
- app/views/export_file/_export_details.html.erb
- spec/controllers/export_file_controller_spec.rb
- spec/features/assignment_export_details/expected_details_csv.txt
Code Snippets
- export_file_controller_spec.rb
This method is called when the 'Export Details' button is clicked and selects the delimiter and generates the csv with selected columns. It then passes the CSV into the assignment models method to populate it.
def exportdetails @delim_type = params[:delim_type2] if @delim_type == "comma" filename = params[:model] + params[:id] + "_Details.csv" delimiter = "," elsif @delim_type == "space" filename = params[:model] + params[:id] + "_Details.csv" delimiter = " " elsif @delim_type == "tab" filename = params[:model] + params[:id] + "_Details.csv" delimiter = "\t" elsif @delim_type == "other" filename = params[:model] + params[:id] + "_Details.csv" delimiter = other_char2 end allowed_models = ['Assignment'] csv_data = CSV.generate(col_sep: delimiter) do |csv| if allowed_models.include? params[:model] csv << Object.const_get(params[:model]).export_Headers(params[:id]) csv << Object.const_get(params[:model]).export_details_fields(params[:details]) Object.const_get(params[:model]).export_details(csv, params[:id], params[:details]) end end send_data csv_data, type: 'text/csv; charset=iso-8859-1; header=present', disposition: "attachment; filename=#{filename}" end
- app/models/assignment.rb
This method is called to populate it the csv and is where the majority of our implementation lies. It finds all the ResponseMaps associated with this assignment, then finds all the Responses associated with that each ResponseMap. Then for each response it saves the Answer objects associated with it into an array that is stored in a hash that is indexed by round and response type (teammate review/feedback review/etc).
def self.export_details(csv, parent_id, detail_options) @assignment = Assignment.find(parent_id) @answers = {} # Contails all answer objects for this assignment #Find all unique response types @uniq_response_type = ResponseMap.uniq.pluck(:type) #Find all unique round numbers @uniq_rounds = Response.uniq.pluck(:round) #create the nested hash that holds all the answers organized by round # and response type @uniq_rounds.each do |round_num| @answers[round_num] = {} @uniq_response_type.each do |res_type| @answers[round_num][res_type] = [] end end #get all response maps for this assignment @responseMapsForAssignment = ResponseMap.find_by_sql(["SELECT * FROM response_maps WHERE reviewed_object_id = #{@assignment.id}"]) #for each map, get the response & answer associated with it @responseMapsForAssignment.each do |map| @responseForThisMap = Response.find_by_sql(["SELECT * FROM responses WHERE map_id = #{map.id}"]) #for this response, get the answer associated with it @responseForThisMap.each do |res_map| @answer = Answer.find_by_sql(["SELECT * FROM answers WHERE response_id = #{res_map.id}"]) @answer.each do |ans| @answers[res_map.round][map.type].push(ans) end end end @uniq_rounds.each do |round_num| @uniq_response_type.each do |res_type| if @answers[round_num][res_type].size > 0 if round_num.nil? round_type = "Round Nill - " + res_type else round_type = "Round " + round_num.to_s + " - " + res_type.to_s end csv << [round_type, '---', '---', '---', '---', '---', '---'] end @answers[round_num][res_type].each do |answer| row = [] tcsv = [] @response = Response.find_by_id(answer.response_id) ans = ResponseMap.find_by_id(@response.map_id) @reviewee = Team.find_by_id(ans.reviewee_id) if @reviewee.nil? @reviewee = Participant.find_by_id(ans.reviewee_id).user end reviewer = Participant.find_by_id(ans.reviewer_id).user if @reviewee.nil? tcsv << ' ' else if detail_options['team_id'] == 'true' tcsv << @reviewee.id end end if @reviewee.nil? tcsv << ' ' else if detail_options['team_name'] == 'true' tcsv << @reviewee.name end end if reviewer.nil? tcsv << ' ' else if detail_options['reviewer'] == 'true' tcsv << reviewer.name end end if answer.question.txt.nil? tcsv << ' ' else if detail_options['question'] == 'true' tcsv << answer.question.txt end end if answer.question.id.nil? tcsv << ' ' else if detail_options['question_id'] == 'true' tcsv << answer.question.id end end if answer.id.nil? tcsv << ' ' else if detail_options['comment_id'] == 'true' tcsv << answer.id end end if answer.comments.nil? tcsv << ' ' else if detail_options['comments'] == 'true' tcsv << answer.comments end end if answer.answer.nil? tcsv << ' ' else if detail_options['score'] == 'true' tcsv << answer.answer end end csv << tcsv end end end end
This method is called by the controller to set the columns in the csv.
# This method is used for export detailed contents. - Akshit, Kushagra, Vaibhav def self.export_details_fields(detail_options) fields = [] fields << 'Team ID / Author ID' if detail_options['team_id'] == 'true' fields << 'Team Name / Author Name' if detail_options['team_name'] == 'true' fields << 'Reviewer' if detail_options['reviewer'] == 'true' fields << 'Question / Dimension Name' if detail_options['question'] == 'true' fields << 'Question ID / Dimension' if detail_options['question_id'] == 'true' fields << 'Comment ID' if detail_options['comment_id'] == 'true' fields << 'Comments' if detail_options['comments'] == 'true' fields << 'Score' if detail_options['score'] == 'true' fields end
This method is called by the controller to set the headers in the csv (including Assignment Name and Instructor)
# This method is used to set the headers for the csv like Assignment Name and Assignment Instructor def self.export_Headers(parent_id) @assignment = Assignment.find(parent_id) fields = [] fields << "Assignment Name: " + @assignment.name.to_s fields << "Assignment Instructor: " + User.find(@assignment.instructor_id).name.to_s fields end
Test Plan
Test Type | Feature/Integration Test |
Testing Tool | Rspec |
Scenario 1 |
Export to CSV with all field options enabled and data contains an answer |
Test Process Description |
Before each test case is run, the following factories are created: before(:each) do @assignment = create(:assignment) create(:assignment_team, name: "team1") @student = create(:student, name: "student1") create(:participant, user: @student) create(:questionnaire) create(:question) create(:review_response_map) create(:response) end The following test case is run to check this scenario: it "checks_if_csv has the correct data" do create(:answer, comments: "Test comment") options = {"team_id" => "true", "team_name" => "true", "reviewer" => "true", "question" => "true", "question_id" => "true", "comment_id" => "true", "comments" => "true", "score" => "true"} expected_csv = File.read('spec/features/assignment_export_details/expected_details_csv.txt') generated_csv = CSV.generate(col_sep: delimiter) do |csv| csv << Assignment.export_headers(@assignment.id) csv << Assignment.export_details_fields(options) Assignment.export_details(csv, @assignment.id, options) end expect(generated_csv).to eq(expected_csv) end The expected CSV file is read in as a text file to simplify string comparison with generated CSV string. The assignment details and all field headers should be displayed with one answer. A CSV file with the following content is to be expected: Assignment Name: final2,Assignment Instructor: instructor6 Team ID / Author ID,Team Name / Author Name,Reviewer,Question / Dimension Name,Question ID / Dimension,Comment ID,Comments,Score Round 1 - ReviewResponseMap,---,---,---,---,---,--- 1,team1,student1,Test question:,1,1,Test comment,1 |
Scenario 2 |
Export to CSV with some field options enabled and data contains an answer |
Test Process Description |
The following test case is run to check this scenario: it "checks csv with some options" do create(:answer, comments: "Test comment") options = {"team_id" => "false", "team_name" => "true", "reviewer" => "true", "question" => "true", "question_id" => "false", "comment_id" => "false", "comments" => "true", "score" => "true"} expected_csv = File.read('spec/features/assignment_export_details/expected_details_some_options_csv.txt') generated_csv = CSV.generate(col_sep: delimiter) do |csv| csv << Assignment.export_headers(@assignment.id) csv << Assignment.export_details_fields(options) Assignment.export_details(csv, @assignment.id, options) end expect(generated_csv).to eq(expected_csv) end The assignment details and all non-ID field headers should be displayed with one answer. A CSV file with the following content is to be expected: Assignment Name: final2,Assignment Instructor: instructor6 Team Name / Author Name,Reviewer,Question / Dimension Name,Comments,Score Round 1 - ReviewResponseMap,---,---,---,---,---,--- team1,student1,Test question:,Test comment,1 |
Scenario 3 |
Export to CSV with all field options enabled and data contains no answer |
Test Process Description |
The following test case is run to check this scenario: it "checks csv with no data" do options = {"team_id" => "true", "team_name" => "true", "reviewer" => "true", "question" => "true", "question_id" => "true", "comment_id" => "true", "comments" => "true", "score" => "true"} expected_csv = File.read('spec/features/assignment_export_details/expected_details_no_data_csv.txt') generated_csv = CSV.generate(col_sep: delimiter) do |csv| csv << Assignment.export_headers(@assignment.id) csv << Assignment.export_details_fields(options) Assignment.export_details(csv, @assignment.id, options) end expect(generated_csv).to eq(expected_csv) end Only the assignment details and all field headers should be displayed. A CSV file with the following content is to be expected: Assignment Name: final2,Assignment Instructor: instructor6 Team ID / Author ID,Team Name / Author Name,Reviewer,Question / Dimension Name,Question ID / Dimension,Comment ID,Comments,Score |
Scenario 4 |
Export to CSV with no field options enabled and data contains an answer |
Test Process Description |
The following test case is run to check this scenario: it "checks csv with data and no options" do create(:answer, comments: "Test comment") options = {"team_id" => "false", "team_name" => "false", "reviewer" => "false", "question" => "false", "question_id" => "false", "comment_id" => "false", "comments" => "false", "score" => "false"} expected_csv = File.read('spec/features/assignment_export_details/expected_details_no_options_csv.txt') generated_csv = CSV.generate(col_sep: delimiter) do |csv| csv << Assignment.export_headers(@assignment.id) csv << Assignment.export_details_fields(options) Assignment.export_details(csv, @assignment.id, options) end expect(generated_csv).to eq(expected_csv) end Only the assignment details should be displayed along with no headers and no answer. A CSV file with the following content is to be expected: Assignment Name: final2,Assignment Instructor: instructor6 |
Test Type | Functional Testing |
Testing Tool | Manual Testing |
Scenario 5 |
HINT WHEN TESTING: When you click the 'View Score' icon for an assignment, http://152.46.16.143:3000/export_file/start?id=754&model=Assignment |