def create_rating(user_id, content_id, rating, timestamp): rating = Rating(user_id=user_id, movie_id=content_id, rating=decimal.Decimal(rating), rating_timestamp=datetime.datetime.fromtimestamp(float(timestamp))) rating.save() return rating
def log(request): if request.method == 'POST': date = request.GET.get('date', datetime.datetime.now()) date = str(date).split(':')[0] user_id = request.POST['user_id'] user_id = User.objects.filter(name__exact=user_id).values(*['id']) user_id = pd.DataFrame.from_records(user_id, columns=['id']).values[0][0] item_id = request.POST['item_id'] rating = request.POST['rating'] type = request.POST['type'] type = str(type).split('_')[0] print(user_id, item_id, rating, date, type) l = Rating(user_id=user_id, item_id=str(item_id), rating=rating, rating_timestamp=date, type=type) l.save() else: HttpResponse('log only works with POST') return HttpResponse('ok')
def save_ratings(ratings, user_id, type): print("saving ratings for {}".format(user_id)) for content_id, rating in ratings.items(): if rating > 0: Rating(user_id=user_id, food_id=int(content_id), rating=rating, rating_timestamp=datetime.datetime.now(), type=type).save()
def save_ratings(ratings, user_id, type): print("saving ratings for {}".format(user_id)) i = 0 for content_id, rating in ratings.items(): if rating > 0: Rating(user_id=user_id, movie_id=str(content_id), rating=rating, rating_timestamp=datetime.datetime.now(), type=type).save() print('{} {}'.format(user_id, str(content_id))) i += 1 if i == 100: print('.', end="") i = 0
def save_ratings(ratings, userid, type, conn=data_helper.connect_to_db()): print("saving ratings for {}".format(userid)) i = 0 for content_id, rating in ratings.items(): Rating(user_id=userid, movie_id=str(content_id), rating=rating, rating_timestamp=datetime.datetime.now(), type=type).save() print('{} {}'.format(userid, str(content_id))) #conn.cursor().execute(sql) i += 1 if i == 100: print('.', end="") i = 0
def split_data(self, num_folds=5): users = Rating.objects().values('user_id').distinct() kf = KFold(n_split=num_folds) self.folds = kf.split(users)
def training_data(self): if self.folds is None: return Rating.objects().all() else: return Rating.objects().filter(user_id__in=self.folds)