From ac7caaf5769fe08c847b28d945ed7a9852ceb671 Mon Sep 17 00:00:00 2001 From: Eleftherios Angelos Tsourdiou <eleftherios2.tsourdiou@live.uwe.ac.uk> Date: Mon, 10 Feb 2025 10:34:20 +0000 Subject: [PATCH] Second push --- data_handler.py | 0 main.py | 159 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 0 ui_design.py | 0 visualizer.py | 0 5 files changed, 159 insertions(+) create mode 100644 data_handler.py create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 ui_design.py create mode 100644 visualizer.py diff --git a/data_handler.py b/data_handler.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..4881612 --- /dev/null +++ b/main.py @@ -0,0 +1,159 @@ +import sys +import pandas as pd +from PyQt6.QtWidgets import ( + QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, + QFileDialog, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QTextEdit +) +from PyQt6.QtGui import QColor +from PyQt6.QtCore import Qt +import matplotlib.pyplot as plt +from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas + + +class FeedingDashboard(QMainWindow): + def __init__(self): + super().__init__() + + self.setWindowTitle("Feeding Dashboard") + self.setGeometry(100, 100, 1000, 600) + + # Main Tab Widget + self.tabs = QTabWidget() + self.setCentralWidget(self.tabs) + + # Create Tabs + self.upload_tab = QWidget() + self.dashboard_tab = QWidget() + self.analytics_tab = QWidget() + self.help_tab = QWidget() + + # Add tabs to the tab widget + self.tabs.addTab(self.upload_tab, "Upload CSV File") + self.tabs.addTab(self.dashboard_tab, "View Dashboard") + self.tabs.addTab(self.analytics_tab, "Analytics") + self.tabs.addTab(self.help_tab, "Help") + + # Initialize tab UI + self.init_upload_tab() + self.init_dashboard_tab() + self.init_analytics_tab() + self.init_help_tab() + + self.df = None # Store the loaded data + + def init_upload_tab(self): + """Upload CSV File Tab""" + layout = QVBoxLayout() + + self.upload_button = QPushButton("Upload CSV File") + self.upload_button.clicked.connect(self.load_csv) + + self.file_label = QLabel("No file selected") + + layout.addWidget(self.upload_button) + layout.addWidget(self.file_label) + + self.upload_tab.setLayout(layout) + + def init_dashboard_tab(self): + """Dashboard Tab - Displays CSV Data in a Table""" + layout = QVBoxLayout() + + self.table_widget = QTableWidget() + layout.addWidget(self.table_widget) + + self.dashboard_tab.setLayout(layout) + + def init_analytics_tab(self): + """Analytics Tab - Displays Graphs""" + layout = QVBoxLayout() + + self.canvas = FigureCanvas(plt.figure(figsize=(6, 4))) + layout.addWidget(self.canvas) + + self.analytics_tab.setLayout(layout) + + def init_help_tab(self): + """Help Tab - Displays Instructions""" + layout = QVBoxLayout() + + help_text = QTextEdit() + help_text.setReadOnly(True) + help_text.setText( + "Welcome to the Feeding Dashboard!\n\n" + "1. Upload a CSV file in the 'Upload CSV File' tab.\n" + "2. View patient data in the 'View Dashboard' tab.\n" + "3. Analyze trends in the 'Analytics' tab.\n" + "4. Refer to this guide for help.\n" + ) + + layout.addWidget(help_text) + self.help_tab.setLayout(layout) + + def load_csv(self): + """Load CSV File""" + file_path, _ = QFileDialog.getOpenFileName(self, "Open CSV", "", "CSV Files (*.csv)") + if file_path: + self.file_label.setText(f"Loaded: {file_path}") + self.df = pd.read_csv(file_path) + self.df = self.df.fillna("None") #handle empty values + + + if "referral" in self.df.columns: + self.df["referral"] = self.df["referral"].replace({1.0: "Need Referral", 0.0: "No Need for Referral"}) + + self.display_data() + self.display_graphs() + + def display_data(self): + """Display CSV Data in Dashboard Table""" + if self.df is None: + return + + self.table_widget.setRowCount(self.df.shape[0]) + self.table_widget.setColumnCount(self.df.shape[1]) + self.table_widget.setHorizontalHeaderLabels(self.df.columns) + + for row in range(self.df.shape[0]): + for col in range(self.df.shape[1]): + cell_value = str(self.df.iat[row, col]) + if cell_value.strip() == "": + cell_value = "None" + + item = QTableWidgetItem(cell_value) + + # highlight Referral Patients + if "referral" in self.df.columns and self.df.columns[col] == "referral": + if cell_value == "Need Referral": + item.setBackground(QColor(255, 102, 102)) # light Red + elif cell_value == "No Need for Referral": + item.setBackground(QColor(144, 238, 144)) # light Green + + self.table_widget.setItem(row, col, item) + + def display_graphs(self): + """Display Analytics Graphs""" + if self.df is None or "referral" not in self.df.columns: + return + + # Count referrals + referral_counts = self.df["referral"].value_counts() + + # Clear previous graph + self.canvas.figure.clear() + + # Create new graph + ax = self.canvas.figure.add_subplot(111) + ax.bar(referral_counts.index, referral_counts.values, color=["green", "red"]) + ax.set_title("Patient Referrals") + ax.set_ylabel("Count") + + # Update canvas + self.canvas.draw() + + +if __name__ == "__main__": + app = QApplication(sys.argv) + window = FeedingDashboard() + window.show() + sys.exit(app.exec()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/ui_design.py b/ui_design.py new file mode 100644 index 0000000..e69de29 diff --git a/visualizer.py b/visualizer.py new file mode 100644 index 0000000..e69de29 -- GitLab