CSC/ECE 517 Spring 2017/oss E1729: Difference between revisions
Line 91: | Line 91: | ||
end | end | ||
end | end | ||
@uniq_rounds.each do |round_num| | @uniq_rounds.each do |round_num| | ||
@uniq_response_type.each do |res_type| | @uniq_response_type.each do |res_type| | ||
Line 105: | Line 104: | ||
row = [] | row = [] | ||
tcsv = [] | tcsv = [] | ||
@response = Response.find_by_id(answer.response_id) | @response = Response.find_by_id(answer.response_id) | ||
ans = ResponseMap.find_by_id(@response.map_id) | ans = ResponseMap.find_by_id(@response.map_id) | ||
@reviewee = Team.find_by_id(ans.reviewee_id) | @reviewee = Team.find_by_id(ans.reviewee_id) | ||
if @reviewee.nil? | if @reviewee.nil? | ||
@reviewee = Participant.find_by_id(ans.reviewee_id).user | @reviewee = Participant.find_by_id(ans.reviewee_id).user | ||
end | end | ||
reviewer = Participant.find_by_id(ans.reviewer_id).user | reviewer = Participant.find_by_id(ans.reviewer_id).user | ||
if @reviewee.nil? | if @reviewee.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 123: | Line 118: | ||
end | end | ||
end | end | ||
if @reviewee.nil? | if @reviewee.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 131: | Line 125: | ||
end | end | ||
end | end | ||
if reviewer.nil? | if reviewer.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 139: | Line 132: | ||
end | end | ||
end | end | ||
if answer.question.txt.nil? | if answer.question.txt.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 147: | Line 139: | ||
end | end | ||
end | end | ||
if answer.question.id.nil? | if answer.question.id.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 155: | Line 146: | ||
end | end | ||
end | end | ||
if answer.id.nil? | if answer.id.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 163: | Line 153: | ||
end | end | ||
end | end | ||
if answer.comments.nil? | if answer.comments.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 171: | Line 160: | ||
end | end | ||
end | end | ||
if answer.answer.nil? | if answer.answer.nil? | ||
tcsv << ' ' | tcsv << ' ' | ||
Line 179: | Line 167: | ||
end | end | ||
end | end | ||
csv << tcsv | csv << tcsv | ||
end | end | ||
Line 185: | Line 172: | ||
end | end | ||
end | end | ||
# This method is used for export detailed contents. - Akshit, Kushagra, Vaibhav | # This method is used for export detailed contents. - Akshit, Kushagra, Vaibhav |
Revision as of 22:46, 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.
Part of the implementation includes 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
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
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 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 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