def user(request): if request.method == "GET": return HttpResponse("nothing") if request.method == "POST": login_request = json.loads(request.body) try: login_user = User.objects.get(login_id=login_request["id"]) if login_user.password == login_request["password"]: jsonData = OrderedDict() jsonData["u_id"] = login_user.u_id return HttpResponse(json.dumps(jsonData, ensure_ascii=False, indent="\t"), content_type="application/json") else: return HttpResponse("user.post.fail:wrongPassword") except User.DoesNotExist: return HttpResponse("user.post.fail:notExists") if request.method == "PUT": signUp_request = json.loads(request.body) if User.objects.filter(login_id=signUp_request["id"]).exists(): return HttpResponse("user.put.fail:idExists") new_user = User(name=signUp_request["name"], birth_date=signUp_request["birthDate"], login_id=signUp_request["id"], password=signUp_request["password"]) new_user.save() return HttpResponse("user.put.success") if request.method == "DELETE": return HttpResponse("nothing")
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data name = data['name'] email = data['email'] passwd = data['passwd'] person = User(name=name, email=email, passwd=passwd) person.save() return HttpResponseRedirect('/movie/') else: form = RegisterForm() return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
def fileToDB(request): print("===========================") print("----- fileToDB start -----") print(datetime.datetime.now()) count = 1 data = recommender.data_for_db("C:\\Users\\isaac\\Desktop\\project\\server") # 디비에 저장 print("transfer user data") print(datetime.datetime.now()) for i in range(1, data.user_num + 1): if i % 100 == 0: print("doing : " + str(i)) newUser = User(u_id=i, login_id="test"+str(i), password="******"+str(i)) newUser.unknown_rate = data.user_profile[i][recommender._unknown] newUser.action_rate = data.user_profile[i][recommender._action] newUser.adventure_rate = data.user_profile[i][recommender._adventure] newUser.animation_rate = data.user_profile[i][recommender._animation] newUser.children_rate = data.user_profile[i][recommender._children] newUser.comedy_rate = data.user_profile[i][recommender._comedy] newUser.crime_rate = data.user_profile[i][recommender._crime] newUser.documentary_rate = data.user_profile[i][recommender._documentary] newUser.drama_rate = data.user_profile[i][recommender._drama] newUser.fantasy_rate = data.user_profile[i][recommender._fantasy] newUser.film_noir_rate = data.user_profile[i][recommender._film_noir] newUser.horror_rate = data.user_profile[i][recommender._horror] newUser.musical_rate = data.user_profile[i][recommender._musical] newUser.mystery_rate = data.user_profile[i][recommender._mystery] newUser.romance_rate = data.user_profile[i][recommender._romance] newUser.sci_fi_rate = data.user_profile[i][recommender._sci_fi] newUser.thriller_rate = data.user_profile[i][recommender._thriller] newUser.war_rate = data.user_profile[i][recommender._war] newUser.western_rate = data.user_profile[i][recommender._western] newUser.unknown_num = data.user_profile[i][19 + recommender._unknown] newUser.action_num = data.user_profile[i][19 + recommender._action] newUser.adventure_num = data.user_profile[i][19 + recommender._adventure] newUser.animation_num = data.user_profile[i][19 + recommender._animation] newUser.children_num = data.user_profile[i][19 + recommender._children] newUser.comedy_num = data.user_profile[i][19 + recommender._comedy] newUser.crime_num = data.user_profile[i][19 + recommender._crime] newUser.documentary = data.user_profile[i][19 + recommender._documentary] newUser.drama_num = data.user_profile[i][19 + recommender._drama] newUser.fantasy_num = data.user_profile[i][19 + recommender._fantasy] newUser.film_noir_num = data.user_profile[i][19 + recommender._film_noir] newUser.horror_num = data.user_profile[i][19 + recommender._horror] newUser.musical_num = data.user_profile[i][19 + recommender._musical] newUser.mystery_num = data.user_profile[i][19 + recommender._mystery] newUser.romance_num = data.user_profile[i][19 + recommender._romance] newUser.sci_fi_num = data.user_profile[i][19 + recommender._sci_fi] newUser.thriller_num = data.user_profile[i][19 + recommender._thriller] newUser.war_num = data.user_profile[i][19 + recommender._war] newUser.western_num = data.user_profile[i][19 + recommender._western] newUser.save() print("transfer movie data") print(datetime.datetime.now()) for i in range(1, data.movie_num + 1): if i % 100 == 0: print("doing : " + str(i)) newMovie = Movie(m_id=i, title=data.movies.movie_list[i].title) newMovie.is_unknown = True if data.movie_profile[recommender._unknown][i] == 1 else False newMovie.is_action = True if data.movie_profile[recommender._action][i] == 1 else False newMovie.is_adventure = True if data.movie_profile[recommender._adventure][i] == 1 else False newMovie.is_animation = True if data.movie_profile[recommender._animation][i] == 1 else False newMovie.is_children = True if data.movie_profile[recommender._children][i] == 1 else False newMovie.is_comedy = True if data.movie_profile[recommender._comedy][i] == 1 else False newMovie.is_crime = True if data.movie_profile[recommender._crime][i] == 1 else False newMovie.is_documentary = True if data.movie_profile[recommender._documentary][i] == 1 else False newMovie.is_drama = True if data.movie_profile[recommender._drama][i] == 1 else False newMovie.is_fantasy = True if data.movie_profile[recommender._fantasy][i] == 1 else False newMovie.is_film_noir = True if data.movie_profile[recommender._film_noir][i] == 1 else False newMovie.is_horror = True if data.movie_profile[recommender._horror][i] == 1 else False newMovie.is_musical = True if data.movie_profile[recommender._musical][i] == 1 else False newMovie.is_mystery = True if data.movie_profile[recommender._mystery][i] == 1 else False newMovie.is_romance = True if data.movie_profile[recommender._romance][i] == 1 else False newMovie.is_sci_fi = True if data.movie_profile[recommender._sci_fi][i] == 1 else False newMovie.is_thriller = True if data.movie_profile[recommender._thriller][i] == 1 else False newMovie.is_war = True if data.movie_profile[recommender._war][i] == 1 else False newMovie.is_western = True if data.movie_profile[recommender._western][i] == 1 else False newMovie.save() print("transfer rating data") print(datetime.datetime.now()) for i in range(1, data.user_num + 1): if i % 20 == 0: print("doing user : "******"----- fileToDB end -----") print(datetime.datetime.now()) print("===========================") print("===============================") print("----- prepareSVDpp start -----") print(datetime.datetime.now()) global td temp = recommender.total_data() print("----- prepareSVDpp end -----") print(datetime.datetime.now()) print("===============================") print("==========================") print("----- doSVDpp start -----") print(datetime.datetime.now()) temp.start_svd() temp.start_prediction() temp.start_recommendation() td = temp print("----- doSVDpp end -----") print(datetime.datetime.now()) print("==========================") return HttpResponse("fileToDB, doSVDpp가 완료되었습니다.")