Skip to content

Commit 2796b30

Browse files
Update
1 parent f483ab6 commit 2796b30

File tree

1 file changed

+75
-22
lines changed

1 file changed

+75
-22
lines changed

main.py

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,68 @@ def browse_directory():
155155
daemon=True).start()
156156

157157

158+
# =========================
159+
# Функция для вывода прочих библиотек
160+
# =========================
161+
162+
def show_others(imports_count, total_imports, output_text):
163+
# Сортируем библиотеки по количеству
164+
sorted_imports = sorted(imports_count.items(), key=lambda x: x[1], reverse=True)
165+
166+
# Ограничиваем вывод до 200 библиотек
167+
top_imports = sorted_imports[:200]
168+
others_count = sum(count for lib, count in sorted_imports[200:])
169+
170+
# Очищаем вывод
171+
output_text.delete(1.0, "end")
172+
173+
# Выводим "Прочее" для остальных
174+
if others_count > 0:
175+
output_text.insert("insert", f"Прочее:\n")
176+
for lib, count in sorted_imports[200:]:
177+
percentage = (count / total_imports) * 100
178+
output_text.insert("insert", f"{lib}: {count} ({percentage:.2f}%)\n")
179+
else:
180+
output_text.insert("insert", "Прочее: Нет дополнительных библиотек.\n")
158181

159182

160183
# =========================
161184
# Функции для вывода
162185
# =========================
163186

187+
def show_main_libs(imports_count, total_imports, output_text):
188+
output_text.delete(1.0, "end")
189+
output_text.insert("insert", "Топ 100 популярных библиотек:\n")
190+
191+
sorted_imports = sorted(imports_count.items(), key=lambda x: x[1], reverse=True)
192+
top_imports = sorted_imports[:100]
193+
194+
for lib, count in top_imports:
195+
percentage = (count / total_imports) * 100
196+
output_text.insert("insert", f"{lib}: {count} ({percentage:.2f}%)\n")
197+
198+
199+
def print_import_statistics(imports_count, total_imports, output_text):
200+
output_text.delete(1.0, "end")
201+
output_text.insert("insert", f"Общее количество импортов: {total_imports}\n")
202+
203+
# Сортируем библиотеки по количеству
204+
sorted_imports = sorted(imports_count.items(), key=lambda x: x[1], reverse=True)
205+
206+
# Ограничиваем вывод до 100 библиотек
207+
top_imports = sorted_imports[:100]
208+
others_count = sum(count for lib, count in sorted_imports[100:])
209+
210+
# Выводим топ 100 библиотек
211+
for lib, count in top_imports:
212+
percentage = (count / total_imports) * 100
213+
output_text.insert("insert", f"{lib}: {count} ({percentage:.2f}%)\n")
214+
215+
# Выводим "Прочее" для остальных
216+
if others_count > 0:
217+
output_text.insert("insert", f"Прочее: {others_count} ({(others_count / total_imports) * 100:.2f}%)\n")
218+
219+
164220
def plot_import_statistics(imports_count, total_imports, plot_type="both"):
165221
# Сортируем библиотеки по убыванию использования
166222
sorted_imports = sorted(imports_count.items(), key=lambda x: x[1], reverse=True)
@@ -202,25 +258,6 @@ def plot_import_statistics(imports_count, total_imports, plot_type="both"):
202258
canvas.get_tk_widget().pack(side="top", fill="both", expand=True)
203259

204260

205-
def print_import_statistics(imports_count, total_imports, output_text):
206-
output_text.delete(1.0, "end")
207-
output_text.insert("insert", f"Общее количество импортов: {total_imports}\n")
208-
209-
# Сортируем библиотеки по количеству
210-
sorted_imports = sorted(imports_count.items(), key=lambda x: x[1], reverse=True)
211-
212-
# Ограничиваем вывод до 80 библиотек
213-
top_imports = sorted_imports[:80]
214-
others_count = sum(count for lib, count in sorted_imports[80:])
215-
216-
# Выводим топ 80 библиотек
217-
for lib, count in top_imports:
218-
percentage = (count / total_imports) * 100
219-
output_text.insert("insert", f"{lib}: {count} ({percentage:.2f}%)\n")
220-
221-
# Выводим "Прочее" для остальных
222-
if others_count > 0:
223-
output_text.insert("insert", f"Прочее: {others_count} ({(others_count / total_imports) * 100:.2f}%)\n")
224261

225262

226263

@@ -252,6 +289,9 @@ def update_gui():
252289
# GUI
253290
# =========================
254291

292+
293+
294+
255295
window = Tk()
256296
window.title("Статистика импортов в проектах")
257297
window.geometry("1200x800")
@@ -273,13 +313,25 @@ def update_gui():
273313
output_text.tag_configure("cyan", foreground="cyan")
274314
output_text.tag_configure("red", foreground="red")
275315

276-
# Кнопки для переключения между графиками
277-
btn_bar_chart = Button(window, text="Гистограмма", command=lambda: plot_import_statistics(imports_count, total_imports, "bar"))
316+
# Первый ряд: графики
317+
chart_frame = Frame(window)
318+
chart_frame.pack(pady=5)
319+
320+
btn_bar_chart = Button(chart_frame, text="Гистограмма", command=lambda: plot_import_statistics(imports_count, total_imports, "bar"))
278321
btn_bar_chart.pack(side="left", padx=10)
279322

280-
btn_pie_chart = Button(window, text="Круговая диаграмма", command=lambda: plot_import_statistics(imports_count, total_imports, "pie"))
323+
btn_pie_chart = Button(chart_frame, text="Круговая диаграмма", command=lambda: plot_import_statistics(imports_count, total_imports, "pie"))
281324
btn_pie_chart.pack(side="left", padx=10)
282325

326+
# Второй ряд: основные и прочие библиотеки
327+
lib_frame = Frame(window)
328+
lib_frame.pack(pady=5)
329+
330+
btn_main_libs = Button(lib_frame, text="Показать основные библиотеки", command=lambda: show_main_libs(imports_count, total_imports, output_text))
331+
btn_main_libs.pack(side="left", padx=10)
332+
333+
btn_others = Button(lib_frame, text="Показать прочие библиотеки", command=lambda: show_others(imports_count, total_imports, output_text))
334+
btn_others.pack(side="left", padx=10)
283335

284336
# Добавляем контекстное меню для копирования
285337
context_menu = Menu(window, tearoff=0)
@@ -300,3 +352,4 @@ def show_context_menu(event):
300352
window.after(100, update_gui)
301353

302354
window.mainloop()
355+

0 commit comments

Comments
 (0)