Commit 369f5fcb authored by I.K Seneviratne's avatar I.K Seneviratne

Committing the implementation of lecture activity frame recordings.

parent f451b8fa
...@@ -189,9 +189,9 @@ class LectureActivityFrameGroupings(models.Model): ...@@ -189,9 +189,9 @@ class LectureActivityFrameGroupings(models.Model):
# this abstract class will contain lecture activity frame recognition details # this abstract class will contain lecture activity frame recognition details
class LectureActivityFrameRecognitionDetails(models.Model): class LectureActivityFrameRecognitionDetails(models.Model):
frame_name = models.CharField(max_length=15) frame_name = models.CharField(max_length=15)
phone_perct = models.DecimalField(default=0.0, max_digits=3, decimal_places=1) phone_perct = models.FloatField()
listen_perct = models.DecimalField(default=0.0, max_digits=3, decimal_places=1) listen_perct = models.FloatField()
note_perct = models.DecimalField(default=0.0, max_digits=3, decimal_places=1) note_perct = models.FloatField()
class Meta: class Meta:
abstract = True abstract = True
......
...@@ -361,8 +361,59 @@ class GetLectureActivityRecognitionsForFrames(APIView): ...@@ -361,8 +361,59 @@ class GetLectureActivityRecognitionsForFrames(APIView):
def get(self, request): def get(self, request):
video_name = request.query_params.get('video_name') video_name = request.query_params.get('video_name')
# finding the existence of Lecture activity frame recognition record
isExist = LectureActivityFrameRecognitions.objects.filter(lecture_activity_id__lecture_video_id__video_name=video_name).exists()
if (isExist):
lecture_activity_frame_recognitions = LectureActivityFrameRecognitions.objects.filter(lecture_activity_id__lecture_video_id__video_name=video_name)
lecture_activity_frame_recognitions_ser = LectureActivityFrameRecognitionsSerializer(lecture_activity_frame_recognitions, many=True)
lecture_activity_frame_recognitions_data = lecture_activity_frame_recognitions_ser.data[0]
frame_detections = lecture_activity_frame_recognitions_data['frame_recognition_details']
return Response({
"response": frame_detections
})
else:
# retrieve the lecture activity id
lec_activity = LectureActivity.objects.filter(lecture_video_id__video_name=video_name)
lec_activity_ser = LectureActivitySerializer(lec_activity, many=True)
lec_activity_data = lec_activity_ser.data[0]
lec_activity_id = lec_activity_data['id']
# create a new lecture activity frame detections id
last_lec_activity_frame_recognitions = LectureActivityFrameRecognitions.objects.order_by('lecture_activity_frame_recognition_id').last()
new_lecture_activity_frame_recognitions_id = "LAFR00001" if (last_lec_activity_frame_recognitions is None) else \
ig.generate_new_id(last_lec_activity_frame_recognitions.lecture_activity_frame_recognition_id)
# calculate the frame detections
frame_detections = ar.get_frame_activity_recognition(video_name) frame_detections = ar.get_frame_activity_recognition(video_name)
frame_recognition_details = []
# save the new lecture activity frame recognitions
for detection in frame_detections:
lec_activity_frame_recognition_details = LectureActivityFrameRecognitionDetails()
lec_activity_frame_recognition_details.frame_name = detection['frame_name']
lec_activity_frame_recognition_details.phone_perct = detection['phone_perct']
lec_activity_frame_recognition_details.listen_perct = detection['listening_perct']
lec_activity_frame_recognition_details.note_perct = detection['note_perct']
frame_recognition_details.append(lec_activity_frame_recognition_details)
lec_activity_frame_recognitions = LectureActivityFrameRecognitions()
lec_activity_frame_recognitions.lecture_activity_frame_recognition_id = new_lecture_activity_frame_recognitions_id
lec_activity_frame_recognitions.lecture_activity_id_id = lec_activity_id
lec_activity_frame_recognitions.frame_recognition_details = frame_recognition_details
lec_activity_frame_recognitions.save()
return Response({ return Response({
"response": frame_detections "response": frame_detections
}) })
......
...@@ -289,6 +289,7 @@ class LectureActivityFrameRecognitionsSerializer(serializers.ModelSerializer): ...@@ -289,6 +289,7 @@ class LectureActivityFrameRecognitionsSerializer(serializers.ModelSerializer):
lecture_activity_id = LectureActivitySerializer() lecture_activity_id = LectureActivitySerializer()
frame_recognition_details = serializers.SerializerMethodField() frame_recognition_details = serializers.SerializerMethodField()
# this method will be used to serialize the 'frame_recogition_details' field
def get_frame_recognition_details(self, obj): def get_frame_recognition_details(self, obj):
return_data = [] return_data = []
...@@ -297,9 +298,9 @@ class LectureActivityFrameRecognitionsSerializer(serializers.ModelSerializer): ...@@ -297,9 +298,9 @@ class LectureActivityFrameRecognitionsSerializer(serializers.ModelSerializer):
recognition = {} recognition = {}
recognition["frame_name"] = frame_recognition.frame_name recognition["frame_name"] = frame_recognition.frame_name
recognition["phone_perct"] = frame_recognition.frame_name recognition["phone_perct"] = frame_recognition.phone_perct
recognition["listen_perct"] = frame_recognition.frame_name recognition["listen_perct"] = frame_recognition.listen_perct
recognition["note_perct"] = frame_recognition.frame_name recognition["note_perct"] = frame_recognition.note_perct
return_data.append(recognition) return_data.append(recognition)
...@@ -307,6 +308,11 @@ class LectureActivityFrameRecognitionsSerializer(serializers.ModelSerializer): ...@@ -307,6 +308,11 @@ class LectureActivityFrameRecognitionsSerializer(serializers.ModelSerializer):
return return_data return return_data
class Meta:
model = LectureActivityFrameRecognitions
fields = '__all__'
# EMOTIONS section # EMOTIONS section
# lecture emotions serailzier # lecture emotions serailzier
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment