CSC/ECE 517 Spring 2017/oss E1729: Difference between revisions
No edit summary |
|||
Line 206: | Line 206: | ||
==Test Plan== | ==Test Plan== | ||
EDGE CASES: The only edge case I think of is the one where an assignment has no reviews, therefore we simply print out an empty csv. Akshit test for this!!!!!! |
Revision as of 23:09, 22 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
EDGE CASES: The only edge case I think of is the one where an assignment has no reviews, therefore we simply print out an empty csv. Akshit test for this!!!!!!