<commit_before><commit_msg>Implements the script to generate csvs<commit_after>import time
from datetime import datetime, timedelta

from django.db import transaction
from django.core.management.base import BaseCommand

from ivrs.models import State
from stories.models import Story, UserType, Questiongroup, Answer


class Command(BaseCommand):
    args = ""
    help = """Creates csv files for calls happened each day

    ./manage.py generategkacsv"""

    @transaction.atomic
    def handle(self, *args, **options):
        states = State.objects.filter(
            date_of_visit__lte=datetime.now()
        )

        date = datetime.now().date().strftime("%d_%b_%Y")
        csv = open(date+".csv", "w")

        lines = ["Sl. No, School ID, Telephone, Date Of Visit, Invalid, \
Was the school open?, \
Class visited, \
Was Math class happening on the day of your visit?, \
Which chapter of the textbook was taught?, \
Which Ganitha Kalika Andolana TLM was being used by teacher?, \
Did you see children using the Ganitha Kalika Andolana TLM?, \
Was group work happening in the class on the day of your visit?, \
Were children using square line book during math class?, \
Are all the toilets in the school functional?, \
Does the school have a separate functional toilet for girls?, \
Does the school have drinking water?, \
Is a Mid Day Meal served in the school?"
]

        for (number, state) in enumerate(states):
            values = [str(number + 1),
                      str(state.school_id),
                      str(state.telephone),
                      str(state.date_of_visit.date()),
                      str(state.is_invalid)
            ]
            values = values + [answer for answer in state.answers[1:]]
            values = ",".join(values)
            lines.append(str(values))
                            
        for line in lines:
            csv.write(line+"\n")
{'fraction_non_alphanumeric': 0.09468700683850605, 'fraction_numerical': 0.0010520778537611783, 'mean_word_length': 2.4835164835164836, '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': '245987', 'n_tokens_mistral': 522, 'n_tokens_neox': 498, 'n_words': 193}