<commit_before>from kolibri.logger.models import AttemptLog, ContentRatingLog, ContentSessionLog, ContentSummaryLog, MasteryLog, UserSessionLog
from rest_framework import serializers


class ContentSessionLogSerializer(serializers.ModelSerializer):

    class Meta:
        model = ContentSessionLog
        fields = ('pk', 'user', 'content_id', 'channel_id', 'start_timestamp',
                  'end_timestamp', 'time_spent', 'kind', 'extra_fields', 'progress')

class MasteryLogSerializer(serializers.ModelSerializer):

    responsehistory = serializers.SerializerMethodField()
    totalattempts = serializers.SerializerMethodField()

    class Meta:
        model = MasteryLog
        fields = ('pk', 'summarylog', 'start_timestamp', 'responsehistory', 'totalattempts',
                  'end_timestamp', 'completion_timestamp', 'mastery_criterion', 'mastery_level', 'complete')

    def get_responsehistory(self, obj):
        try:
            logs = obj.attemptlogs.order_by('completion_timestamp').values('correct')
            return logs
        except AttemptLog.DoesNotExist:
            return []

    def get_totalattempts(self, obj):
        return AttemptLog.objects.filter(masterylog__summarylog=obj.summarylog).count()

class AttemptLogSerializer(serializers.ModelSerializer):

    class Meta:
        model = AttemptLog
        fields = ('pk', 'masterylog', 'start_timestamp',
                  'end_timestamp', 'completion_timestamp', 'item', 'time_spent',
                  'complete', 'correct', 'answer', 'simple_answer', 'interaction_history')

class NestedMasteryLogSerializer(MasteryLogSerializer):

    currentattemptlog = serializers.SerializerMethodField()

    class Meta(MasteryLogSerializer.Meta):
        fields = MasteryLogSerializer.Meta.fields + ('currentattemptlog',)
<commit_msg>replace totalattempts with pastattempts that returns a list of correct filed<commit_after>from kolibri.logger.models import AttemptLog, ContentRatingLog, ContentSessionLog, ContentSummaryLog, MasteryLog, UserSessionLog
from rest_framework import serializers


class ContentSessionLogSerializer(serializers.ModelSerializer):

    class Meta:
        model = ContentSessionLog
        fields = ('pk', 'user', 'content_id', 'channel_id', 'start_timestamp',
                  'end_timestamp', 'time_spent', 'kind', 'extra_fields', 'progress')

class MasteryLogSerializer(serializers.ModelSerializer):

    responsehistory = serializers.SerializerMethodField()
    pastattempts = serializers.SerializerMethodField()

    class Meta:
        model = MasteryLog
        fields = ('pk', 'summarylog', 'start_timestamp', 'responsehistory', 'pastattempts',
                  'end_timestamp', 'completion_timestamp', 'mastery_criterion', 'mastery_level', 'complete')

    def get_responsehistory(self, obj):
        try:
            logs = obj.attemptlogs.order_by('completion_timestamp').values('correct')
            return logs
        except AttemptLog.DoesNotExist:
            return []

    def get_pastattempts(self, obj):
        # will return a list of correct field for each attempt.
        return AttemptLog.objects.filter(masterylog__summarylog=obj.summarylog).values_list('correct', flat=True)

class AttemptLogSerializer(serializers.ModelSerializer):

    class Meta:
        model = AttemptLog
        fields = ('pk', 'masterylog', 'start_timestamp',
                  'end_timestamp', 'completion_timestamp', 'item', 'time_spent',
                  'complete', 'correct', 'answer', 'simple_answer', 'interaction_history')

class NestedMasteryLogSerializer(MasteryLogSerializer):

    currentattemptlog = serializers.SerializerMethodField()

    class Meta(MasteryLogSerializer.Meta):
        fields = MasteryLogSerializer.Meta.fields + ('currentattemptlog',)

{'fraction_non_alphanumeric': 0.10312004230565838, 'fraction_numerical': 0.0, 'mean_word_length': 3.9776315789473684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1051473', 'n_tokens_mistral': 1023, 'n_tokens_neox': 962, 'n_words': 211}