示例#1
0
文件: ap.py 项目: nprapps/elections14
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 ===='
示例#2
0
    def test_update_calls(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_calls('data/tests/calls.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.assertTrue(race.is_called())
            self.assertTrue(race.ap_called)
            self.assertEqual(race.ap_called_time, datetime(2014, 9, 25, 17, 8, 14))
            self.assertEqual(race.get_called_time(), datetime(2014, 9, 25, 17, 8, 14))

            self.assertFalse(candidate_4848.ap_winner)
            self.assertFalse(candidate_4642.ap_winner)
            self.assertTrue(candidate_4979.ap_winner)