async def retrain(app): getLogger('root').info("Retraining...") loop = app.loop async with app.pool.acquire() as conn: accessor = DataAccessor(conn=conn, rating_scale=rating_scale) new_predictor = AlgorithmWrapper(loop, app.executor, algorithm_module.create_algorithm()) await new_predictor.fit(await accessor.trainset()) app.predictor = new_predictor getLogger('root').info('Retraining finished...')
async def setup(context, loop): context.executor = ThreadPoolExecutor() context.predictor = AlgorithmWrapper(loop, context.executor, algorithm_module.create_algorithm()) context.pool = await repeated_pool(loop, 5, 10) async with context.pool.acquire() as conn: accessor = DataAccessor(conn=conn, rating_scale=rating_scale) trainset = await accessor.trainset() await context.predictor.fit(trainset)
def setUp(self): connection = MagicMock(spec=Connection) cursor = MagicMock(spec=Cursor) connection.cursor.return_value = cursor cursor.__aenter__ = CoroutineMock(return_value=cursor) cursor.execute = CoroutineMock() self.accessor = DataAccessor(connection) self.connection = connection self.cursor = cursor
def setUp(self): connection = MagicMock(spec=Connection) cursor = MagicMock(spec=Cursor) connection.cursor.return_value = cursor cursor.__aenter__ = CoroutineMock(return_value=cursor) votes = [('user_a', 'item_a', 0), ('user_a', 'item_b', 1), ('user_b', 'item_a', 1), ('user_b', 'item_b', 1)] vote_scale = (0, 1) cursor.fetchall = CoroutineMock(return_value=votes) cursor.fetchone = CoroutineMock(return_value=vote_scale) cursor.execute = CoroutineMock() self.accessor = DataAccessor(connection) self.connection = connection self.cursor = cursor
def setUp(self): connection = MagicMock(spec=Connection) cursor = MagicMock(spec=Cursor) connection.cursor.return_value = cursor cursor.__aenter__ = CoroutineMock(return_value=cursor) cursor.fetchmany = CoroutineMock() self.accessor = DataAccessor(connection) self.connection = connection self.cursor = cursor self.posts = [{ 'id': 'test_post0' }, { 'id': 'test_post1' }, { 'id': 'test_post2' }, { 'id': 'test_post3' }]
async def generate_accessor(request): request['conn'] = await app.pool.acquire() request['accessor'] = DataAccessor(conn=request['conn'], rating_scale=rating_scale)
def create_accessor(context): return DataAccessor(conn=context)
async def generate_accessor(request): request['conn'] = await app.pool.acquire() request['accessor'] = DataAccessor(request['conn']) request['recommender'] = Recommender(request['accessor'], **rating_config)