[Bf-extensions-cvs] [6a81558b] blender-v2.93-release: BlenderKit: fetch user's ratings from server

Vilem Duha noreply at git.blender.org
Mon Aug 9 08:42:15 CEST 2021


Commit: 6a81558b63d579a58de4df39def083bb34defca7
Author: Vilem Duha
Date:   Fri May 21 14:44:11 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rBA6a81558b63d579a58de4df39def083bb34defca7

BlenderKit: fetch user's ratings from server

by now enabled only for validators, to test performance. Also shows to validator which assets were not yet rated by them.

===================================================================

M	blenderkit/ratings.py
M	blenderkit/ratings_utils.py
M	blenderkit/search.py
M	blenderkit/ui.py

===================================================================

diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index 2a3ac76b..10d815ba 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -58,6 +58,9 @@ def upload_review_thread(url, reviews, headers):
     #     print('reviews upload failed: %s' % str(e))
 
 
+
+
+
 def upload_rating(asset):
     user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
     api_key = user_preferences.api_key
diff --git a/blenderkit/ratings_utils.py b/blenderkit/ratings_utils.py
index 26acb84c..fe2643e1 100644
--- a/blenderkit/ratings_utils.py
+++ b/blenderkit/ratings_utils.py
@@ -68,6 +68,12 @@ def send_rating_to_thread_work_hours(url, ratings, headers):
     thread.start()
 
 
+def store_rating_local_empty(asset_id):
+    context = bpy.context
+    context.window_manager['asset ratings'] = context.window_manager.get('asset ratings', {})
+    context.window_manager['asset ratings'][asset_id] = context.window_manager['asset ratings'].get(asset_id, {})
+
+
 def store_rating_local(asset_id, type='quality', value=0):
     context = bpy.context
     context.window_manager['asset ratings'] = context.window_manager.get('asset ratings', {})
@@ -75,6 +81,36 @@ def store_rating_local(asset_id, type='quality', value=0):
     context.window_manager['asset ratings'][asset_id][type] = value
 
 
+def get_rating(asset_id, headers):
+    '''
+    Retrieve ratings from BlenderKit server. Can be run from a thread
+    Parameters
+    ----------
+    asset_id
+    headers
+
+    Returns
+    -------
+    ratings - dict of type:value ratings
+    '''
+    url = paths.get_api_url() + 'assets/' + asset_id + '/rating/'
+    params = {}
+    r = rerequests.get(url, params=params, verify=True, headers=headers)
+    print(r.text)
+    rj = r.json()
+    ratings = {}
+    # store ratings - send them to task queue
+    for r in rj['results']:
+        ratings[r['ratingType']] = r['score']
+        tasks_queue.add_task((store_rating_local,(asset_id, r['ratingType'], r['score'])))
+        # store_rating_local(asset_id, type = r['ratingType'], value = r['score'])
+
+    if len(rj['results'])==0:
+        # store empty ratings too, so that server isn't checked repeatedly
+        tasks_queue.add_task((store_rating_local_empty,(asset_id,)))
+    return ratings
+
+
 def get_rating_local(asset_id):
     context = bpy.context
     context.window_manager['asset ratings'] = context.window_manager.get('asset ratings', {})
@@ -246,61 +282,67 @@ class RatingsProperties():
 
     high_rating_warning = "This is a high rating, please be sure to give such rating only to amazing assets"
 
+    possible_wh_values = [0,.5,1,2,3,4,5,6,8,10,15,20,30,50,100,150,200,250]
+    items_models = [('0', '0', ''),
+                    ('.5', '0.5', ''),
+                    ('1', '1', ''),
+                    ('2', '2', ''),
+                    ('3', '3', ''),
+                    ('4', '4', ''),
+                    ('5', '5', ''),
+                    ('6', '6', ''),
+                    ('8', '8', ''),
+                    ('10', '10', ''),
+                    ('15', '15', ''),
+                    ('20', '20', ''),
+                    ('30', '30', high_rating_warning),
+                    ('50', '50', high_rating_warning),
+                    ('100', '100', high_rating_warning),
+                    ('150', '150', high_rating_warning),
+                    ('200', '200', high_rating_warning),
+                    ('250', '250', high_rating_warning),
+                    ]
     rating_work_hours_ui: EnumProperty(name="Work Hours",
                                        description="How many hours did this work take?",
-                                       items=[('0', '0', ''),
-                                              ('.5', '0.5', ''),
-                                              ('1', '1', ''),
-                                              ('2', '2', ''),
-                                              ('3', '3', ''),
-                                              ('4', '4', ''),
-                                              ('5', '5', ''),
-                                              ('6', '6', ''),
-                                              ('8', '8', ''),
-                                              ('10', '10', ''),
-                                              ('15', '15', ''),
-                                              ('20', '20', ''),
-                                              ('30', '30', high_rating_warning),
-                                              ('50', '50', high_rating_warning),
-                                              ('100', '100', high_rating_warning),
-                                              ('150', '150', high_rating_warning),
-                                              ('200', '200', high_rating_warning),
-                                              ('250', '250', high_rating_warning),
-                                              ],
+                                       items=items_models,
                                        default='0', update=update_ratings_work_hours_ui,
                                        options={'SKIP_SAVE'}
                                        )
-
+    possible_wh_values_1_5 = [0,.2, .5,1,2,3,4,5]
+
+    items_1_5 = [('0', '0', ''),
+                 ('.2', '0.2', ''),
+                 ('.5', '0.5', ''),
+                 ('1', '1', ''),
+                 ('2', '2', ''),
+                 ('3', '3', ''),
+                 ('4', '4', ''),
+                 ('5', '5', '')
+                 ]
     rating_work_hours_ui_1_5: EnumProperty(name="Work Hours",
                                            description="How many hours did this work take?",
-                                           items=[('0', '0', ''),
-                                                  ('.2', '0.2', ''),
-                                                  ('.5', '0.5', ''),
-                                                  ('1', '1', ''),
-                                                  ('2', '2', ''),
-                                                  ('3', '3', ''),
-                                                  ('4', '4', ''),
-                                                  ('5', '5', '')
-                                                  ],
+                                           items=items_1_5,
                                            default='0',
                                            update=update_ratings_work_hours_ui_1_5,
                                            options={'SKIP_SAVE'}
                                            )
-
+    possible_wh_values_1_10 = [0,1,2,3,4,5,6,7,8,9,10]
+
+    items_1_10= [('0', '0', ''),
+       ('1', '1', ''),
+       ('2', '2', ''),
+       ('3', '3', ''),
+       ('4', '4', ''),
+       ('5', '5', ''),
+       ('6', '6', ''),
+       ('7', '7', ''),
+       ('8', '8', ''),
+       ('9', '9', ''),
+       ('10', '10', '')
+       ]
     rating_work_hours_ui_1_10: EnumProperty(name="Work Hours",
                                             description="How many hours did this work take?",
-                                            items=[('0', '0', ''),
-                                                   ('1', '1', ''),
-                                                   ('2', '2', ''),
-                                                   ('3', '3', ''),
-                                                   ('4', '4', ''),
-                                                   ('5', '5', ''),
-                                                   ('6', '6', ''),
-                                                   ('7', '7', ''),
-                                                   ('8', '8', ''),
-                                                   ('9', '9', ''),
-                                                   ('10', '10', '')
-                                                   ],
+                                            items= items_1_10,
                                             default='0',
                                             update=update_ratings_work_hours_ui_1_10,
                                             options={'SKIP_SAVE'}
@@ -313,8 +355,10 @@ class RatingsProperties():
             self.rating_quality = ratings['quality']
         if ratings and ratings.get('working_hours'):
             wh = int(ratings['working_hours'])
-            self.rating_work_hours_ui = str(wh)
-            if wh < 6:
-                self.rating_work_hours_ui_1_5 = str(int(ratings['working_hours']))
-            if wh < 11:
-                self.rating_work_hours_ui_1_10 = str(int(ratings['working_hours']))
+            whs = str(wh)
+            if wh in self.possible_wh_values:
+                self.rating_work_hours_ui = whs
+            if wh < 6 and wh in self.possible_wh_values_1_5:
+                self.rating_work_hours_ui_1_5 = whs
+            if wh < 11 and wh in self.possible_wh_values_1_10:
+                self.rating_work_hours_ui_1_10 = whs
diff --git a/blenderkit/search.py b/blenderkit/search.py
index 310d1138..0d3d73b0 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -17,7 +17,7 @@
 # ##### END GPL LICENSE BLOCK #####
 
 from blenderkit import paths, utils, categories, ui, colors, bkit_oauth, version_checker, tasks_queue, rerequests, \
-    resolutions, image_utils
+    resolutions, image_utils, ratings_utils
 
 import blenderkit
 from bpy.app.handlers import persistent
@@ -428,6 +428,7 @@ def search_timer():
 
             rdata = thread[0].result
             result_field = []
+
             ok, error = check_errors(rdata)
             if ok:
                 ui_props = bpy.context.scene.blenderkitUI
@@ -435,22 +436,18 @@ def search_timer():
                 if not ui_props.assetbar_on:
                     bpy.ops.object.run_assetbar_fix_context()
 
-
+                user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
+                api_key = user_preferences.api_key
+                headers = utils.get_headers(api_key)
 
                 for r in rdata['results']:
                     asset_data = parse_result(r)
                     if asset_data != None:
   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list