예제 #1
0
    def test_update_results(self):
        with test_database(test_db, [Race, Candidate]):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')
            race = Race.get(Race.race_id == '38529-OR')

            candidate_4848 = Candidate.get(Candidate.candidate_id == '4848-OR')
            candidate_4642 = Candidate.get(Candidate.candidate_id == '4642-OR')
            candidate_4979 = Candidate.get(Candidate.candidate_id == '4979-OR')

            self.assertEqual(race.precincts_reporting, 1970)
            self.assertEqual(race.precincts_total, 2288)
            self.assertTrue(race.is_reporting())

            self.assertEqual(candidate_4848.vote_count, 150000)
            self.assertEqual(candidate_4642.vote_count, 200000)
            self.assertEqual(candidate_4979.vote_count, 250000)
            self.assertEqual(race.count_votes(), 600000)

            self.assertEqual(candidate_4848.vote_percent(), Decimal('25.0')) 
            self.assertAlmostEqual(candidate_4642.vote_percent(), Decimal('33.333'), 3) 
            self.assertAlmostEqual(candidate_4979.vote_percent(), Decimal('41.667'), 3) 

            # Results does not call races
            self.assertFalse(candidate_4848.ap_winner)
            self.assertFalse(candidate_4642.ap_winner)
            self.assertFalse(candidate_4979.ap_winner)
예제 #2
0
    def test_update_results(self):
        with test_database(test_db, [Race, Candidate]):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')
            race = Race.get(Race.race_id == '38529-OR')

            candidate_4848 = Candidate.get(Candidate.candidate_id == '4848-OR')
            candidate_4642 = Candidate.get(Candidate.candidate_id == '4642-OR')
            candidate_4979 = Candidate.get(Candidate.candidate_id == '4979-OR')

            self.assertEqual(race.precincts_reporting, 1970)
            self.assertEqual(race.precincts_total, 2288)
            self.assertTrue(race.is_reporting())

            self.assertEqual(candidate_4848.vote_count, 150000)
            self.assertEqual(candidate_4642.vote_count, 200000)
            self.assertEqual(candidate_4979.vote_count, 250000)
            self.assertEqual(race.count_votes(), 600000)

            self.assertEqual(candidate_4848.vote_percent(), Decimal('25.0'))
            self.assertAlmostEqual(candidate_4642.vote_percent(),
                                   Decimal('33.333'), 3)
            self.assertAlmostEqual(candidate_4979.vote_percent(),
                                   Decimal('41.667'), 3)

            # Results does not call races
            self.assertFalse(candidate_4848.ap_winner)
            self.assertFalse(candidate_4642.ap_winner)
            self.assertFalse(candidate_4979.ap_winner)
예제 #3
0
    def test_count_votes(self):
        with test_database(test_db, [Race, Candidate], create_tables=True):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')

            race = Race.get(Race.race_id == '38529-OR')
            self.assertTrue(race.is_reporting())
            self.assertEqual(race.count_votes(), 600000)
예제 #4
0
    def test_top_choices(self):
        with test_database(test_db, [Race, Candidate], create_tables=True):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')

            race = Race.get(Race.race_id == '27456-MO')
            top_choices = race.top_choices()
            self.assertEqual(top_choices[0].last_name, 'Yes')
            self.assertEqual(top_choices[1].last_name, 'No')
예제 #5
0
    def test_top_candidates(self):
        with test_database(test_db, [Race, Candidate], create_tables=True):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')

            race = Race.get(Race.race_id == '38529-OR')
            top_candidates = race.top_candidates()
            self.assertEqual(top_candidates[0].party, 'Dem')
            self.assertEqual(top_candidates[1].party, 'GOP')
예제 #6
0
    def test_precincts_reporting_percent(self):
        with test_database(test_db, [Race, Candidate], create_tables=True):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')

            race = Race.select().get()
            race.precincts_reporting = 700
            race.precincts_total = 1100
            race.save()

            self.assertAlmostEqual(race.precincts_reporting_percent(), Decimal('63.636'), 3)
예제 #7
0
    def test_vote_percent(self):
        with test_database(test_db, [Race, Candidate], create_tables=True):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')

            candidate_4848 = Candidate.get(Candidate.candidate_id == '4848-OR')
            candidate_4642 = Candidate.get(Candidate.candidate_id == '4642-OR')
            candidate_4979 = Candidate.get(Candidate.candidate_id == '4979-OR')

            self.assertEqual(candidate_4848.vote_percent(), Decimal('25.0')) 
            self.assertAlmostEqual(candidate_4642.vote_percent(), Decimal('33.333'), 3) 
            self.assertAlmostEqual(candidate_4979.vote_percent(), Decimal('41.667'), 3) 
예제 #8
0
def playback(folder_name='2014-10-06', update_interval=60):
    """
    Begin playback of recorded AP data.
    """
    from fabfile import data

    folder = 'data/recording/%s' % folder_name

    timestamps = sorted(os.listdir(folder))
    initial = '%s/%s' % (folder, timestamps[0])

    for timestamp in timestamps[1:]:
        print '==== LOADING NEXT DATA (%s) ====' % timestamp
        path = '%s/%s' % (folder, timestamp)
        data.load_updates('%s/update.json' % path)
        data.load_calls('%s/calls.json' % path)
        sleep(int(update_interval))

    print '==== PLAYBACK COMPLETE ===='
예제 #9
0
    def test_update_times(self):
        with test_database(test_db, [Race, Candidate]):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')

            race = Race.get(Race.race_id == '38529-OR')
            first_last_updated = race.last_updated

            data.load_updates('data/tests/update.json')
            race = Race.get(Race.race_id == '38529-OR')
            last_updated = race.last_updated
            self.assertEqual(first_last_updated, last_updated)

            data.load_updates('data/tests/update-votes.json')
            race = Race.get(Race.race_id == '38529-OR')
            last_updated = race.last_updated
            self.assertEqual(first_last_updated, last_updated)

            data.load_updates('data/tests/update-precincts.json')
            race = Race.get(Race.race_id == '38529-OR')
            last_updated = race.last_updated
            self.assertEqual(first_last_updated, last_updated)
예제 #10
0
    def test_update_times(self):
        with test_database(test_db, [Race, Candidate]):
            data.load_races('data/tests/init_races.json')
            data.load_candidates('data/tests/init_candidates.json')
            data.load_updates('data/tests/update.json')

            race = Race.get(Race.race_id == '38529-OR')
            first_last_updated = race.last_updated

            data.load_updates('data/tests/update.json')
            race = Race.get(Race.race_id == '38529-OR')
            last_updated = race.last_updated
            self.assertEqual(first_last_updated, last_updated)

            data.load_updates('data/tests/update-votes.json')
            race = Race.get(Race.race_id == '38529-OR')
            last_updated = race.last_updated
            self.assertEqual(first_last_updated, last_updated)

            data.load_updates('data/tests/update-precincts.json')
            race = Race.get(Race.race_id == '38529-OR')
            last_updated = race.last_updated
            self.assertEqual(first_last_updated, last_updated)