From 10266bdef98961448b58b37b64b9e86e13d28424 Mon Sep 17 00:00:00 2001 From: erjemin Date: Sun, 4 Dec 2022 01:28:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D0=B0:=20"=D0=A0=D0=B5=D0=B9=D1=82=D0=B8=D0=BD=D0=B3=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D0=B5=D0=B9"=20--=20minor?= =?UTF-8?q?=20(=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D1=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oknardia/web/report2.py | 61 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/oknardia/web/report2.py b/oknardia/web/report2.py index 72f74e9..bf73f32 100644 --- a/oknardia/web/report2.py +++ b/oknardia/web/report2.py @@ -28,31 +28,30 @@ def profiles_rating(request: HttpRequest) -> HttpResponse: """ time_start = time() template = "rating/profiles_rating.html" - to_template = {} - q = PVCprofiles.objects.order_by("fProfileRating", "fProfileSeals", "fProfileHeatTransf", - "fProfileSoundproofing", "iProfileHeight", "iProfileRabbet", - "iProfileGlazingThickness", "iProfileThickness", "iProfileCameras") + q_pvc_profiles = PVCprofiles.objects.order_by("fProfileRating", "fProfileSeals", "fProfileHeatTransf", + "fProfileSoundproofing", "iProfileHeight", "iProfileRabbet", + "iProfileGlazingThickness", "iProfileThickness", "iProfileCameras") table = [] keys = [RANK_PVCP_HEAT_TRANSFER_NAME, RANK_PVCP_SOUNDPROOFING_NAME, RANK_PVCP_SEALS_NAME, RANK_PVCP_HEIGHT_NAME, RANK_PVCP_G_THICKNESS_NAME, RANK_PVCP_THICKNESS_NAME, RANK_PVCP_RABBET_NAME, RANK_PVCP_CAMERAS_NUM_NAME, RANK_PVCP_CAMERAS_POPULARITY_NAME] - to_template.update({'KEYS': keys}) - for i in q: + to_template = {'KEYS': keys} + for profile in q_pvc_profiles: try: - received_json = json.loads(i.sProfileDescription) + received_json = json.loads(profile.sProfileDescription) except json.decoder.JSONDecodeError: continue if KEY_RATING in received_json: rating_real = True - r = received_json[KEY_RATING] - color = int(255 - normalize(i.fProfileRating) * 255) + rating = received_json[KEY_RATING] + color = int(255 - normalize(profile.fProfileRating) * 255) rating_color = f"{color},255,{color}" rating_color2 = False elif KEY_RATING_VIRTUAL in received_json: rating_real = False - r = received_json[KEY_RATING_VIRTUAL] - color = int(255 - normalize(i.fProfileRating) * 64) - color2 = int(220 - normalize(i.fProfileRating) * 127) + rating = received_json[KEY_RATING_VIRTUAL] + color = int(255 - normalize(profile.fProfileRating) * 64) + color2 = int(220 - normalize(profile.fProfileRating) * 127) rating_color = f"{color},{color},{color}" rating_color2 = f"{color2},{color2},{color2}" else: @@ -61,29 +60,29 @@ def profiles_rating(request: HttpRequest) -> HttpResponse: # keys = sorted(r.keys()) # to_template.update({'KEYS': keys}) k_arr = [] - for j in keys: - if rating_real: # Это рейтинг на профили, по которым есть ценник (зелененький) - clr = int(255 - r[j] * 255) - k_arr.append({"COLOR": f"{clr},255,{clr}", "VAL": r[j], "KEY": j}) - else: # Это "потенциальный" рейтинг, без реальных ценовых предложений (серенький) - clr = int(255 - r[j] * 64) - k_arr.append({"COLOR": f"{clr},{clr},{clr}", "VAL": r[j], "KEY": j}) + for key in keys: + if rating_real: + # Это рейтинг на профили, по которым есть ценник (зелененький) + color = int(255 - rating[key] * 255) + k_arr.append({"COLOR": f"{color},255,{color}", "VAL": rating[key], "KEY": key}) + else: + # Это "виртуальный" рейтинг, без реальных ценовых предложений (серенький) + color = int(255 - rating[key] * 64) + k_arr.append({"COLOR": f"{color},{color},{color}", "VAL": rating[key], "KEY": key}) table.append({ - "ID": i.id, + "ID": profile.id, "R_REAL": rating_real, - "BRAND": i.sProfileManufacturer, - "BRAND_URL": pytils.translit.slugify(i.sProfileManufacturer), - "NAME": i.sProfileName, - "NAME_URL": pytils.translit.slugify(i.sProfileName), + "BRAND": profile.sProfileManufacturer, + "BRAND_URL": pytils.translit.slugify(profile.sProfileManufacturer), + "NAME": profile.sProfileName, + "NAME_URL": pytils.translit.slugify(profile.sProfileName), "K_ARR": k_arr, - "RATING_STAR": get_rating_set_for_stars(i.fProfileRating), - "RATING_N": i.fProfileRating, + "RATING_STAR": get_rating_set_for_stars(profile.fProfileRating), + "RATING_N": profile.fProfileRating, "RATING_COLOR": rating_color, "RATING_COLOR2": rating_color2 }) - # получаем данные для фрейма ценовых предложений - to_template.update({'TABLE': table}) - to_template.update({'ticks': float(time() - time_start)}) - response = render(request, template, to_template) - return response + to_template.update({'TABLE': table, + 'ticks': float(time() - time_start)}) + return render(request, template, to_template)