''' 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 LOW_POP = 5 LENGTH_SIM = 5 class TVShow: def __init__(self, title, length = 30, popularity = 1, rating = 1): self.title = title self.length = length self.popularity = popularity self.rating = rating def recommend(self, other): if self.rating >= MIN_RATING: if other.popularity <= LOW_POP and self.popularity <= LOW_POP or other.popularity > LOW_POP and self.popularity > LOW_POP: if abs(self.length - other.length) <= LENGTH_SIM: 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.rating - other.rating) ** 2 return distance ** .5