import streamlit as st import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as patches import math import matplotlib.transforms as transforms import sqlite3 # Import FPSO-specific modules from reparos.clv import * from reparos.paz import * from reparos.dal import * from reparos.gir import * # --- UI CONFIG & STYLE --- st.set_page_config(page_title="Inspekta Deck - FPSO Notifications", layout="wide") st.markdown(""" """, unsafe_allow_html=True) # Add logo and title st.markdown("""

🚢 Inspekta Deck

FPSO Notifications Analysis

""", unsafe_allow_html=True) # Main title st.title("🚢 FPSO Notifications Analysis Platform") st.markdown("---") # Initialize session state if 'data_loaded' not in st.session_state: st.session_state.data_loaded = False if 'df' not in st.session_state: st.session_state.df = None if 'fpsos' not in st.session_state: st.session_state.fpsos = [] # Sidebar with st.sidebar: st.header("📊 Data Management") # File upload uploaded_file = st.file_uploader("Upload Excel file", type=['xlsx', 'xls']) if uploaded_file is not None: try: # Load data df = pd.read_excel(uploaded_file) st.session_state.df = df st.session_state.data_loaded = True st.session_state.fpsos = df['FPSO'].unique().tolist() st.success("Data loaded successfully!") except Exception as e: st.error(f"Error loading file: {str(e)}") # Database connection (if available) if st.button("Load from Database"): try: # Try multiple possible database paths db_paths = [ 'reparos/notifs_data.db', 'notifs_data.db', './reparos/notifs_data.db', '../reparos/notifs_data.db' ] df = None for db_path in db_paths: try: conn = sqlite3.connect(db_path) df = pd.read_sql_query("SELECT * FROM notifications", conn) conn.close() st.success(f"Data loaded from database: {db_path}") break except Exception: continue if df is not None: st.session_state.df = df st.session_state.data_loaded = True st.session_state.fpsos = df['FPSO'].unique().tolist() else: st.error("Database file not found. Please upload an Excel file instead.") except Exception as e: st.error(f"Error loading from database: {str(e)}") if st.session_state.data_loaded: st.markdown("---") st.header("🎯 Analysis Options") # FPSO selection selected_fpsos = st.multiselect( "Select FPSOs to analyze", st.session_state.fpsos, default=st.session_state.fpsos[:3] if len(st.session_state.fpsos) >= 3 else st.session_state.fpsos ) # Date range if 'Date' in st.session_state.df.columns: st.session_state.df['Date'] = pd.to_datetime(st.session_state.df['Date']) min_date = st.session_state.df['Date'].min() max_date = st.session_state.df['Date'].max() date_range = st.date_input( "Select date range", value=(min_date, max_date), min_value=min_date, max_value=max_date ) # Main content if st.session_state.data_loaded: # Create tabs tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs([ "📈 Overview", "🔍 CLV Analysis", "⚡ PAZ Analysis", "🏗️ DAL Analysis", "⚙️ GIR Analysis", "🤖 RAG Assistant" ]) with tab1: st.header("📊 Overview Dashboard") # Key metrics col1, col2, col3, col4 = st.columns(4) with col1: st.metric("Total Notifications", len(st.session_state.df)) with col2: st.metric("Unique FPSOs", len(st.session_state.fpsos)) with col3: if 'Priority' in st.session_state.df.columns: high_priority = len(st.session_state.df[st.session_state.df['Priority'] == 'High']) st.metric("High Priority", high_priority) with col4: if 'Status' in st.session_state.df.columns: open_notifications = len(st.session_state.df[st.session_state.df['Status'] == 'Open']) st.metric("Open Notifications", open_notifications) # Charts col1, col2 = st.columns(2) with col1: st.subheader("Notifications by FPSO") fpso_counts = st.session_state.df['FPSO'].value_counts() fig, ax = plt.subplots(figsize=(10, 6)) fpso_counts.plot(kind='bar', ax=ax) plt.xticks(rotation=45) plt.tight_layout() st.pyplot(fig) with col2: if 'Priority' in st.session_state.df.columns: st.subheader("Notifications by Priority") priority_counts = st.session_state.df['Priority'].value_counts() fig, ax = plt.subplots(figsize=(10, 6)) priority_counts.plot(kind='pie', autopct='%1.1f%%', ax=ax) plt.tight_layout() st.pyplot(fig) with tab2: st.header("🔍 CLV Analysis") # CLV-specific analysis would go here st.info("CLV analysis features will be implemented here") with tab3: st.header("⚡ PAZ Analysis") # PAZ-specific analysis would go here st.info("PAZ analysis features will be implemented here") with tab4: st.header("🏗️ DAL Analysis") # DAL-specific analysis would go here st.info("DAL analysis features will be implemented here") with tab5: st.header("⚙️ GIR Analysis") # GIR-specific analysis would go here st.info("GIR analysis features will be implemented here") with tab6: st.header("🤖 RAG Assistant") try: # Import RAG chatbot from reparos.rag_chatbot import DigiTwinRAG # Initialize RAG system if 'rag_system' not in st.session_state: st.session_state.rag_system = DigiTwinRAG() # Load data into RAG system if st.session_state.df is not None: st.session_state.rag_system.load_notifications_data(st.session_state.df) # Render chat interface st.session_state.rag_system.render_chat_interface() except ImportError: st.error("RAG module not available. Please install the required dependencies.") st.code("pip install -r reparos/requirements_rag.txt") except Exception as e: st.error(f"Error initializing RAG system: {str(e)}") else: st.info("👆 Please upload an Excel file or load data from database to begin analysis.") # Show sample data structure st.subheader("📋 Expected Data Structure") st.markdown(""" Your Excel file should contain the following columns: - **FPSO**: FPSO identifier - **Date**: Notification date - **Priority**: Notification priority (High, Medium, Low) - **Status**: Notification status (Open, Closed, etc.) - **Description**: Notification description - **Category**: Notification category """) # Show sample data sample_data = pd.DataFrame({ 'FPSO': ['CLV', 'PAZ', 'DAL', 'GIR'], 'Date': ['2024-01-01', '2024-01-02', '2024-01-03', '2024-01-04'], 'Priority': ['High', 'Medium', 'Low', 'High'], 'Status': ['Open', 'Closed', 'Open', 'Closed'], 'Description': ['Sample notification 1', 'Sample notification 2', 'Sample notification 3', 'Sample notification 4'], 'Category': ['Safety', 'Maintenance', 'Operations', 'Safety'] }) st.dataframe(sample_data) # Footer st.markdown("---") st.markdown("""

🚢 Inspekta Deck - FPSO Notifications Analysis Platform

Built with ❤️ by ValonyLabs | Powered by Streamlit

""", unsafe_allow_html=True)