Страница: "Рейтинги профилей" -- minor (переименование переменных)

This commit is contained in:
2022-12-04 01:28:27 +03:00
parent efd2a20b27
commit 10266bdef9

View File

@@ -28,31 +28,30 @@ def profiles_rating(request: HttpRequest) -> HttpResponse:
""" """
time_start = time() time_start = time()
template = "rating/profiles_rating.html" template = "rating/profiles_rating.html"
to_template = {} q_pvc_profiles = PVCprofiles.objects.order_by("fProfileRating", "fProfileSeals", "fProfileHeatTransf",
q = PVCprofiles.objects.order_by("fProfileRating", "fProfileSeals", "fProfileHeatTransf", "fProfileSoundproofing", "iProfileHeight", "iProfileRabbet",
"fProfileSoundproofing", "iProfileHeight", "iProfileRabbet", "iProfileGlazingThickness", "iProfileThickness", "iProfileCameras")
"iProfileGlazingThickness", "iProfileThickness", "iProfileCameras")
table = [] table = []
keys = [RANK_PVCP_HEAT_TRANSFER_NAME, RANK_PVCP_SOUNDPROOFING_NAME, RANK_PVCP_SEALS_NAME, 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_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] RANK_PVCP_RABBET_NAME, RANK_PVCP_CAMERAS_NUM_NAME, RANK_PVCP_CAMERAS_POPULARITY_NAME]
to_template.update({'KEYS': keys}) to_template = {'KEYS': keys}
for i in q: for profile in q_pvc_profiles:
try: try:
received_json = json.loads(i.sProfileDescription) received_json = json.loads(profile.sProfileDescription)
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
continue continue
if KEY_RATING in received_json: if KEY_RATING in received_json:
rating_real = True rating_real = True
r = received_json[KEY_RATING] rating = received_json[KEY_RATING]
color = int(255 - normalize(i.fProfileRating) * 255) color = int(255 - normalize(profile.fProfileRating) * 255)
rating_color = f"{color},255,{color}" rating_color = f"{color},255,{color}"
rating_color2 = False rating_color2 = False
elif KEY_RATING_VIRTUAL in received_json: elif KEY_RATING_VIRTUAL in received_json:
rating_real = False rating_real = False
r = received_json[KEY_RATING_VIRTUAL] rating = received_json[KEY_RATING_VIRTUAL]
color = int(255 - normalize(i.fProfileRating) * 64) color = int(255 - normalize(profile.fProfileRating) * 64)
color2 = int(220 - normalize(i.fProfileRating) * 127) color2 = int(220 - normalize(profile.fProfileRating) * 127)
rating_color = f"{color},{color},{color}" rating_color = f"{color},{color},{color}"
rating_color2 = f"{color2},{color2},{color2}" rating_color2 = f"{color2},{color2},{color2}"
else: else:
@@ -61,29 +60,29 @@ def profiles_rating(request: HttpRequest) -> HttpResponse:
# keys = sorted(r.keys()) # keys = sorted(r.keys())
# to_template.update({'KEYS': keys}) # to_template.update({'KEYS': keys})
k_arr = [] k_arr = []
for j in keys: for key in keys:
if rating_real: # Это рейтинг на профили, по которым есть ценник (зелененький) if rating_real:
clr = int(255 - r[j] * 255) # Это рейтинг на профили, по которым есть ценник (зелененький)
k_arr.append({"COLOR": f"{clr},255,{clr}", "VAL": r[j], "KEY": j}) color = int(255 - rating[key] * 255)
else: # Это "потенциальный" рейтинг, без реальных ценовых предложений (серенький) k_arr.append({"COLOR": f"{color},255,{color}", "VAL": rating[key], "KEY": key})
clr = int(255 - r[j] * 64) else:
k_arr.append({"COLOR": f"{clr},{clr},{clr}", "VAL": r[j], "KEY": j}) # Это "виртуальный" рейтинг, без реальных ценовых предложений (серенький)
color = int(255 - rating[key] * 64)
k_arr.append({"COLOR": f"{color},{color},{color}", "VAL": rating[key], "KEY": key})
table.append({ table.append({
"ID": i.id, "ID": profile.id,
"R_REAL": rating_real, "R_REAL": rating_real,
"BRAND": i.sProfileManufacturer, "BRAND": profile.sProfileManufacturer,
"BRAND_URL": pytils.translit.slugify(i.sProfileManufacturer), "BRAND_URL": pytils.translit.slugify(profile.sProfileManufacturer),
"NAME": i.sProfileName, "NAME": profile.sProfileName,
"NAME_URL": pytils.translit.slugify(i.sProfileName), "NAME_URL": pytils.translit.slugify(profile.sProfileName),
"K_ARR": k_arr, "K_ARR": k_arr,
"RATING_STAR": get_rating_set_for_stars(i.fProfileRating), "RATING_STAR": get_rating_set_for_stars(profile.fProfileRating),
"RATING_N": i.fProfileRating, "RATING_N": profile.fProfileRating,
"RATING_COLOR": rating_color, "RATING_COLOR": rating_color,
"RATING_COLOR2": rating_color2 "RATING_COLOR2": rating_color2
}) })
# получаем данные для фрейма ценовых предложений # получаем данные для фрейма ценовых предложений
to_template.update({'TABLE': table}) to_template.update({'TABLE': table,
to_template.update({'ticks': float(time() - time_start)}) 'ticks': float(time() - time_start)})
response = render(request, template, to_template) return render(request, template, to_template)
return response