''' DS2000 Spring 2023 Sample code from class - recommendation system Building a content-based filtering system Designing a class... TVShow (contains user info too) Attributes: * title * length of episode (mins) * number of seasons * indv rating of the show (1-5) * user's age (years) Methods: * __init__ * others???? Algorithm: * Have a bunch of TVShow objects =====> NEXT WEEK * Ask the user (Laney) for info about a show they 've watched =====> TODAY * Recommend shows with similar episode lengths, season, user age, and with high rating bit.ly/sec3_recs ''' MIN_RATING = 6 POP_SPLIT = 5 NEWNESS_DIFF = 2 LENGTH_DIFF = 10 class TVShow: def __init__(self, title, length = 30, popularity = 1, rating = 1, newness = 1): self.title = title self.length = length self.popularity = popularity self.newness = newness self.rating = rating def recommend(self, other): if self.rating >= MIN_RATING: if other.popularity < POP_SPLIT and self.popularity < POP_SPLIT or \ other.popularity >= POP_SPLIT and self.popularity >= POP_SPLIT: if abs(other.newness - self.newness) <= NEWNESS_DIFF: if abs(other.length - self.length) <= LENGTH_DIFF: return True return False def __str__(self): return self.title + " with rating " + str(self.rating) def euclidean(self, other): distance = (self.length - other.length) ** 2 + \ (self.popularity - other.popularity) ** 2 + \ (self.newness - other.newness) ** 2 return distance ** .5