def runPipeline(self): for user_uuid in get_recommender_uuid_list(): recommend_trips = [] # Converting to a list because otherwise, when we prepare feature # vectors, the iterator is all used up trips_to_improve = list(self.get_trips_to_improve(user_uuid)) alternatives = atm.get_alternative_for_trips(trips_to_improve) trips_with_alts = self.prepare_feature_vectors(trips_to_improve, alternatives) logging.debug("trips_with_alts = %s" % trips_with_alts) user_model = self.get_selected_user_utility_model(user_uuid, trips_to_improve) if user_model: for trip_to_improve in trips_to_improve: logging.debug("user_model = %s" % user_model) original_trip = trip_to_improve if (len(list(atm.get_alternative_for_trip(original_trip))) == 0): logging.debug("trip = %s has no alternatives, skipping..." % original_trip._id) continue; logging.debug("considering for recommendation, original trip = %s " % original_trip.__dict__) recommended_trip = user_model.predict(original_trip) logging.debug("recommended_trip = %s" % recommended_trip) if original_trip != recommended_trip: logging.debug("recommended trip is different, setting it") original_trip.mark_recommended(recommended_trip) recommend_trips.append(recommended_trip) else: logging.debug("Original Trip is best") else: logging.debug("No user model found, skipping")
def testQueryAndSaveAlternatives(self): trip_iter = self.pipeline.get_trips_for_alternatives(self.testUUID) self.assertTrue(hasattr(trip_iter, '__iter__')) trip_list = list(trip_iter) for trip in trip_list: query.obtain_alternatives(trip.trip_id, self.testUUID) firstElement = trip_list[0] self.assertTrue(isinstance(firstElement, ecwt.E_Mission_Trip)) for trip in trip_list: alt_it = pipeline_module.get_alternative_for_trip(trip) alt_list = list(alt_it)
def testQueryAndSaveAlternatives(self): trip_iter = self.pipeline.get_trips_for_alternatives(self.testUUID) self.assertTrue(hasattr(trip_iter, '__iter__')) trip_list = list(trip_iter) for trip in trip_list: query.obtain_alternatives(trip.trip_id, self.testUUID) firstElement = trip_list[0] self.assertTrue(isinstance(firstElement, ecwt.E_Mission_Trip)) for trip in trip_list: alt_it = pipeline_module.get_alternative_for_trip(trip) alt_list = list(alt_it)
def testQueryAndSaveAlternatives(self): trip_iter = self.pipeline.get_trips_for_alternatives(self.testUUID) self.assertTrue(hasattr(trip_iter, "__iter__")) trip_list = list(trip_iter) for trip in trip_list: query.obtain_alternatives(trip.trip_id, self.testUUID) firstElement = trip_list[0] self.assertTrue(isinstance(firstElement, ecwt.E_Mission_Trip)) for trip in trip_list: alt_it = pipeline_module.get_alternative_for_trip(trip) alt_list = list(alt_it) # TODO: Figure out why we sometimes have three alternatives and sometimes have 4. # We are querying for 4 alternatives in the code, so why don't we have all four self.assertTrue(len(alt_list) == 3 or len(alt_list) == 4)
def runPipeline(self): for user_uuid in get_recommender_uuid_list(): recommend_trips = [] # Converting to a list because otherwise, when we prepare feature # vectors, the iterator is all used up trips_to_improve = list(self.get_trips_to_improve(user_uuid)) alternatives = atm.get_alternative_for_trips(trips_to_improve) trips_with_alts = self.prepare_feature_vectors( trips_to_improve, alternatives) logging.debug("trips_with_alts = %s" % trips_with_alts) user_model = self.get_selected_user_utility_model( user_uuid, trips_to_improve) if user_model: for trip_to_improve in trips_to_improve: logging.debug("user_model = %s" % user_model) original_trip = trip_to_improve if (len(list(atm.get_alternative_for_trip(original_trip))) == 0): logging.debug( "trip = %s has no alternatives, skipping..." % original_trip._id) continue logging.debug( "considering for recommendation, original trip = %s " % original_trip.__dict__) recommended_trip = user_model.predict(original_trip) logging.debug("recommended_trip = %s" % recommended_trip) if original_trip != recommended_trip: logging.debug( "recommended trip is different, setting it") original_trip.mark_recommended(recommended_trip) recommend_trips.append(recommended_trip) else: logging.debug("Original Trip is best") else: logging.debug("No user model found, skipping")