get_lemmas_stats.py 1.64 KB
#-*- coding:utf-8 -*-

import datetime

from django.core.management.base import BaseCommand

from dictionary.models import Lemma
from dictionary.models import get_checked_statuses


STARTDATE = datetime.datetime(2018, 7, 1, 00, 00)
ENDDATE = datetime.datetime(2019, 1, 1, 00, 00)


class Command(BaseCommand):
    help = 'Get Walenty lemmas simple statistics.'

    def handle(self, **options):
        get_lemmas_stats(STARTDATE, ENDDATE, 'noun')
        get_lemmas_stats(STARTDATE, ENDDATE, 'verb')
        get_lemmas_stats(STARTDATE, ENDDATE, 'adv')
        get_lemmas_stats(STARTDATE, ENDDATE, 'adj')


def get_lemmas_stats(start, end, pos):
    checked_statuses = get_checked_statuses()

    stats = {u'Sprawdzone składniowo': [],
             u'Wykonane semantycznie': [],
             u'Sprawdzone semantycznie': []}

    lemmas = Lemma.objects.filter(old=False,
                                  entry_obj__pos__tag=pos).filter(status__in=checked_statuses).distinct()

    for lemma in lemmas.order_by('entry_obj__name').all():
        history_from_to = lemma.status_history.filter(date__gte=start, date__lt=end)

        if history_from_to.filter(status__type__sym_name='checked').exists():
            stats[u'Sprawdzone składniowo'].append(lemma.entry_obj.name)

        if history_from_to.filter(status__type__sym_name='ready_s').exists():
            stats[u'Wykonane semantycznie'].append(lemma.entry_obj.name)

        if history_from_to.filter(status__type__sym_name='checked_s').exists():
            stats[u'Sprawdzone semantycznie'].append(lemma.entry_obj.name)

    print(pos)
    for key in stats:
        print(key, len(stats[key]))
        print(stats[key])