def add_project(request): current_project= Project(project_title=request.POST['project-title'], project_url=request.POST['pcori-url'], project_description= request.POST['project-description'], posted_by= request.user) current_project.save() current_project.analyze_and_save() return redirect('/pccr/researcher')
def match(pid): # django query to find all patients who have one or more entities matching # researcher project profile m = mc(db="pccr") tags = Project.get_tags(pid) res = m.find({"tags": {"$in": tags}}, collection="patient_tags_new") user_tag_set = {} for r in res: try: user_tag_set[r["username"]]["tags"].append(r["tags"]) except: user_tag_set[r["username"]] = {} user_tag_set[r["username"]]["tags"] = [r["tags"]] user_tag_set[r["username"]]["uid"] = r["uid"] """ try: user_tag_set[str(r['username'])].append(r[tags]) except: user_tag_set[str(r['username'])]= [] """ user_score_set = {} tags = frozenset(tags) for user in user_tag_set: user_tags = user_tag_set[user]["tags"] for user_tag in user_tags: try: user_score_set[user] += len(set(user_tag).intersection(tags)) except: user_score_set[user] = len(set(user_tag).intersection(tags)) sorted_user_scores = sorted(user_score_set.iteritems(), key=operator.itemgetter(1), reverse=True) return [(user_tag_set[uc[0]]["uid"], uc[0], uc[1]) for uc in sorted_user_scores][:6]
def project(request,pid): current_project= Project.objects.get(id= pid) inputs = {'title':current_project.project_title, 'description':current_project.project_description, 'researchers':current_project.posted_by, 'show_nav':1, 'tags':Project.get_tags(pid) } if request.user: inputs.update({'user_signed':True, 'userid':request.user.username,}) if current_project.posted_by==request.user: inputs.update({'current_researcher_is_project_owner':True,}) inputs.update(csrf(request)) #inputs['matches']=[{'name':name, 'topic':'Marzipan'} for name in ['Brad Ruderman','Annie Chiang','Danny Daniels',]] inputs['matches']=[{'uid':user_score[0], 'name':user_score[1], 'network':'MeMed', 'topic':user_score[2],} for user_score in Match.match(pid)] return render_to_response('pccrportal/study.html',inputs,)