Advertisement
mikhailemv

Untitled

Jun 13th, 2023
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.26 KB | None | 0 0
  1. # VIEWS.PY
  2. # 201 - 231 строчка кода
  3. # Просто вставить
  4.  
  5.     # Создание словаря
  6.     incomes_dict_inc = dict(zip(labels_incomes, data_incomes))
  7.  
  8.     # Сортировка словаря по значениям в порядке убывания
  9.     sorted_incomes = sorted(incomes_dict_inc.items(), key=lambda x: x[1], reverse=True)
  10.  
  11.     # Получение трех самых дорогих категорий
  12.     top_incomes = sorted_incomes[:3]
  13.  
  14.     # Вычисление суммы остальных расходов
  15.     other_incomes_sum = sum(value for _, value in sorted_incomes[3:])
  16.  
  17.     # Создание массивов для записи результатов
  18.     top_categories_incomes = []
  19.     top_amounts_incomes = []
  20.  
  21.     # Запись трех самых дорогих категорий в массивы
  22.     for category, amount in top_incomes:
  23.         top_categories_incomes.append(category)
  24.         top_amounts_incomes.append(amount)
  25.  
  26.     # Добавление 'Другое' в массивы
  27.     if len(sorted_incomes) > 3:
  28.         top_categories_incomes.append('Другое')
  29.         top_amounts_incomes.append(other_incomes_sum)
  30.  
  31.     if len(sorted_incomes) == 4 and top_amounts_incomes[3] == 0:
  32.         top_amounts_incomes.pop()
  33.         top_categories_incomes.pop()
  34.  
  35. # VIEWS.PY
  36. # 143 - 173
  37.  
  38.     # Создание словаря
  39.     expenses_dict = dict(zip(labels_expenses, data_expenses))
  40.  
  41.     # Сортировка словаря по значениям в порядке убывания
  42.     sorted_expenses = sorted(expenses_dict.items(), key=lambda x: x[1], reverse=True)
  43.  
  44.     # Получение трех самых дорогих категорий
  45.     top_expenses = sorted_expenses[:3]
  46.  
  47.     # Вычисление суммы остальных расходов
  48.     other_expenses_sum = sum(value for _, value in sorted_expenses[3:])
  49.  
  50.     # Создание массивов для записи результатов
  51.     top_categories = []
  52.     top_amounts = []
  53.  
  54.     # Запись трех самых дорогих категорий в массивы
  55.     for category, amount in top_expenses:
  56.         top_categories.append(category)
  57.         top_amounts.append(amount)
  58.  
  59.     # Добавление 'Другое' в массивы
  60.     if len(sorted_expenses) > 3:
  61.         top_categories.append('Другое')
  62.         top_amounts.append(other_expenses_sum)
  63.  
  64.     if len(sorted_expenses) == 4 and top_amounts[3] == 0:
  65.         top_amounts.pop()
  66.         top_categories.pop()
  67.  
  68. # Замените context
  69. # 237 - 251
  70.  
  71.     context = {
  72.         'accounts': accounts,
  73.         'combined_data_expenses': zip(top_categories, top_amounts),
  74.         'combined_data_incomes': zip(top_categories_incomes, top_amounts_incomes),
  75.         'full_expenses_sum': full_expenses_sum,
  76.         'full_incomes_sum': full_incomes_sum,
  77.         'daily_operations': daily_operations,
  78.         'regular_transactions': regular_transactions,
  79.         'sorted_operations': sorted_operations,
  80.         'top_amounts': top_amounts,
  81.         'top_categories': top_categories,
  82.         'top_amounts_incomes': top_amounts_incomes,
  83.         'top_categories_incomes': top_categories_incomes,
  84.         'form': form,
  85.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement