Ejemplo n.º 1
0
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]
Ejemplo n.º 2
0
    def get_details(user):
        mongo_c= mc(db='pccr')
        res= mongo_c.find_one({'uid':user.id},collection='pccr_researcher')
        mongo_c.close_connection()
        try:
            #return {key: value for key, value in res[0].iteritems() if key!='_id' and key!='uid'}
            #return {key: value for key, value in res[0].iteritems()}
			return res[0]
        except:
            return {}
Ejemplo n.º 3
0
 def get_tags(project_id):
     mongo_c= mc(db='pccr')
     res= mongo_c.find_one({'pid':int(project_id)},
                             fields=('project_tags',),
                             collection='pccr_project')
     mongo_c.close_connection()
     try:
         return res[0]['project_tags']
     except Exception, e:
         print e
         return {}
Ejemplo n.º 4
0
def analyze_and_save(sender, **kwargs):
    try:
        res= opencalais.fetch_calais(sender.project_description)
        if res:
            mongo_c= mc(db='pccr')
            mongo_c.update({'pid':sender.id},
                        {'project_title':sender.project_title,
                         'project_description':sender.project_description,
                         'project_url':sender.project_url,
                         'project_tags':res,
                         'pid':sender.id,
                         }, collection='pccr_researcher')
            mongo_c.close_connection()
    except Exception, e:
        print e
        pass
Ejemplo n.º 5
0
 def analyze_and_save(self):
     try:
         res= opencalais.fetch_calais(self.project_description)
         if res:
             mongo_c= mc(db='pccr')
             mongo_c.update({'pid':self.id},
                         {'project_title':self.project_title,
                          'project_description':self.project_description,
                          'project_url':self.project_url,
                          'project_tags':res,
                          'posted_by':self.posted_by.id,
                          'pid':self.id,
                          }, collection='pccr_project')
             mongo_c.close_connection()
     except Exception, e:
         print e
         print 'EXCEPTION CAUGHT'
         pass
Ejemplo n.º 6
0
 def save(self, name, email, institution, user):
     mongo_c= mc(db='pccr')
     mongo_c.update({'uid':user.id},{'name':name, 'email':email, 'institution':institution,'uid':user.id}, collection='pccr_researcher')
     mongo_c.close_connection()