Пример #1
0
    def update(self, request, recipe_id, api_key=None, rating=None):
        """ handle PUT request to update the data set or to rate the
          corresponding action recipe.
         
          'http://roboearth.informatik.uni-stuttgart.de/api/0.1/recipe/<recipe_id>/<identifier>/<rating>',

          update data set:

          'recipe_id' : the complete UID of the corresponding data set
          
          Content-Type: application/json which contains:

          'description' : human readable description of the environment

          'recipe' : action recipe (OWL)
          
          'api_key' : authenticates the user

          submit rating:

          'api_key' : identify user

          'rating' : rating [0..10]
      """

        #chek if ranking or data set was submitted
        if api_key and recipe_id and rating:
            # update rating
            api_key = api_keys.objects.get(key__exact=api_key)
            if not User.objects.get(
                    username__exact=api_key.username).is_active:
                return rc.BAD_REQUEST

            ar = transaction.get(query=recipe_id, format="json", exact=True)
            if not ar:
                return rc.NOT_HERE

            try:
                hbase_op.update_rating(
                    "Recipes", recipe_id,
                    roboearth.calc_rating(float(ar[0]['rating']),
                                          float(rating)))
            except Exception, e:
                return rc.BAD_REQUEST

            return rc.ALL_OK
Пример #2
0
   def update(self, request, recipe_id, api_key=None, rating=None):
      """ handle PUT request to update the data set or to rate the
          corresponding action recipe.
         
          'http://roboearth.informatik.uni-stuttgart.de/api/0.1/recipe/<recipe_id>/<identifier>/<rating>',

          update data set:

          'recipe_id' : the complete UID of the corresponding data set
          
          Content-Type: application/json which contains:

          'description' : human readable description of the environment

          'recipe' : action recipe (OWL)
          
          'api_key' : authenticates the user

          submit rating:

          'api_key' : identify user

          'rating' : rating [0..10]
      """

      #chek if ranking or data set was submitted
      if api_key and recipe_id and rating:
         # update rating
         api_key = api_keys.objects.get(key__exact=api_key)
         if not User.objects.get(username__exact=api_key.username).is_active:
            return rc.BAD_REQUEST

         ar = transaction.get(query=recipe_id, format="json", exact=True)
         if not ar: 
            return rc.NOT_HERE

         try:
            hbase_op.update_rating("Recipes", recipe_id, roboearth.calc_rating(float(ar[0]['rating']), float(rating)))
         except Exception, e:
            return rc.BAD_REQUEST

         return rc.ALL_OK
Пример #3
0
   def update(self, request, object_id, api_key=None, data=None):
      """ handle PUT request to update the data set or to rate the
          corresponding object description
          'http://roboearth.informatik.uni-stuttgart.de/api/0.1/object/<object_id>/<api_key>/<rating>',

          update data set:

          object_id: the complete UID of the corresponding data set

          Content-Type: application/json which contains:

          description: human readable description of the object

          object_description: object description (OWL)

          api_key: authenticates the user

          submit rating:

          api_key: authenticates the user

          data: rating [0..10]
      """

      #chek if ranking or data set was submitted
      if api_key and object_id and data:
         # update rating
         api_key = api_keys.objects.get(key__exact=api_key)
         if not User.objects.get(username__exact=api_key.username).is_active:
            return rc.BAD_REQUEST

         obj = transaction.get(query=object_id, format="json", exact=True)
         if not obj: 
            return rc.NOT_HERE

         try:
            hbase_op.update_rating("Objects", object_id, roboearth.calc_rating(float(obj[0]['rating']), float(data)))
         except Exception, e:
            return rc.BAD_REQUEST

         return rc.ALL_OK