''' 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 = 3 LENGTH_DIFF = 10 AGE_DIFF = 5 class TVShow: def __init__(self, title, length = 30, seasons = 1, age = 21, rating = 1): self.title = title self.length = length self.seasons = seasons self.age = age self.rating = rating def recommend(self, other): if self.rating >= MIN_RATING: if abs(self.length - other.length) <= LENGTH_DIFF: if abs(self.age - other.age) <= AGE_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.seasons - other.seasons) ** 2 + \ (self.age - other.age) ** 2 return distance ** .5