@@ -141,9 +141,9 @@ def create
141141 end
142142 end
143143
144- # -------------------------------------------------------------
145- # POST /odsa_exercise_attempts/pe
146- def create_pe
144+ # POST /odsa_exercise_attempts/new
145+ def create_attempt
146+
147147 unless user_logged_in?
148148 return
149149 end
@@ -162,151 +162,14 @@ def create_pe
162162 "inst_book_id=? and inst_section_id=? and inst_exercise_id=?" ,
163163 params [ :inst_book_id ] , params [ :inst_section_id ] , inst_exercise . id
164164 ) . first
165- if inst_book_section_exercise . blank?
166- respond_to do |format |
167- msg = { :status => "fail" , :message => "Fail!" }
168- format . json { render :json => msg }
169- end
170- return
171- end
172- threshold = inst_book_section_exercise . threshold
173- elsif is_standalone_module
174- inst_exercise = InstExercise . find_by ( short_name : params [ :exercise ] )
175- inst_module_section_exercise = InstModuleSectionExercise . find_by (
176- inst_exercise_id : inst_exercise . id ,
177- inst_module_version_id : params [ :inst_module_version_id ] )
178- threshold = inst_module_section_exercise . threshold
179- else
180- inst_course_offering_exercise = InstCourseOfferingExercise . find_by (
181- id : params [ :inst_course_offering_exercise_id ] ,
182- )
183- threshold = inst_course_offering_exercise . threshold
184- end
185-
186- if inst_book_section_exercise != nil or inst_course_offering_exercise != nil or inst_module_section_exercise != nil
187- if hasBook
188- unless exercise_progress = OdsaExerciseProgress . where ( "user_id=? and
189- inst_book_section_exercise_id=?" ,
190- current_user . id ,
191- inst_book_section_exercise . id ) . first
192- exercise_progress = OdsaExerciseProgress . new ( user : current_user ,
193- inst_book_section_exercise : inst_book_section_exercise )
194- exercise_progress . save
195- end
196- elsif is_standalone_module
197- unless exercise_progress = OdsaExerciseProgress . where ( "user_id=? and
198- inst_module_section_exercise_id=?" ,
199- current_user . id ,
200- inst_module_section_exercise . id ) . first
201- exercise_progress = OdsaExerciseProgress . new ( user : current_user ,
202- inst_module_section_exercise : inst_module_section_exercise )
203- exercise_progress . save
204- end
205- else
206- unless exercise_progress = OdsaExerciseProgress . where ( "user_id=? and
207- inst_course_offering_exercise_id=?" ,
208- current_user . id ,
209- inst_course_offering_exercise . id ) . first
210- exercise_progress = OdsaExerciseProgress . new ( user : current_user ,
211- inst_course_offering_exercise : inst_course_offering_exercise )
212- exercise_progress . save
213- end
214- end
215-
216- already_proficient = exercise_progress . proficient?
217- correct = params [ :score ] . to_f >= params [ :threshold ] . to_f
218-
219- exercise_attempt = OdsaExerciseAttempt . new (
220- inst_book_id : params [ :inst_book_id ] ,
221- user : current_user ,
222- inst_section : inst_section ,
223- inst_book_section_exercise : inst_book_section_exercise ,
224- inst_course_offering_exercise : inst_course_offering_exercise ,
225- inst_module_section_exercise : inst_module_section_exercise ,
226- worth_credit : correct ,
227- correct : correct ,
228- time_done : Time . now ,
229- time_taken : ( params [ :total_time ] . to_f / 1000 ) . round ,
230- count_hints : 0 ,
231- count_attempts : params [ :uiid ] ,
232- hint_used : 0 ,
233- question_name : params [ :exercise ] ,
234- request_type : "PE" ,
235- ip_address : request . ip ,
236- pe_score : params [ :score ] ,
237- pe_steps_fixed : params [ :steps_fixed ] ,
238- )
239-
165+ if inst_book_section_exercise . blank?
240166 respond_to do |format |
241- if exercise_attempt . save
242- if hasBook
243- exercise_progress = OdsaExerciseProgress . where (
244- "user_id=? and inst_book_section_exercise_id=?" ,
245- current_user . id ,
246- inst_book_section_exercise . id
247- ) . first
248- elsif is_standalone_module
249- exercise_progress = OdsaExerciseProgress . find_by ( user_id : current_user . id ,
250- inst_module_section_exercise_id : inst_module_section_exercise . id )
251- else
252- exercise_progress = OdsaExerciseProgress . find_by ( user_id : current_user . id ,
253- inst_course_offering_exercise_id : inst_course_offering_exercise . id )
254- end
255- if !already_proficient and exercise_progress . proficient? and
256- exercise_progress . has_inst_course_offering_exercise? ( )
257-
258- exercise_progress . post_course_offering_exercise_score_to_lms ( )
259- end
260- format . json {
261- render :json => {
262- :exercise_progress => exercise_progress ,
263- :threshold => threshold ,
264- :was_proficient => already_proficient ,
265- :is_proficient => exercise_progress . proficient? ,
266- }
267- }
268- else
269- msg = { :status => "fail" , :message => "Fail!" }
270- format . json { render :json => msg }
167+ format . json do
168+ render json : { status : "fail" , message : "Unable to find inst_book_section_exercise!" } , status : :bad_request
271169 end
272170 end
273- else
274- respond_to do |format |
275- msg = { :status => "fail" , :message => "Fail!" }
276- format . json { render :json => msg }
277- end
278- end
279- end
280-
281-
282- # -------------------------------------------------------------
283- # POST /odsa_exercise_attempts/ae
284- def create_ae
285- unless user_logged_in?
286171 return
287172 end
288-
289- hasBook = params . key? ( :inst_book_id )
290- is_standalone_module = params . key? ( :inst_module_version_id )
291- if params . key? ( :inst_book_section_exercise_id )
292- inst_book_section_exercise = InstBookSectionExercise . find ( params [ :inst_book_section_exercise_id ] )
293- inst_section = inst_book_section_exercise . inst_section
294- threshold = inst_book_section_exercise . threshold
295- elsif hasBook
296- inst_book = InstBook . find_by ( id : params [ :inst_book_id ] )
297- inst_exercise = InstExercise . find_by ( short_name : params [ :exercise ] )
298- inst_section = InstSection . find_by ( id : params [ :inst_section_id ] )
299- inst_book_section_exercise = InstBookSectionExercise . where (
300- "inst_book_id=? and inst_section_id=? and inst_exercise_id=?" ,
301- params [ :inst_book_id ] , params [ :inst_section_id ] , inst_exercise . id
302- ) . first
303- if inst_book_section_exercise . blank?
304- respond_to do |format |
305- msg = { :status => "fail" , :message => "Fail!" }
306- format . json { render :json => msg }
307- end
308- return
309- end
310173 threshold = inst_book_section_exercise . threshold
311174 elsif is_standalone_module
312175 inst_exercise = InstExercise . find_by ( short_name : params [ :exercise ] )
@@ -353,8 +216,12 @@ def create_ae
353216
354217 already_proficient = exercise_progress . proficient?
355218
356- correct = 1
357- #correct = params[:score].to_f >= params[:threshold].to_f
219+
220+ correct = 1 #params[:score][:correct]
221+ request_type = params [ :type ]
222+ if request_type == "PE"
223+ correct = params [ :score ] [ :correct ] . to_f >= params [ :threshold ] . to_f
224+ end
358225
359226 exercise_attempt = OdsaExerciseAttempt . new (
360227 inst_book_id : params [ :inst_book_id ] ,
@@ -371,7 +238,7 @@ def create_ae
371238 count_attempts : params [ :uiid ] ,
372239 hint_used : 0 ,
373240 question_name : params [ :exercise ] ,
374- request_type : "AE" ,
241+ request_type : request_type ,
375242 ip_address : request . ip ,
376243 pe_score : params [ :score ] ,
377244 pe_steps_fixed : params [ :steps_fixed ] ,
0 commit comments