| | import os |
| | import sys |
| | import sqlite3 |
| | import tkinter as tk |
| | from tkinter import ttk |
| | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg |
| | import matplotlib.pyplot as plt |
| | import matplotlib |
| |
|
| | SUPPORTED_FILE_TYPES = ['.sh', '.bat', '.ps1', '.cs', '.c', '.cpp', '.h', '.cmake', '.py', '.git', '.sql', '.csv', '.sqlite', '.lsl', '.html', '.xml', '.rtf'] |
| |
|
| | |
| | matplotlib.rcParams.update({'font.size': plt.rcParams['font.size'] * 0.8}) |
| |
|
| | class DatenVisualizer(tk.Tk): |
| | def __init__(self, db_pfad): |
| | super().__init__() |
| |
|
| | self.title("Daten Visualizer") |
| | self.geometry("1200x720") |
| |
|
| | |
| | self.chars_window = tk.Toplevel(self) |
| | self.chars_window.title("Anzahl der Zeichen") |
| | self.chars_window.geometry("480x360") |
| | self.chars_window.protocol("WM_DELETE_WINDOW", self.close_chars_window) |
| |
|
| | |
| | self.chars_frame = ttk.Frame(self.chars_window) |
| | self.chars_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True) |
| |
|
| | |
| | self.anzeigen_anzahl_zeichen(db_pfad) |
| |
|
| | |
| | self.quality_window = tk.Toplevel(self) |
| | self.quality_window.title("Qualität des Datensatzes") |
| | self.quality_window.geometry("480x360") |
| | self.quality_window.protocol("WM_DELETE_WINDOW", self.close_quality_window) |
| |
|
| | |
| | self.quality_frame = ttk.Frame(self.quality_window) |
| | self.quality_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True) |
| |
|
| | |
| | self.anzeigen_qualität(db_pfad) |
| |
|
| | |
| | self.tree_frame = ttk.Frame(self) |
| | self.tree_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True) |
| |
|
| | |
| | self.tree = ttk.Treeview(self.tree_frame) |
| | self.tree["columns"] = ("dateipfad", "anzahl_zeilen", "anzahl_zeichen", "long_text_mode", "dimensionalität") |
| | self.tree.heading("#0", text="ID") |
| | self.tree.heading("dateipfad", text="Dateipfad") |
| | self.tree.heading("anzahl_zeilen", text="Anzahl Zeilen") |
| | self.tree.heading("anzahl_zeichen", text="Anzahl Zeichen") |
| | self.tree.heading("long_text_mode", text="Long Text Mode") |
| | self.tree.heading("dimensionalität", text="Dimensionalität") |
| |
|
| | self.tree_scroll = ttk.Scrollbar(self.tree_frame, orient=tk.VERTICAL, command=self.tree.yview) |
| | self.tree.configure(yscrollcommand=self.tree_scroll.set) |
| |
|
| | self.tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) |
| | self.tree_scroll.pack(side=tk.RIGHT, fill=tk.Y) |
| |
|
| | self.lade_daten_aus_db(db_pfad) |
| |
|
| | def lade_daten_aus_db(self, db_pfad): |
| | try: |
| | with sqlite3.connect(db_pfad) as conn: |
| | cursor = conn.cursor() |
| | cursor.execute("SELECT * FROM dateiparameter") |
| | daten = cursor.fetchall() |
| | |
| | for row in daten: |
| | self.tree.insert("", tk.END, values=row) |
| | |
| | except sqlite3.Error as e: |
| | print(f"SQLite Fehler: {e}") |
| | except Exception as e: |
| | print(f"Allgemeiner Fehler: {e}") |
| |
|
| | def anzeigen_anzahl_zeichen(self, db_pfad): |
| | try: |
| | with sqlite3.connect(db_pfad) as conn: |
| | cursor = conn.cursor() |
| | cursor.execute("SELECT dateipfad, anzahl_zeichen FROM dateiparameter") |
| | daten = cursor.fetchall() |
| |
|
| | |
| | plot_figure_chars = plt.Figure(figsize=(6, 4.5), dpi=100) |
| | plot_ax_chars = plot_figure_chars.add_subplot(111) |
| | plot_ax_chars.bar([row[0] for row in daten], [int(row[1]) for row in daten], color='orange') |
| | plot_ax_chars.set_xlabel("Dateipfad") |
| | plot_ax_chars.set_ylabel("Anzahl Zeichen") |
| |
|
| | plot_canvas_chars = FigureCanvasTkAgg(plot_figure_chars, master=self.chars_frame) |
| | plot_canvas_chars.get_tk_widget().pack() |
| |
|
| | except sqlite3.Error as e: |
| | print(f"SQLite Fehler: {e}") |
| | except Exception as e: |
| | print(f"Allgemeiner Fehler: {e}") |
| |
|
| | def anzeigen_qualität(self, db_pfad): |
| | try: |
| | with sqlite3.connect(db_pfad) as conn: |
| | cursor = conn.cursor() |
| | cursor.execute("SELECT * FROM dateiparameter") |
| | daten = cursor.fetchall() |
| |
|
| | |
| | anzahl_dateien = len(daten) |
| | durchschnittliche_anzahl_zeichen = sum(int(row[3]) for row in daten) / anzahl_dateien if anzahl_dateien > 0 else 0 |
| | durchschnittliche_anzahl_zeilen = sum(int(row[2]) for row in daten) / anzahl_dateien if anzahl_dateien > 0 else 0 |
| |
|
| | |
| | plot_figure_quality = plt.Figure(figsize=(6, 4.5), dpi=100) |
| | plot_ax_quality = plot_figure_quality.add_subplot(111) |
| | plot_ax_quality.bar(["Durchschnittliche Anzahl Zeichen", "Durchschnittliche Anzahl Zeilen"], [durchschnittliche_anzahl_zeichen, durchschnittliche_anzahl_zeilen], color=['skyblue', 'lightgreen']) |
| | plot_ax_quality.set_xlabel("Metrik") |
| | plot_ax_quality.set_ylabel("Durchschnittswerte") |
| |
|
| | plot_canvas_quality = FigureCanvasTkAgg(plot_figure_quality, master=self.quality_frame) |
| | plot_canvas_quality.get_tk_widget().pack() |
| |
|
| | except sqlite3.Error as e: |
| | print(f"SQLite Fehler: {e}") |
| | except Exception as e: |
| | print(f"Allgemeiner Fehler: {e}") |
| |
|
| | def close_chars_window(self): |
| | self.chars_window.destroy() |
| |
|
| | def close_quality_window(self): |
| | self.quality_window.destroy() |
| |
|
| | def main(db_pfad): |
| | try: |
| | daten_visualizer = DatenVisualizer(db_pfad) |
| | daten_visualizer.mainloop() |
| |
|
| | except Exception as e: |
| | print(f"Fehler beim Hauptprogramm: {e}") |
| |
|
| | if __name__ == "__main__": |
| | |
| | if len(sys.argv) > 1: |
| | db_pfad = sys.argv[1] |
| | else: |
| | print("Bitte geben Sie den Pfad zur SQLite-Datenbank als Argument an.") |
| | sys.exit(1) |
| |
|
| | main(db_pfad) |
| |
|