def test_filter_query(self): with self.assertRaises(ValueError): cf = CollaborativeFilter(db=self.conn) with Query(self.conn) as q: q.add(self.conn.rating(student=self.student2, section=self.section3, rating=4)) cf = CollaborativeFilter(db=self.conn) self.assertIsInstance(cf.getData(), type([]))
def add_filters(self): # attrs = set(x for x in dir(self.db.rating) if not x.startswith("_")) # attrs -= set(["metadata", "section_id", "student", "section", "student_id"]) # return {attr: CollaborativeFilter(db=self.db, metric=attr) for attr in attrs} with Query(self.db)as q: num = max(1, int(q.query(self.db.student).count() / 5)) return {'rating': CollaborativeFilter(db=self.db, metric='rating', numRecommendations=num)}
def setUp(self): self.data = { 'Lisa Rose': { 'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5, 'Just My Luck': 3.0, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5, 'The Night Listener': 3.0 }, 'Gene Seymour': { 'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5, 'Just My Luck': 1.5, 'Superman Returns': 5.0, 'The Night Listener': 3.0, 'You, Me and Dupree': 3.5 }, 'Michael Phillips': { 'Lady in the Water': 2.5, 'Snakes on a Plane': 3.0, 'Superman Returns': 3.5, 'The Night Listener': 4.0 }, 'Claudia Puig': { 'Snakes on a Plane': 3.5, 'Just My Luck': 3.0, 'The Night Listener': 4.5, 'Superman Returns': 4.0, 'You, Me and Dupree': 2.5 }, 'Mick LaSalle': { 'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0, 'Just My Luck': 2.0, 'Superman Returns': 3.0, 'The Night Listener': 3.0, 'You, Me and Dupree': 2.0 }, 'Jack Matthews': { 'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0, 'The Night Listener': 3.0, 'Superman Returns': 5.0, 'You, Me and Dupree': 3.5 }, 'Toby': { 'Snakes on a Plane': 4.5, 'You, Me and Dupree': 1.0, 'Superman Returns': 4.0 } } self.instance = 'Gene Seymour' self.feature = 'Snakes on a Plane' self.testInstance = {'Gene Seymour': {'Snakes on a Plane': 10}} self.recTester = {'Gene Seymour': ['Snakes on a Plane']} self.fltr = CollaborativeFilter(self.data, 1) self.test2Instance = {'Gene Seymour': {'Snakes on a Plane': 20}}