Exemplo n.º 1
0
    def process_state(self, qg_type):
        states = State.objects.filter(
            qg_type=qg_type,
            is_processed=False,
        )

        valid_count = states.filter(is_invalid=False).count()
        invalid_count = states.filter(is_invalid=True).count()

        for state in states:
            state.is_processed = True
            state.save()

            if state.is_invalid:
                continue

            user = state.user
            school = School.objects.get(id=state.school_id)
            telephone = state.telephone
            date = state.date_of_visit
            akshara_staff = UserType.objects.get_or_create(
                name=UserType.AKSHARA_STAFF)[0]
            question_group = qg_type.questiongroup
            story = Story.objects.create(user=user,
                                         school=school,
                                         is_verified=True,
                                         group=question_group,
                                         date_of_visit=date,
                                         telephone=telephone,
                                         user_type=akshara_staff)
            for (question_number, answer) in enumerate(state.answers[1:]):
                if answer != 'NA':
                    question = get_question(question_number + 1,
                                            qg_type.questiongroup)
                    answer = Answer.objects.get_or_create(story=story,
                                                          question=question,
                                                          text=answer)

        if qg_type.name == 'gkav4':
            author = 'GKA SMS'
            emoji = ':memo:'
        else:
            author = None

        if author:
            try:
                post_to_slack(
                    channel='#klp',
                    author=author,
                    message='%s Valid calls & %s Invalid calls' %
                    (valid_count, invalid_count),
                    emoji=emoji,
                )
            except:
                pass
Exemplo n.º 2
0
    def process_state(self, qg_type):
        states = State.objects.filter(
            qg_type=qg_type,
            is_processed=False,
        )

        valid_count = states.filter(is_invalid=False).count()
        invalid_count = states.filter(is_invalid=True).count()

        for state in states:
            state.is_processed = True
            state.save()

            if state.is_invalid:
                continue

            user = state.user
            institution = Institution.objects.get(id=state.school_id)
            date = state.date_of_visit
            mobile = state.telephone
            akshara_staff = RespondentType.objects.get(name='Akshara Staff')
            question_group = qg_type.questiongroup
            status = Status.objects.get(name='Active')
            if user.first_name == 'Unknown' and user.last_name == 'User':
                answergroup, created = AnswerGroup_Institution.objects.get_or_create(
                    created_by=user,
                    institution=institution,
                    is_verified=True,
                    questiongroup=question_group,
                    date_of_visit=date,
                    status=status,
                    respondent_type=akshara_staff,
                    mobile=mobile)
            else:
                answergroup, created = AnswerGroup_Institution.objects.get_or_create(
                    created_by=user,
                    institution=institution,
                    is_verified=True,
                    questiongroup=question_group,
                    date_of_visit=date,
                    status=status,
                    respondent_type=akshara_staff,
                    defaults={'mobile': mobile})
            for (question_number, answer) in enumerate(state.answers[1:]):
                if answer != 'NA':
                    question = get_question(question_number + 1,
                                            qg_type.questiongroup)
                    answerinstitution = AnswerInstitution.objects.get_or_create(
                        answergroup=answergroup,
                        question=question,
                        answer=answer,
                        double_entry=0)
        if qg_type.name == 'gkav4':
            author = 'GKA SMS'
            emoji = ':memo:'
        else:
            author = None
        if author:
            try:
                post_to_slack(
                    channel='#klp',
                    author=author,
                    message='In Unified DB, %s Valid calls & %s Invalid calls'
                    % (valid_count, invalid_count),
                    emoji=emoji,
                )
            except:
                print("could not post to slack")
                pass
Exemplo n.º 3
0
    def process_state(self, ivrs_type, version):
        valid_count = 0 # For posting daily notifications to slack.
        invalid_count = 0
        fifteen_minutes = datetime.now() - timedelta(minutes=15)

        ivrs_type_number_dict = {
            'gka' : GKA_SERVER,
            'gka-new' : GKA_SERVER,
            'ivrs-pri' : PRI,
            'ivrs-pre' : PRE,
        }

        states = State.objects.filter(
            ivrs_type=ivrs_type,
            is_processed=False,
            date_of_visit__lte=fifteen_minutes
        )

        if states:
            for state in states:
                if not sane_state(state, ivrs_type):
                    state.is_invalid = True
                    invalid_count += 1
                else:
                    school = School.objects.get(id=state.school_id)
                    telephone = state.telephone
                    date = state.date_of_visit
                    akshara_staff = UserType.objects.get_or_create(
                        name=UserType.AKSHARA_STAFF
                    )[0]
                    question_group = Questiongroup.objects.get(
                        version=version,
                        source__name='ivrs'
                    )

                    story = Story.objects.create(
                        school=school,
                        is_verified=True,
                        group=question_group,
                        date_of_visit=date,
                        telephone=telephone,
                        user_type=akshara_staff
                    )

                    for (question_number, answer) in enumerate(state.answers[1:]):
                        if answer != 'NA':
                            question = get_question(
                                question_number+1,
                                ivrs_type_number_dict[ivrs_type]
                            )
                            answer = Answer.objects.get_or_create(
                                story=story,
                                question=question,
                                text=answer
                            )

                    valid_count += 1

                state.is_processed = True
                state.save()

        if ivrs_type in ['gka-new']:
            author = 'GKA IVRS'
        elif ivrs_type == 'ivrs-pri':
            author = 'Primary School IVRS'
        else:
            author = None

        if author:
            try:
                post_to_slack(
                    channel='#klp',
                    author=author,
                    message='%s Valid calls & %s Invalid calls' %(valid_count, invalid_count),
                    emoji=':calling:',
                )
            except:
                pass
Exemplo n.º 4
0
    def process_state(self, qg_type):
        valid_count = 0 # For posting daily notifications to slack.
        invalid_count = 0

        states = State.objects.filter(
            qg_type=qg_type,
            is_processed=False,
        )

        for state in states:
            if not sane_state(state, qg_type):
                state.is_invalid = True
                invalid_count += 1
            else:
                school = School.objects.get(id=state.school_id)
                telephone = state.telephone
                date = state.date_of_visit
                akshara_staff = UserType.objects.get_or_create(
                    name=UserType.AKSHARA_STAFF
                )[0]
                question_group = qg_type.questiongroup
                story = Story.objects.create(
                    school=school,
                    is_verified=True,
                    group=question_group,
                    date_of_visit=date,
                    telephone=telephone,
                    user_type=akshara_staff
                )
                for (question_number, answer) in enumerate(state.answers[1:]):
                    if answer != 'NA':
                        question = get_question(
                            question_number+1,
                            qg_type.questiongroup
                        )
                        answer = Answer.objects.get_or_create(
                            story=story,
                            question=question,
                            text=answer
                        )
                valid_count += 1

            state.is_processed = True
            state.save()

        if qg_type.name == 'gkav3':
            author = 'GKA IVRS'
            emoji = ':calling:'
        elif qg_type.name == 'gkav4':
            author = 'GKA SMS'
            emoji = ':memo:'
        elif qg_type.name == 'prischoolv1':
            author = 'Primary School IVRS'
            emoji = ':calling:'
        else:
            author = None

        if author:
            try:
                post_to_slack(
                    channel='#klp',
                    author=author,
                    message='%s Valid calls & %s Invalid calls' %(valid_count, invalid_count),
                    emoji=emoji,
                )
            except:
                pass
Exemplo n.º 5
0
    def process_state(self, qg_type):
        states = State.objects.filter(
            qg_type=qg_type,
            is_processed=False,
        )

        valid_count = states.filter(is_invalid=False).count()
        invalid_count = states.filter(is_invalid=True).count()

        for state in states:
            state.is_processed = True
            state.save()

            if state.is_invalid:
                continue

            user = state.user
            school = School.objects.get(id=state.school_id)
            telephone = state.telephone
            date = state.date_of_visit
            akshara_staff = UserType.objects.get_or_create(
                name=UserType.AKSHARA_STAFF
            )[0]
            question_group = qg_type.questiongroup
            story = Story.objects.create(
                user=user,
                school=school,
                is_verified=True,
                group=question_group,
                date_of_visit=date,
                telephone=telephone,
                user_type=akshara_staff
            )
            for (question_number, answer) in enumerate(state.answers[1:]):
                if answer != 'NA':
                    question = get_question(
                        question_number+1,
                        qg_type.questiongroup
                    )
                    answer = Answer.objects.get_or_create(
                        story=story,
                        question=question,
                        text=answer
                    )

        if qg_type.name == 'gkav4':
            author = 'GKA SMS'
            emoji = ':memo:'
        else:
            author = None

        if author:
            try:
                post_to_slack(
                    channel='#klp',
                    author=author,
                    message='%s Valid calls & %s Invalid calls' %(valid_count, invalid_count),
                    emoji=emoji,
                )
            except:
                pass