Exemplo n.º 1
0
    def handle(self, *args, **options):
        if options['date']:
            date_of = datetime.strptime(options['date'],
                                        API_DATE_FORMAT).date()
        else:
            date_of = datetime.now().date()

        for org_id in getParentOrganizationsWithVoters():
            self.stdout.write('Organization: %s' % str(org_id))
            data = getCompassData(date_of, org_id)
            if data == []:
                self.stdout.write('No data for compass. Organization %s' %
                                  str(org_id))
            #print data

            existing_compas = Compass.objects.filter(
                created_for=date_of, organization__id_parladata=org_id)
            if existing_compas:
                existing_compas[0].data = data
                existing_compas[0].save()
            else:
                org = Organization.objects.get(id_parladata=org_id)
                Compass(created_for=date_of, data=data,
                        organization=org).save()
            self.stdout.write('Compass was set.')
        return 0
Exemplo n.º 2
0
    def handle(self, *args, **options):
        date_of = datetime.now().date()
        date_ = date_of.strftime(API_DATE_FORMAT)
        for org_id in getParentOrganizationsWithVoters():
            sw = WordAnalysis(organization_id=org_id,
                              count_of='groups',
                              date_=date_)

            #if not sw.isNewSpeech:
            #    return JsonResponse({'alliswell': True,
            #                         'msg': 'Na ta dan ni bilo govorov'})

            # Vocabolary size
            all_score = sw.getVocabularySize()
            max_score, maxPGid = sw.getMaxVocabularySize()
            avg_score = sw.getAvgVocabularySize()
            date_of = sw.getDate()
            maxPG = Organization.objects.get(id_parladata=maxPGid)

            print '[INFO] saving vocabulary size'
            for p in all_score:
                self.stdout.write('Settings organisation %s' %
                                  str(p['counter_id']))
                org = Organization.objects.get(
                    id_parladata=int(p['counter_id']))
                saveOrAbortNew(model=VocabularySize,
                               organization=org,
                               created_for=date_of,
                               score=int(p['coef']),
                               maxOrg=maxPG,
                               average=avg_score,
                               maximum=max_score)

            self.stdout.write('DONE')
        return 0
Exemplo n.º 3
0
    def handle(self, *args, **options):
        date_of = datetime.now().date()
        date_ = date_of.strftime(API_DATE_FORMAT)

        for org_id in getParentOrganizationsWithVoters():
            members = getVotersIDs(organization_id=org_id)
            setPercentOFAttendedSession(self, members, date_of)
        return 0
    def handle(self, *args, **options):
        date_ = ''

        if options['date']:
            date_of = datetime.strptime(options['date'],
                                        API_DATE_FORMAT).date()
            date_ = options['date']
        else:
            # dirty work around, TODO: fix findDatesFromLastCard for input without person_id
            #date_of = findDatesFromLastCard(Presence, '11', datetime.now().strftime(API_DATE_FORMAT))[0]
            date_of = datetime.now().date()
            date_ = date_of.strftime(API_DATE_FORMAT)

        data = getQuestions()
        self.stdout.write('Get voters')
        for org_id in getParentOrganizationsWithVoters():
            mps_ids = getVotersIDs(date_=date_of, organization_id=org_id)
            print(mps_ids)
            authors = []
            for question in data:
                for author in question['authors']:
                    if author in mps_ids:
                        authors.append(author)

            print(org_id, len(authors), float(len(mps_ids)))
            try:
                avg = len(authors) / float(len(mps_ids))
            except ZeroDivisionError as error:
                avg = 0
            question_count = Counter(authors)
            max_value = 0
            max_persons = []
            for maxi in question_count.most_common(90):
                if max_value == 0:
                    max_value = maxi[1]
                if maxi[1] == max_value:
                    max_persons.append(maxi[0])
                else:
                    break

            for person_id in mps_ids:
                person = Person.objects.get(id_parladata=person_id)
                saveOrAbortNew(model=NumberOfQuestions,
                               created_for=date_of,
                               person=person,
                               score=question_count[person_id],
                               average=avg,
                               maximum=max_value,
                               maxMPs=max_persons)

                self.stdout.write('Done setting NumberOfQuestions to MP %s' %
                                  str(person.id_parladata))

        return 0
Exemplo n.º 5
0
    def handle(self, *args, **options):
        if options['date']:
            date_ = options['date']
        else:
            date_ = datetime.now().date().strftime(API_DATE_FORMAT)

        # TODO refactor votes_pg.py to stop accepting request as an argument
        for org_id in getParentOrganizationsWithVoters():
            set_mismatch_of_pg(None, by_organization=org_id, date_=date_)

        return 0
Exemplo n.º 6
0
    def handle(self, *args, **options):
        if options['date']:
            date_ = options['date']
        else:
            date_ = datetime.now().date().strftime(API_DATE_FORMAT)
        for org_id in getParentOrganizationsWithVoters():
            votes = VotesAnalysis(organization_id=org_id, date_=datetime.strptime(date_, API_DATE_FORMAT))
            self.stdout.write('About to begin VotesAnalysis for %s' % str(date_))
            votes.setAll()
            self.stdout.write('Done with VotesAnalysis for %s' % str(date_))

        return 0
    def handle(self, *args, **options):
        ses_ids = []
        if options['session_ids']:
            ses_ids = options['session_ids']
        else:
            if options['fast']:
                orgs = getParentOrganizationsWithVoters()
                sessions = Session.objects.filter(
                    organization__id_parladata__in=orgs).order_by(
                        '-start_time')
                ses_ids = sessions[:2].values_list('id_parladata', flat=True)
            else:
                ses_ids = Session.objects.all().values_list('id_parladata',
                                                            flat=True)

        # get static data
        self.stdout.write('Getting all static data')

        uploadSessionToSolr(self, ses_ids)

        return 0
Exemplo n.º 8
0
    def handle(self, *args, **options):
        date_of = datetime.now().date()
        date_ = date_of.strftime(API_DATE_FORMAT)

        for org in getParentOrganizationsWithVoters():

            self.stdout.write('getting organizations with voters')
            organization_ids = getOrganizationsWithVoters(date_=date_of)

            scores = {}
            for organization_id in organization_ids:

                self.stdout.write('Org id: %s' % str(organization_id))
                # get word counts with solr
                counter = Counter(
                    getCountList(self, int(organization_id), date_))
                total = sum(counter.values())

                scores_local = getScores(
                    [problematicno, privzdignjeno, preprosto], counter, total)

                self.stdout.write('Outputting scores_local: %s' %
                                  str(scores_local))
                scores[organization_id] = scores_local

            self.stdout.write('Outputting scores: %s' % str(scores))
            average = {
                "problematicno":
                sum([score['problematicno']
                     for score in scores.values()]) / len(scores),
                "privzdignjeno":
                sum([score['privzdignjeno']
                     for score in scores.values()]) / len(scores),
                "preprosto":
                sum([score['preprosto']
                     for score in scores.values()]) / len(scores)
            }
            data = []
            for org_id, score in scores.items():
                data.append({
                    'org': org_id,
                    'problematicno': score['problematicno'],
                    'privzdignjeno': score['privzdignjeno'],
                    'preprosto': score['preprosto'],
                    'problematicno_average': average['problematicno'],
                    'privzdignjeno_average': average['privzdignjeno'],
                    'preprosto_average': average['preprosto']
                })

            for score in data:
                self.stdout.write('About to save %s' % str(score))
                status = saveOrAbortNew(
                    StyleScores,
                    organization=Organization.objects.get(
                        id_parladata=int(score['org'])),
                    created_for=date_of,
                    problematicno=float(score['problematicno']),
                    privzdignjeno=float(score['privzdignjeno']),
                    preprosto=float(score['preprosto']),
                    problematicno_average=float(
                        score['problematicno_average']),
                    privzdignjeno_average=float(
                        score['privzdignjeno_average']),
                    preprosto_average=float(score['preprosto_average']))
                self.stdout.write('SaveOrAbort status: %s' % str(status))

        return 0
Exemplo n.º 9
0
def setAllVotesCards():
    for org_id in getParentOrganizationsWithVoters():
        votesObj = VotesAnalysis(organization_id=org_id)
        votesObj.setAll()
        return 'All is well'
Exemplo n.º 10
0
    def handle(self, *args, **options):
        if options['date']:
            date_ = options['date']
            date_of = datetime.strptime(API_DATE_FORMAT).date()
        else:
            date_of = datetime.now().date()
            date_ = date_of.strftime(API_DATE_FORMAT)

        self.stdout.write('Getting voters')
        for org in getParentOrganizationsWithVoters():
            self.stdout.write('Starting style score for organization %s' % (org))
            mps = getVotersIDs(organization_id=org, date_=date_of)
            scores = {}
            for person_id in mps:

                self.stdout.write('MP id: %s' % str(person_id))
                # get word counts with solr
                counter = Counter(getCountList(self, int(person_id), date_))
                total = sum(counter.values())

                scores_local = getScores([problematicno, privzdignjeno, preprosto],
                                        counter,
                                        total)

                self.stdout.write('Outputting scores_local: %s' %
                                str(scores_local))
                scores[person_id] = scores_local

            self.stdout.write('Outputting scores: %s' % str(scores))
            average = {"problematicno": sum([score['problematicno']
                                            for score
                                            in scores.values()])/len(scores),
                    "privzdignjeno": sum([score['privzdignjeno']
                                            for score
                                            in scores.values()])/len(scores),
                    "preprosto": sum([score['preprosto']
                                        for score
                                        in scores.values()])/len(scores)}
            data = []
            for person, score in scores.items():
                data.append({'member': person,
                            'problematicno': score['problematicno'],
                            'privzdignjeno': score['privzdignjeno'],
                            'preprosto': score['preprosto'],
                            'problematicno_average': average['problematicno'],
                            'privzdignjeno_average': average['privzdignjeno'],
                            'preprosto_average': average['preprosto']})

            for score in data:
                self.stdout.write('About to save %s' % str(score))
                status = saveOrAbortNew(StyleScores,
                                        person=Person.objects.get(
                                            id_parladata=int(score["member"])),
                                        created_for=date_of,
                                        problematicno=float(
                                            score['problematicno']),
                                        privzdignjeno=float(
                                            score['privzdignjeno']),
                                        preprosto=float(score['preprosto']),
                                        problematicno_average=float(
                                            score['problematicno_average']),
                                        privzdignjeno_average=float(
                                            score['privzdignjeno_average']),
                                        preprosto_average=float(
                                            score['preprosto_average'])
                                        )
                self.stdout.write('SaveOrAbort status: %s' % str(status))

        return 0
Exemplo n.º 11
0
    def handle(self, *args, **options):
        if options['date']:
            date_ = options['date']
            date_of = datetime.strptime(date_, API_DATE_FORMAT).date()
        else:
            date_ = datetime.now().date().strftime(API_DATE_FORMAT)
            date_of = datetime.now().date()

        data = getQuestions()

        for org_id in getParentOrganizationsWithVoters():
            pgs_on_date = getOrganizationsWithVoters(date_=date_of,
                                                     organization_id=org_id)
            mps = getVotersIDs(date_=date_of, organization_id=org_id)

            mpStatic = {}
            for mp in mps:
                mpStatic[str(mp)] = getPersonData(str(mp), date_)

            pg_ids = pgs_on_date
            authors = []
            for question in data:
                qDate = datetime.strptime(question['date'], '%Y-%m-%dT%X')
                qDate = qDate.strftime(API_DATE_FORMAT)
                for author in question['authors']:
                    try:
                        person_data = mpStatic[str(author)]
                    except KeyError as e:
                        print(str(question['authors']))
                        person_data = getPersonData(str(author), date_)
                        mpStatic[str(author)] = person_data
                    if person_data and person_data['party'] and person_data[
                            'party']['id']:
                        authors.append(person_data['party']['id'])
                    else:
                        print 'person nima mpstatic: ', author

            avg = len(authors) / float(len(pg_ids))
            question_count = Counter(authors)
            max_value = 0
            max_orgs = []
            for maxi in question_count.most_common(90):
                if max_value == 0:
                    max_value = maxi[1]
                if maxi[1] == max_value:
                    max_orgs.append(maxi[0])
                else:
                    break
            is_saved = []
            for pg_id in pg_ids:
                org = Organization.objects.get(id_parladata=pg_id)
                is_saved.append(
                    saveOrAbortNew(model=NumberOfQuestions,
                                   created_for=date_of,
                                   organization=org,
                                   score=question_count[pg_id],
                                   average=avg,
                                   maximum=max_value,
                                   maxOrgs=max_orgs))

        return 0
Exemplo n.º 12
0
    def handle(self, *args, **options):
        if options['date']:
            date_of = datetime.strptime(options['date'], API_DATE_FORMAT)
        else:
            date_of = datetime.now().date()
        date_ = date_of.strftime(API_DATE_FORMAT)
        for org_id in getParentOrganizationsWithVoters():
            sw = WordAnalysis(organization_id=org_id,
                              count_of='members',
                              date_=date_)

            #if not sw.isNewSpeech:
            #    return JsonResponse({'alliswell': False})

            #Vocabolary size
            all_score = sw.getVocabularySize()
            max_score, maxMPid = sw.getMaxVocabularySize()
            avg_score = sw.getAvgVocabularySize()
            date_of = sw.getDate()
            maxMP = Person.objects.get(id_parladata=maxMPid)

            self.stdout.write('[INFO] saving vocabulary size')
            for p in all_score:
                self.stdout.write(
                    '[INFO] saving vocabulary size for person %s' %
                    str(p['counter_id']))
                saveOrAbortNew(model=VocabularySize,
                               person=Person.objects.get(
                                   id_parladata=int(p['counter_id'])),
                               created_for=date_of,
                               score=int(p['coef']),
                               maxMP=maxMP,
                               average=avg_score,
                               maximum=max_score)

            #Unique words
            all_score = sw.getUniqueWords()
            max_score, maxMPid = sw.getMaxUniqueWords()
            avg_score = sw.getAvgUniqueWords()
            date_of = sw.getDate()
            maxMP = Person.objects.get(id_parladata=maxMPid)

            self.stdout.write('[INFO] saving unique words')
            for p in all_score:
                self.stdout.write('[INFO] saving unique words for person %s' %
                                  str(p['counter_id']))
                saveOrAbortNew(model=VocabularySizeUniqueWords,
                               person=Person.objects.get(
                                   id_parladata=int(p['counter_id'])),
                               created_for=date_of,
                               score=int(p['unique']),
                               maxMP=maxMP,
                               average=avg_score,
                               maximum=max_score)

            #Spoken words
            all_words = sw.getSpokenWords()
            max_words, maxWordsMPid = sw.getMaxSpokenWords()
            avgSpokenWords = sw.getAvgSpokenWords()
            date_of = sw.getDate()
            maxMP = Person.objects.get(id_parladata=maxWordsMPid)

            self.stdout.write('[INFO] saving spoken words')
            for p in all_words:
                self.stdout.write('[INFO] saving spoken words for person %s' %
                                  str(p['counter_id']))
                saveOrAbortNew(model=SpokenWords,
                               created_for=date_of,
                               person=Person.objects.get(
                                   id_parladata=int(p['counter_id'])),
                               score=int(p['wordcount']),
                               maxMP=maxMP,
                               average=avgSpokenWords,
                               maximum=max_words)

            self.stdout.write('[INFO] All MPs updated')

        return 0
Exemplo n.º 13
0
 def handle(self, *args, **options):
     date_of = datetime.now().date()
     for parent_id in getParentOrganizationsWithVoters():
         mps = getVotersIDs(date_=date_of, organization_id=parent_id)
         for org_id in getOrganizationsWithVoters(organization_id=parent_id, date_=date_of):
             setPercentOFAttendedSessionPG(org_id, date_of=date_of, parenet_org=parent_id)