#!/usr/bin/env python3 """ Interactive team dashboard for viewing presence statistics """ import os import sys from datetime import datetime, timedelta from pathlib import Path from config_multi_user import SUMMARIES_DIR, TIMEZONE from data_handler_team import get_team_handler def clear_screen(): """Clear the terminal screen""" os.system('clear' if os.name == 'posix' else 'cls') def print_menu(): """Print the main menu""" print("\n" + "=" * 60) print("SLACK TEAM PRESENCE DASHBOARD") print("=" * 60) print("\n1. Today's Summary") print("2. Yesterday's Summary") print("3. This Week's Summary") print("4. Last Week's Summary") print("5. This Month's Summary") print("6. Last Month's Summary") print("7. Custom Date Range") print("8. User Comparison") print("9. Export Reports") print("0. Exit") print("\n" + "-" * 60) def get_today_summary(): """Get today's current summary""" team_handler = get_team_handler() today = datetime.now(TIMEZONE).date() summary = team_handler.generate_daily_team_summary(today) if not summary: print("\nNo data available for today yet.") return print(f"\nšŸ“Š TODAY'S LIVE SUMMARY - {today.strftime('%Y-%m-%d')} (as of {datetime.now(TIMEZONE).strftime('%H:%M')})") print("-" * 60) # Quick stats active_now = summary['team_totals']['active_users'] total_users = summary['team_totals']['total_users'] print(f"\nšŸ‘„ Team Status: {active_now}/{total_users} members online") # Current hour activity current_hour = datetime.now(TIMEZONE).hour users_this_hour = summary['hourly_team_presence'].get(current_hour, 0) print(f"ā° Active this hour ({current_hour:02d}:00): {users_this_hour} users") # Individual status print("\nšŸ“‹ Individual Status:") sorted_users = sorted(summary['users'].items(), key=lambda x: (x[1]['total_minutes'] > 0, x[1]['total_minutes']), reverse=True) for user_id, user_data in sorted_users: status = "🟢" if user_data['total_minutes'] > 0 else "⚫" name = user_data['name'][:20] if user_data['total_minutes'] > 0: hours = user_data['total_hours'] first = user_data['first_seen'] or '-' last = user_data['last_seen'] or '-' print(f" {status} {name:<20} - {hours:.1f}h (First: {first}, Last: {last})") else: print(f" {status} {name:<20} - Not seen today") # Peak hours print("\nšŸ“ˆ Peak Hours Today:") peak_hours = sorted([(h, c) for h, c in summary['hourly_team_presence'].items() if c > 0], key=lambda x: x[1], reverse=True)[:3] for hour, count in peak_hours: print(f" {hour:02d}:00 - {count} users active") def get_user_comparison(): """Compare users' performance""" team_handler = get_team_handler() # Get last 7 days of data print("\nšŸ“Š USER COMPARISON - Last 7 Days") print("-" * 60) user_totals = {} for i in range(7): date = datetime.now(TIMEZONE).date() - timedelta(days=i) summary = team_handler.generate_daily_team_summary(date) if summary: for user_id, user_data in summary['users'].items(): if user_id not in user_totals: user_totals[user_id] = { 'name': user_data['name'], 'total_hours': 0, 'days_active': 0, 'earliest_start': None, 'latest_end': None } if user_data['total_hours'] > 0: user_totals[user_id]['total_hours'] += user_data['total_hours'] user_totals[user_id]['days_active'] += 1 # Track earliest/latest if user_data['first_seen']: if not user_totals[user_id]['earliest_start'] or \ user_data['first_seen'] < user_totals[user_id]['earliest_start']: user_totals[user_id]['earliest_start'] = user_data['first_seen'] if user_data['last_seen']: if not user_totals[user_id]['latest_end'] or \ user_data['last_seen'] > user_totals[user_id]['latest_end']: user_totals[user_id]['latest_end'] = user_data['last_seen'] # Rank users ranked_users = sorted(user_totals.items(), key=lambda x: x[1]['total_hours'], reverse=True) print(f"\n{'Rank':<6} {'Name':<20} {'Total':<10} {'Days':<8} {'Avg/Day':<10} {'Typical Hours':<20}") print("-" * 74) for rank, (user_id, data) in enumerate(ranked_users, 1): if data['total_hours'] > 0: name = data['name'][:19] total = f"{data['total_hours']:.1f}h" days = f"{data['days_active']}/7" avg = f"{data['total_hours']/7:.1f}h" if data['days_active'] > 0 else "0h" typical = f"{data['earliest_start'] or '-'} to {data['latest_end'] or '-'}" # Add medal for top 3 medal = "" if rank == 1: medal = "šŸ„‡" elif rank == 2: medal = "🄈" elif rank == 3: medal = "šŸ„‰" print(f"{medal}{rank:<5} {name:<20} {total:<10} {days:<8} {avg:<10} {typical:<20}") def export_reports(): """Export various reports""" print("\nšŸ“ EXPORT OPTIONS") print("-" * 40) print("1. Export daily summary (CSV)") print("2. Export weekly report (Text)") print("3. Export monthly report (Text)") print("4. Export all data (ZIP)") print("0. Back") choice = input("\nSelect export option: ").strip() team_handler = get_team_handler() if choice == '1': # Export daily CSV date_str = input("Enter date (YYYY-MM-DD) or press Enter for yesterday: ").strip() if date_str: target_date = datetime.strptime(date_str, '%Y-%m-%d').date() else: target_date = datetime.now(TIMEZONE).date() - timedelta(days=1) summary = team_handler.generate_daily_team_summary(target_date) if summary: team_handler.save_team_summary_to_csv(summary) print(f"āœ“ Exported to: {team_handler.team_summary_file}") elif choice == '2': # Export weekly report filename = SUMMARIES_DIR / f"weekly_report_{datetime.now().strftime('%Y%m%d')}.txt" os.system(f"python3 team_summary.py --type weekly --save") print(f"āœ“ Exported weekly report") elif choice == '3': # Export monthly report os.system(f"python3 team_summary.py --type monthly --save") print(f"āœ“ Exported monthly report") def main(): """Main dashboard loop""" while True: print_menu() choice = input("Select option: ").strip() if choice == '0': print("\nGoodbye! šŸ‘‹") break elif choice == '1': clear_screen() get_today_summary() input("\nPress Enter to continue...") elif choice == '2': clear_screen() os.system("python3 team_summary.py --type daily") input("\nPress Enter to continue...") elif choice == '3': clear_screen() os.system("python3 team_summary.py --type weekly") input("\nPress Enter to continue...") elif choice == '4': clear_screen() # Last week last_monday = datetime.now(TIMEZONE).date() last_monday -= timedelta(days=last_monday.weekday() + 7) os.system(f"python3 team_summary.py --type weekly --week {last_monday}") input("\nPress Enter to continue...") elif choice == '5': clear_screen() os.system("python3 team_summary.py --type monthly") input("\nPress Enter to continue...") elif choice == '6': clear_screen() # Last month today = datetime.now(TIMEZONE).date() last_month = today.replace(day=1) - timedelta(days=1) os.system(f"python3 team_summary.py --type monthly --month {last_month.strftime('%Y-%m')}") input("\nPress Enter to continue...") elif choice == '7': clear_screen() start_date = input("Enter start date (YYYY-MM-DD): ").strip() end_date = input("Enter end date (YYYY-MM-DD): ").strip() # Custom date range logic would go here print("Custom date range feature coming soon!") input("\nPress Enter to continue...") elif choice == '8': clear_screen() get_user_comparison() input("\nPress Enter to continue...") elif choice == '9': clear_screen() export_reports() input("\nPress Enter to continue...") else: print("Invalid option. Please try again.") input("\nPress Enter to continue...") clear_screen() if __name__ == "__main__": try: main() except KeyboardInterrupt: print("\n\nDashboard closed. Goodbye! šŸ‘‹") sys.exit(0)