def test_get_final_result_without_questions(self):
     selected_proposals = [self.p1, self.p3]
     calculator = Calculator(self.election, [], selected_proposals)
     R = calculator._get_result().tolist()
     self.assertEquals(R, [[2], [2], [0]])
     final_result = calculator.get_result()
     expected = {'candidates': [{'candidate':self.c1, 'value': 100},
                 {'candidate':self.c2, 'value': 100}],
                 'election': self.election}
     self.assertEquals(final_result, expected)
Example #2
0
 def test_get_final_result_without_questions(self):
     selected_proposals = [self.p1, self.p3]
     calculator = Calculator(self.election, [], selected_proposals)
     R = calculator._get_result().tolist()
     self.assertEquals(R, [[2], [2], [0]])
     final_result = calculator.get_result()
     expected = {'candidates': [{'candidate':self.c1, 'value': 100},
                 {'candidate':self.c2, 'value': 100}],
                 'election': self.election}
     self.assertEquals(final_result, expected)
 def test_get_final_result(self):
     self.setUpQuestions()
     selected_positions = [self.position1, self.position4]
     selected_proposals = [self.p1, self.p3]
     calculator = Calculator(self.election, selected_positions, selected_proposals)
     calculator.set_questions_importance(0.5)
     calculator.set_proposals_importance(0.5)
     R = calculator._get_result().tolist()
     self.assertEquals(R, [[1.5],[1],[0]])
     final_result = calculator.get_result()
     expected = {'candidates': [{'candidate':self.c1, 'value':75.0},
                 {'candidate':self.c2, 'value': 50.0}],
                 'election': self.election}
     self.assertEquals(final_result, expected)
Example #4
0
 def test_get_final_result(self):
     self.setUpQuestions()
     selected_positions = [self.position1, self.position4]
     selected_proposals = [self.p1, self.p3]
     calculator = Calculator(self.election, selected_positions, selected_proposals)
     calculator.set_questions_importance(0.5)
     calculator.set_proposals_importance(0.5)
     R = calculator._get_result().tolist()
     self.assertEquals(R, [[1.5],[1],[0]])
     final_result = calculator.get_result()
     expected = {'candidates': [{'candidate':self.c1, 'value':75.0},
                 {'candidate':self.c2, 'value': 50.0}],
                 'election': self.election}
     self.assertEquals(final_result, expected)
    def done(self, form_list, **kwargs):
        cleaned_data = self.get_all_cleaned_data()
        results = []
        has_parent = True
        element_selector = cleaned_data['element_selector']
        elections = self.get_proposal_class()().get_elections(element_selector)
        for election in elections:
            calculator = Calculator(election, cleaned_data['positions'], cleaned_data['proposals'])
            results.append(calculator.get_result())

        is_creator_of_this_proposals_filter = Q(organization__proposals__in=cleaned_data['proposals'])
        is_liker_of_this_proposals = Q(organization__likes__proposal__in=cleaned_data['proposals'])
        organization_templates = OrganizationTemplate.objects.filter(is_creator_of_this_proposals_filter|is_liker_of_this_proposals).distinct()
        return render(self.request, 'medianaranja2/resultado.html', {
            'results': results,
            'organizations': organization_templates
        })