def store_in_db(self, user_id): model_query = {'user_id': user_id, 'type': 'user'} model_object = { 'user_id': user_id, 'cost': self.cost, 'time': self.time, 'mode': self.mode, 'updated_at': datetime.now(), 'type': 'user' } get_utility_model_db().update(model_query, model_object, upsert=True)
def find_from_db(self, user_id, modified): if modified: db_model = get_utility_model_db().find_one({ 'user_id': user_id, 'type': 'recommender' }) else: db_model = get_utility_model_db().find_one({ 'user_id': user_id, 'type': 'user' }) return db_model
def store_in_db(self, user_id): print "storing E_Missions model" model_query = {'user_id': user_id, 'type': 'recommender'} model_object = { 'cost': self.cost, 'user_id': user_id, 'time': self.time, 'mode': self.mode, 'emissions': self.emissions, 'updated_at': datetime.now(), 'type': 'recommender' } get_utility_model_db().update(model_query, model_object, upsert=True)
class UserUtilityModel: # TO DO: # - receive augmented trips as imput, don't call out to receive them # - store/retrive model from DB # - define basic data structure # - define get_utility_model in get_database # return user-specific weights for a given user based on logistic regression on # their past trips and potential alternatives def __init__(user_id, augmented_trips): features = [extractFeatures(trip) for trip in augmented_trips] targets = [] regression = lm.LogisticRegression() regression.fit(features, targets) weights = (0, 0, 0) return weights # update existing model using existing trips # for now, just create a new model and return it def update(augmented_trips): pass def self.find_from_db(user_id): return get_utility_model_db().find_one({'user_id': user_id})
def find_from_db(self, user_id, modified): if modified: db_model = get_utility_model_db().find_one({'user_id': user_id, 'type':'recommender'}) else: db_model = get_utility_model_db().find_one({'user_id': user_id, 'type':'user'}) return db_model
def store_in_db(self, user_id): model_query = {'user_id': user_id, 'type':'user'} model_object = {'user_id': user_id, 'cost': self.cost, 'time': self.time, 'mode': self.mode, 'updated_at': datetime.now(), 'type':'user'} get_utility_model_db().update(model_query, model_object, upsert = True)
def store_in_db(self, user_id): logging.debug("storing E_Missions model") model_query = {'user_id': user_id, 'type':'recommender'} model_object = {'cost': self.cost, 'user_id':user_id, 'time': self.time, 'mode': self.mode, 'emissions': self.emissions, 'updated_at': datetime.now(),'type':'recommender'} get_utility_model_db().update(model_query, model_object, upsert = True)