<commit_before>__author__ = '<NAME>'

from django.core.management.base import BaseCommand
from alert.search.models import Document
from alert.lib.db_tools import queryset_generator

import sys
import time


class Command(BaseCommand):

    def output_citing_relation(self):
        out_file = open('citing_relation.txt', 'w')
        graph_size = Document.objects.all().count()

        qs = Document.objects.only(
            'documentUUID',
            'cases_cited',
        )
        case_list = queryset_generator(qs, chunksize=10000)
        case_count = 0
        timings = []
        average_per_s = 0
        for source_case in case_list:
            case_count += 1
            if case_count % 100 == 1:
                t1 = time.time()
            if case_count % 100 == 0:
                t2 = time.time()
                timings.append(t2 - t1)
                average_per_s = 100 / (sum(timings) / float(len(timings)))
            sys.stdout.write("\rGenerating relation file...{:.0%} ({}/{}, {:.1f}/s)".format(
                case_count * 1.0 / graph_size,
                case_count,
                graph_size,
                average_per_s,
            ))
            sys.stdout.flush()
            for target_case in source_case.cases_cited.all():
                out_file.write(str(source_case.documentUUID)
                    + '\t' + str(target_case.document_set.all()[0].documentUUID) + '\n')

        out_file.close()

    def handle(self, *args, **options):
        self.output_citing_relation()<commit_msg>Update the cl_output_citing_relation.py Become a little bit faster.<commit_after>__author__ = '<NAME>'

from django.core.management.base import BaseCommand
from alert.search.models import Document
from alert.lib.db_tools import queryset_generator

import sys
import time


class Command(BaseCommand):

    def output_citing_relation(self):
        out_file = open('citing_relation.txt', 'w')
        graph_size = Document.objects.all().count()

        qs = Document.objects.only(
            'documentUUID',
            'cases_cited',
        )
        case_list = queryset_generator(qs, chunksize=10000)
        case_count = 0
        timings = []
        average_per_s = 0
        for source_case in case_list:
            case_count += 1
            if case_count % 100 == 1:
                t1 = time.time()
            if case_count % 100 == 0:
                t2 = time.time()
                timings.append(t2 - t1)
                average_per_s = 100 / (sum(timings) / float(len(timings)))
            sys.stdout.write("\rGenerating relation file...{:.0%} ({}/{}, {:.1f}/s)".format(
                case_count * 1.0 / graph_size,
                case_count,
                graph_size,
                average_per_s,
            ))
            sys.stdout.flush()
            for target_case in source_case.cases_cited.values_list('document__pk'):
                out_file.write(str(source_case.documentUUID)
                    + '\t' + str(target_case[0]) + '\n')

        out_file.close()

    def handle(self, *args, **options):
        self.output_citing_relation()
{'fraction_non_alphanumeric': 0.11407455012853471, 'fraction_numerical': 0.017994858611825194, 'mean_word_length': 1.8850787766450416, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1461345', 'n_tokens_mistral': 978, 'n_tokens_neox': 900, 'n_words': 182}