def build_status(): """Get the mappings and refresh the mappings cache. Then process all new feeds using :func:`caravel.feed.new_feed_iter` instead of using the change notification. """ Mapping.set_db(settings.db) Feed.set_db(settings.db) Route.set_db(settings.db) RouteStop.set_db(settings.db) Vehicle.set_db(settings.db) Stop.set_db(settings.db) # Mappings cache in the application server. mappings = {} # Remove all damaged feed documents; these cannot be processed. docs = feed.remove_damaged( settings.db, settings.db.view( "feed/new" ) ) print( "Cleanup", docs ) # If the change notification is a mapping... # Or. Do all new mappings. counts= mapping.refresh_mapping_cache(mappings, Mapping.view('mapping/new', descending=True)) print( "Mapping", dict(counts) ) # If the change notification is a feed... docs= status.remove_old(settings.db) print( "Status Removal", docs ) start= datetime.datetime.now() counts= feed.transform_new( mappings, feed.new_feed_iter(), status.track_arrival, status.track_location ) end= datetime.datetime.now() print( "Transform {0} reports in {1}".format( dict(counts), end-start ) ) # Not every time we receive a feed; only once per day. docs= feed.remove_old( settings.db ) print( "Feed Removal", docs )
def test_should_remove_damaged( self ): self.assertEqual( 1, len( list( db.view("feed/all")) ) ) remove_damaged( db, db.view("feed/all") ) self.assertEqual( 0, len( list( db.view("feed/all")) ) )