Skip to content

Commit 8be3aeb

Browse files
authored
Merge pull request #3 from VisioSphereAI/feature/system_monitoring
Feature/system monitoring
2 parents 7630e8f + 48bca3e commit 8be3aeb

15 files changed

Lines changed: 1702 additions & 46 deletions

‎README.md‎

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ This repository contains an **advanced Flask application** demonstrating product
77
- **🐳 Docker** containerization with Gunicorn
88
- **📅 Interactive Calendar** system
99
- **✓ Task Manager** with priority levels
10-
- **🎨 Bootstrap 5** responsive UI
10+
- **� Gamification** with points, badges, and leaderboards
11+
- **🎯 Mini-games** - Riddle solver and Math challenges
12+
- **💻 System Monitor** - Real-time Windows/Linux performance tracking
13+
- **🌙 Dark Mode** - User-preferred theme support
14+
- **🎨 Bootstrap 5** responsive UI with animations
1115
- **🧪 Comprehensive Tests** with pytest
1216
- **🔄 CI/CD Pipeline** with GitHub Actions
1317
- **📊 Multi-page Application** with Jinja2 templates
@@ -57,14 +61,24 @@ docker compose up --build
5761

5862
### 🏠 Web Pages
5963
- **Home** - Overview of features and quick links
60-
- **📅 Calendar** - Interactive monthly event calendar
61-
- **✓ Tasks** - Task management with priorities and completion tracking
64+
- **📅 Calendar** - Interactive monthly event calendar with task addition
65+
- **✓ Tasks** - Task management with priorities, due dates, and completion tracking
66+
- **🎮 Arcade** - Interactive games (riddles, math challenges, color matching)
67+
- **👤 Profile** - User profile with gamification stats
68+
- **🏆 Leaderboard** - Competitive ranking system
69+
- **💻 System Monitor** - Real-time system performance dashboard
6270
- **About** - Project information and technologies
6371
- **Contact** - Next steps and suggestions
6472

6573
### 🔌 API Endpoints
6674
- `GET /health/` - Health check endpoint
6775
- `POST /api/v1/echo` - Echo JSON messages
76+
- `GET /api/v1/system/info` - Complete system information (JSON)
77+
- `GET /api/v1/system/cpu` - CPU metrics and core usage
78+
- `GET /api/v1/system/memory` - RAM and swap memory details
79+
- `GET /api/v1/system/disk` - Disk partitions and usage
80+
- `GET /api/v1/system/battery` - Battery status and health
81+
- `GET /api/v1/system/network` - Network interfaces and I/O statistics
6882

6983
### 🛠️ Advanced Features
7084
- **App Factory Pattern** - Flexible application initialization
@@ -74,6 +88,12 @@ docker compose up --build
7488
- **Form Handling** - Task creation and management
7589
- **Static Assets** - CSS and JavaScript support
7690
- **Responsive Design** - Mobile-friendly UI with Bootstrap 5
91+
- **📅 Calendar Task Addition** - Click dates to add tasks with due dates
92+
- **🎮 Gamification System** - Points, levels, badges, achievements, leaderboards
93+
- **🌙 Dark Mode Toggle** - Persistent user theme preference
94+
- **🎭 Easter Eggs** - Interactive hidden features (Konami code, etc.)
95+
- **💻 System Monitoring** - CPU, memory, disk, network, battery, and process tracking
96+
- **📊 Performance Metrics** - Top processes by CPU and memory usage
7797

7898
---
7999

@@ -85,29 +105,40 @@ docker compose up --build
85105
│ └── workflows/
86106
│ └── ci.yml # GitHub Actions CI/CD
87107
├── app/
88-
│ ├── __init__.py # App factory
108+
│ ├── __init__.py # App factory with Jinja2 filters
89109
│ ├── config.py # Configuration classes
90-
│ ├── routes.py # Blueprint routes
110+
│ ├── routes.py # Blueprint routes (40+ endpoints)
91111
│ ├── errors.py # Error handlers
92112
│ ├── extensions.py # Flask extensions
93113
│ ├── health.py # Health check blueprint
94114
│ ├── calendar_manager.py # Calendar logic
95115
│ ├── task_manager.py # Task management logic
116+
│ ├── gamification.py # Gamification system (points/badges/leaderboard)
117+
│ ├── minigames.py # Mini-games (riddles, math)
118+
│ ├── system_monitor.py # System monitoring (CPU/memory/disk/network/battery)
96119
│ ├── static/
97120
│ │ ├── css/
98-
│ │ │ └── styles.css # Custom styles
121+
│ │ │ └── styles.css # Custom styles with dark mode
99122
│ │ └── js/
100-
│ │ └── app.js # Frontend JavaScript
123+
│ │ └── app.js # Frontend JS (dark mode, easter eggs)
101124
│ └── templates/
102-
│ ├── layout.html # Base template
125+
│ ├── layout.html # Base template with navbar
103126
│ ├── home.html # Home page
104127
│ ├── calendar.html # Calendar page
105128
│ ├── tasks.html # Tasks page
129+
│ ├── profile.html # User profile page
130+
│ ├── leaderboard.html # Leaderboard page
131+
│ ├── games.html # Games menu page
132+
│ ├── riddle_game.html # Riddle game page
133+
│ ├── math_game.html # Math game page
134+
│ ├── system_monitor.html # System monitor dashboard
106135
│ ├── about.html # About page
107136
│ └── contact.html # Contact page
108137
├── tests/
109-
│ ├── test_api.py # API tests
110-
│ └── test_pages.py # Page tests
138+
│ ├── conftest.py # Pytest configuration
139+
│ ├── test_api.py # API endpoint tests
140+
│ ├── test_pages.py # Page rendering tests
141+
│ └── test_system.py # System monitoring tests
111142
├── docs/
112143
│ ├── api.md # API documentation
113144
│ ├── overview.md # Project overview

‎app/__init__.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
from .routes import main_bp
88

99

10+
def format_bytes(bytes_value):
11+
"""Convert bytes to human readable format."""
12+
for unit in ["B", "KB", "MB", "GB", "TB"]:
13+
if bytes_value < 1024:
14+
return f"{bytes_value:.2f} {unit}"
15+
bytes_value /= 1024
16+
return f"{bytes_value:.2f} PB"
17+
18+
1019
def create_app(config_object=None):
1120
app = Flask(__name__, instance_relative_config=True)
1221
config_object = config_object or "app.config.Config"
@@ -18,4 +27,7 @@ def create_app(config_object=None):
1827
app.register_blueprint(health_bp)
1928
register_error_handlers(app)
2029

30+
# Register custom Jinja2 filters
31+
app.jinja_env.filters["format_bytes"] = format_bytes
32+
2133
return app

‎app/calendar_manager.py‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
class EventCalendar:
66
"""Simple event calendar management."""
77

8-
def __init__(self):
8+
def __init__(self, task_manager=None):
99
self.events = {}
10+
self.task_manager = task_manager
1011

1112
def add_event(self, date_str, event_name):
1213
"""Add an event to a specific date."""
@@ -18,6 +19,28 @@ def get_events(self, date_str):
1819
"""Get events for a specific date."""
1920
return self.events.get(date_str, [])
2021

22+
def get_tasks_for_date(self, date_str):
23+
"""Get tasks for a specific date."""
24+
if not self.task_manager:
25+
return []
26+
27+
# Parse the date string to get year, month, day
28+
try:
29+
year, month, day = map(int, date_str.split('-'))
30+
target_date = datetime(year, month, day).date()
31+
32+
# Get all tasks and filter by due date
33+
all_tasks = self.task_manager.get_all_tasks()
34+
date_tasks = []
35+
36+
for task in all_tasks:
37+
if hasattr(task, 'due_date') and task.due_date == target_date:
38+
date_tasks.append(task)
39+
40+
return date_tasks
41+
except (ValueError, AttributeError):
42+
return []
43+
2144
def get_calendar_data(self, year, month):
2245
"""Get calendar data for a specific month."""
2346
cal_data = []
@@ -27,13 +50,14 @@ def get_calendar_data(self, year, month):
2750
week_data = []
2851
for day in week:
2952
if day == 0:
30-
week_data.append({"day": None, "events": []})
53+
week_data.append({"day": None, "events": [], "tasks": []})
3154
else:
3255
date_str = f"{year}-{month:02d}-{day:02d}"
3356
week_data.append({
3457
"day": day,
3558
"date": date_str,
3659
"events": self.get_events(date_str),
60+
"tasks": self.get_tasks_for_date(date_str),
3761
"is_today": self._is_today(year, month, day),
3862
})
3963
cal_data.append(week_data)

‎app/routes.py‎

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
from .task_manager import TaskManager
88
from .gamification import GamificationManager
99
from .minigames import MiniGame
10+
from .system_monitor import SystemMonitor
1011

1112
main_bp = Blueprint("main", __name__)
1213

1314
# Initialize managers
14-
event_calendar = EventCalendar()
1515
task_manager = TaskManager()
16+
event_calendar = EventCalendar(task_manager)
1617
game_manager = GamificationManager()
1718
mini_game = MiniGame()
19+
system_monitor = SystemMonitor()
1820

1921
# Pre-populate sample events and tasks
2022
event_calendar.add_event("2026-04-11", "Team Meeting")
@@ -99,6 +101,28 @@ def calendar():
99101
return render_template("calendar.html", **context)
100102

101103

104+
@main_bp.route("/calendar/add-task", methods=["POST"])
105+
def add_calendar_task():
106+
"""Add a task from the calendar modal."""
107+
date_str = request.form.get("date")
108+
title = request.form.get("title")
109+
description = request.form.get("description", "")
110+
priority = request.form.get("priority", "medium")
111+
112+
if not title or not date_str:
113+
return redirect(url_for("main.calendar"))
114+
115+
# Add the task with due date
116+
task_manager.add_task(title, description, priority, due_date=date_str)
117+
118+
# Award points for adding a task
119+
user_id = _get_user_id()
120+
game_manager.add_points(user_id, 5)
121+
game_manager.add_badge(user_id, "task_creator")
122+
123+
return redirect(url_for("main.calendar"))
124+
125+
102126
@main_bp.route("/tasks", methods=["GET", "POST"])
103127
def tasks():
104128
"""Display and manage tasks."""
@@ -125,10 +149,10 @@ def toggle_task(task_id):
125149
"""Toggle task completion status."""
126150
user_id = _get_user_id()
127151
task = task_manager.get_task(task_id)
128-
if task and not task["completed"]:
152+
if task and not task.completed:
129153
game_manager.increment_task_count(user_id)
130154
if task:
131-
task_manager.update_task(task_id, completed=not task["completed"])
155+
task_manager.update_task(task_id, completed=not task.completed)
132156

133157
return redirect(url_for("main.tasks"))
134158

@@ -242,3 +266,61 @@ def math_game():
242266
context["math"] = mini_game.quick_math()
243267

244268
return render_template("math_game.html", **context)
269+
270+
271+
@main_bp.route("/system", methods=["GET"])
272+
def system_monitor_page():
273+
"""Display system performance monitoring."""
274+
context = _template_context()
275+
context["title"] = "System Monitor"
276+
277+
system_info = system_monitor.get_all_info()
278+
context["system_info"] = system_info["system"]
279+
context["cpu_info"] = system_info["cpu"]
280+
context["memory_info"] = system_info["memory"]
281+
context["disk_info"] = system_info["disk"]
282+
context["network_info"] = system_info["network"]
283+
context["network_io"] = system_info["network_io"]
284+
context["battery_info"] = system_info["battery"]
285+
context["boot_time"] = system_info["boot_time"]
286+
context["processes"] = system_info["processes"]
287+
context["format_bytes"] = system_monitor.format_bytes
288+
289+
return render_template("system_monitor.html", **context)
290+
291+
292+
@main_bp.route("/api/v1/system/info", methods=["GET"])
293+
def api_system_info():
294+
"""API endpoint for system information."""
295+
return jsonify(system_monitor.get_all_info())
296+
297+
298+
@main_bp.route("/api/v1/system/cpu", methods=["GET"])
299+
def api_cpu_info():
300+
"""API endpoint for CPU information."""
301+
return jsonify(system_monitor.get_cpu_info())
302+
303+
304+
@main_bp.route("/api/v1/system/memory", methods=["GET"])
305+
def api_memory_info():
306+
"""API endpoint for memory information."""
307+
return jsonify(system_monitor.get_memory_info())
308+
309+
310+
@main_bp.route("/api/v1/system/disk", methods=["GET"])
311+
def api_disk_info():
312+
"""API endpoint for disk information."""
313+
return jsonify(system_monitor.get_disk_info())
314+
315+
316+
@main_bp.route("/api/v1/system/battery", methods=["GET"])
317+
def api_battery_info():
318+
"""API endpoint for battery information."""
319+
return jsonify(system_monitor.get_battery_info())
320+
321+
322+
@main_bp.route("/api/v1/system/network", methods=["GET"])
323+
def api_network_info():
324+
"""API endpoint for network information."""
325+
network_data = system_monitor.get_network_info()
326+
return jsonify(network_data)

0 commit comments

Comments
 (0)