コード例 #1
0
ファイル: tfg_server.py プロジェクト: gualdras/tfg_server
def update_related_users(user1, image):
	images_used = ImageUsed.query(ImageUsed.image == image)
	for imgUsed in images_used:
		user2 = imgUsed.user
		r_user = RelatedUsers.query(RelatedUsers.user1.IN([user1, user2]),
		                            RelatedUsers.user2.IN([user1, user2])).get()
		if r_user is not None:
			r_user.relation += 1
		else:
			r_user = RelatedUsers(user1=user1, user2=user2, relation=1)
		r_user.put()
コード例 #2
0
def update_related_users(user1, image):
    images_used = ImageUsed.query(ImageUsed.image == image)
    for imgUsed in images_used:
        user2 = imgUsed.user
        r_user = RelatedUsers.query(RelatedUsers.user1.IN([user1, user2]),
                                    RelatedUsers.user2.IN([user1,
                                                           user2])).get()
        if r_user is not None:
            r_user.relation += 1
        else:
            r_user = RelatedUsers(user1=user1, user2=user2, relation=1)
        r_user.put()
コード例 #3
0
def get_images_collaborative(user, key_words, pictograms):
	def callback(images_used):
		return images_used.user

	recommended_images = pictograms
	images = Image.query(ndb.OR(Image.keyWords.keyWord.IN(key_words), Image.tags.tag.IN(key_words))).fetch(keys_only=True)

	if len(images) > 0:
		query = ImageUsed.query(ImageUsed.image.IN(images))
		if query.count() > 0:
			users = query.map(callback)
			query = RelatedUsers.query(ndb.OR(RelatedUsers.user1 == user, RelatedUsers.user2 == user)).filter(
										ndb.OR(RelatedUsers.user1.IN(users), RelatedUsers.user2.IN(users))).order(-
										RelatedUsers.relation)

			related = query.fetch(LIMIT_OF_RUSERS)
			for ru in related:
				if ru.relation > MINIMUM_RELATION:
					related_user = ru.get_related_user(user)
					images_used = ImageUsed.query(ImageUsed.user == related_user, ImageUsed.image.IN(images)).order(ImageUsed.count)
					for image_used in images_used:
						image = image_used.image
						if not (image.id() in recommended_images):
							recommended_images.append({tfg_server.BLOB: image.id(), tfg_server.LINK: image.get().link})
							break
					if len(recommended_images) > IMAGES_COLLABORATIVE:
						break

				else:
					break
	return recommended_images