def post(self):
   self.response.out.write('METODO POST<br/>')
   opcao = self.request.get('opcao')
   self.response.out.write('Opcao:'+opcao+'<br>')
   if opcao == 'criar':
     name = self.request.get('name')
     player = Player(name=name)
     player.put()
   if opcao == 'listar':
     all_players = Player.all()
     for player in all_players:
       self.response.out.write('Player name:'+player.name+'<br>')
 
   ##################Joao Pedro#################################
   if opcao == 'upload':
     name = self.request.get('name')
     university = self.request.get('university')
     course= self.request.get('course')
     image = self.request.get('image')
     
     picture = Picture()
     
     """picture.image = db.Blob(image)
     picture.name = name
     picture.name_university = university
     picture.name_course = course"""
     
     #self.response.out.write('name:'+name+'<br>')
     #self.response.out.write('university:'+university+'<br>')
     #self.response.out.write('course:'+course+'<br>')
     picture.put()
   ######################################################
   
   self.redirect('/')
Exemple #2
0
def upload(name, img_url, tags):
    picture = Picture()
    picture.name = name
    picture.img_url = img_url
    picture.tags = tags
    picture.save()
    return picture
Exemple #3
0
 def insert_list_picture(self, mimg):
     try:
         for m in mimg:
             picture = Picture(img=m.get("data"), datatype=m.get("type"))
             session.add(picture)
         session.commit()
         return picture.id
     except Exception as ex:
         session.rollback()
         logger.warnning("插入picture表发生异常" + str(ex))
Exemple #4
0
    def _compute(self, img: np.ndarray) -> Picture:
        kps = []
        for x in range(0, img.shape[1], self.step_size):
            for y in range(0, img.shape[0], self.step_size):
                for s in self.scales:
                    kp = cv2.KeyPoint(x, y, s)
                    kps.append(kp)
        kps, des = self._sift.compute(img, kps)

        return Picture(img.shape[:2], kps, des)
Exemple #5
0
def once_load_all():
    for str_tag in available_tags:
        for i in range(1, 21):
            snum = str(i)
            while len(snum) < 5:
                snum = '0' + snum

            picture = Picture()
            picture.name = snum + '-' + str_tag
            picture.img_url = '/' + snum + '-' + str_tag + '.jpg'
            picture.tags = [str_tag]
            picture.likes = random.randint(0, 666)

            picture.save()
Exemple #6
0
def change_likes_of_pic(pic_id, num=1):
    pic_list = Picture.objects(id=pic_id)
    if (len(pic_list) <= 0):
        current_app.logger.info('change_likes_of_pic find id=' + str(pic_id) +
                                ' cannot find the pic')
        return

    pic = pic_list[0]
    current_app.logger.info('change_likes_of_pic find id=' + str(pic_id) +
                            ' to change it num by ' + str(num) +
                            ' the original is :' + str(pic.likes))
    pic.likes = pic.likes + num
    pic.save()
  def post(self):
    try:
      name = self.request.get('name')
      university = self.request.get('university')
      course= self.request.get('course')
      
      upload = self.get_uploads()[0]
      
      picture = Picture()
      picture.image = upload.key()
      picture.name = name
      picture.name_university = university
      picture.name_course = course
      
      db.put(picture)

      self.redirect('/view_photo/%s' % upload.key())
      #self.response.out.write('TUDO FUNCIONOU OK!!!!')

    except:
      #self.redirect('/upload_failure.html')
      self.response.out.write('FALHOUUUUU FUDEUUUU!')
Exemple #8
0
def randomly_get_pics(prefered_tags=[], num=20):
    pictures = []

    if len(prefered_tags) == 0:
        pictures = Picture.objects().aggregate(*[
            {
                '$sample': {
                    'size': num
                }
            },
        ])
    else:
        count_sum = 20
        for i in range(0, len(prefered_tags)):
            if i != len(prefered_tags) - 1:
                cnt = random.randint(0, count_sum)
            else:
                cnt = count_sum
            if cnt > 0:
                pictures.extend(Picture.objects().aggregate(*[
                    {
                        '$match': {
                            'tags': {
                                '$eq': prefered_tags[i]
                            }
                        }
                    },
                    {
                        '$sample': {
                            'size': cnt
                        }
                    },
                ]))
                count_sum -= cnt

    random.shuffle(pictures)
    return pictures
Exemple #9
0
def recommend_likes(user, num=5):
    rec_dict = select_random_user_and_likes(user)
    rec_dict = fill_dict_with_others(rec_dict)

    item_sim = calculate_similar_items(rec_dict)

    result = get_recommended_items(rec_dict, item_sim, user.username)
    result = result[:5]

    no_0_result = []
    for (r, pid) in result:
        if r > 0:
            no_0_result.append(pid)

    pics = Picture.objects(id__in=no_0_result)

    return pics
  def get(self):
    query = Player.all()
    players = query.fetch(limit=None)
    
    query = Picture.all()
    pictures = query.fetch(limit=None)
    
    
    upload_picture = blobstore.create_upload_url('/upload_picture')
    
      
    template_values = {
        'players': players,
        'pictures': pictures,
        'upload_picture': upload_picture,
    }
    

    
    template = jinja_environment.get_template('index.html')
    self.response.out.write(template.render(template_values))