Skip to content

MikoAlt/finpro_alprog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

29 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿซ Smart Classroom Monitoring System

Final Project - CS1 (Case Study 1)

A comprehensive sensor monitoring system designed for smart classroom environments in electrical engineering education. This system implements real-time data collection, anomaly detection, and data persistence with a client-server architecture.


๐Ÿ‘ฅ Team Members

  • Ali Reza - 2306211471
  • Mikola Syabila - 2306266741
  • Fadlin Alwan Hanafi - 2306224335
  • Muhammad Alif Iqbal - 2306206654

๐ŸŽฏ Project Overview

This system monitors classroom environmental conditions using three key sensors:

  • ๐ŸŒก๏ธ Temperature: Optimal range 18-26ยฐC for learning environments
  • ๐Ÿ’ง Humidity: Maintained between 30-70% for comfort
  • ๐Ÿ’ก Light Intensity: 300-1000 lux for adequate visibility

Key Features

  • โœ… Real-time Monitoring: Live sensor data collection and processing
  • โœ… Anomaly Detection: Automatic identification of environmental issues
  • โœ… Data Persistence: Binary and JSON export capabilities
  • โœ… Client-Server Architecture: Distributed monitoring system
  • โœ… Interactive CLI: User-friendly command-line interface
  • โœ… Comprehensive Testing: 40+ unit and integration tests

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    Network     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Client      โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ†’ โ”‚     Server      โ”‚
โ”‚  (Data Source)  โ”‚                 โ”‚ (Data Processor)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                            โ”‚
                                            โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚          Data Manager               โ”‚
                    โ”‚    (Anomaly Detection & Query)     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                            โ”‚
                                            โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚         Data Storage                โ”‚
                    โ”‚    (Binary Files & JSON Export)    โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Components

  1. Client (Client.cpp/hpp)

    • Simulates sensor data collection
    • Establishes TCP connections to server
    • Automatic reconnection on connection loss
    • Configurable data transmission intervals
  2. Server (Server.cpp/hpp)

    • Handles multiple client connections
    • Real-time data processing and validation
    • Integration with DataManager for anomaly detection
    • Callback system for data processing notifications
  3. DataManager (DataManager.cpp/hpp)

    • Anomaly detection with configurable thresholds
    • Advanced querying and filtering capabilities
    • Statistical analysis and data sorting
    • Memory-efficient data management
  4. DataStorage (DataStorage.cpp/hpp)

    • Binary file persistence for performance
    • JSON export for data analysis and reports
    • Batch operations for large datasets
    • Error handling for file I/O operations
  5. AnomalyDetector (AnomalyDetector.cpp/hpp)

    • Multi-parameter anomaly detection
    • Configurable threshold system
    • Detailed anomaly classification
    • Batch anomaly analysis

๐Ÿš€ Getting Started

Prerequisites

  • Windows 10/11 (Primary development environment)
  • Visual Studio 2019/2022 with C++ support
  • CMake 3.15+
  • Google Test Framework (included in project)

Building the Project

  1. Clone and Navigate:
git clone <repository-url>
cd finpro
  1. Build with CMake:
mkdir build
cd build
cmake ..
cmake --build . --config Release
  1. Verify Installation:
# Run all tests
.\tests\run_tests.exe

# Should output: [  PASSED  ] 40 tests.

Running the Application

The system supports three execution modes:

1. ๐Ÿ–ฅ๏ธ Interactive CLI Mode (Default)

.\finpro.exe

Features:

  • Interactive menu system with emoji indicators
  • Real-time data generation and analysis
  • Manual anomaly detection
  • Query system with filtering and sorting
  • Data export capabilities

2. ๐ŸŒ Server Mode

.\finpro.exe server 8080

Features:

  • Listens for client connections on specified port
  • Real-time data processing with anomaly detection
  • Automatic data persistence
  • Multi-client support

3. ๐Ÿ“ก Client Mode

.\finpro.exe client 127.0.0.1 8080

Features:

  • Connects to specified server
  • Continuous sensor data transmission
  • Automatic reconnection on network issues
  • Configurable transmission intervals

๐ŸŽฎ Quick Demo

Use the provided demo script for a complete system demonstration:

.\demo.bat

This script will:

  1. Start the server in background
  2. Run a client simulation
  3. Demonstrate all system features
  4. Show real-time anomaly detection

๐Ÿ“Š Data Format

Sensor Data Structure

struct SensorData {
    uint64_t timestamp;     // Unix timestamp in milliseconds
    double temperature;     // Temperature in Celsius
    double humidity;        // Humidity percentage (0-100)
    double lightIntensity;  // Light intensity in lux
    bool isAnomalous;       // Anomaly detection flag
    double deviation;       // Statistical deviation score
};

Network Protocol

Format: "Timestamp (ms): 1640995200000, Temp: 22.50 C, Humidity: 45.30 %, Light: 500.00 lux"
Response: "OK" or "ERROR"

File Formats

Binary Storage: Efficient binary format for high-performance storage and retrieval JSON Export: Human-readable format for analysis and reporting

{
  "anomalies": [
    {
      "timestamp": 1640995200000,
      "temperature": 35.0,
      "humidity": 80.0,
      "lightIntensity": 50.0,
      "deviation": 2.5
    }
  ]
}

๐Ÿ”ง Configuration

Anomaly Detection Thresholds

// Default thresholds (can be customized)
Temperature: 18.0ยฐC - 26.0ยฐC
Humidity: 30.0% - 70.0%
Light Intensity: 300.0 - 1000.0 lux

Network Settings

// Default server settings
Port: 8080
Max Connections: 10
Connection Timeout: 5 seconds
Retry Attempts: 3

๐Ÿงช Testing

Test Coverage

Our comprehensive test suite includes 40 tests covering:

  • Unit Tests: Individual component functionality
  • Integration Tests: Component interaction and data flow
  • Network Tests: Client-server communication
  • Storage Tests: Data persistence and retrieval
  • Anomaly Detection Tests: Detection accuracy and edge cases

Running Tests

# Run all tests
.\tests\run_tests.exe

# Sample output:
[==========] Running 40 tests from 5 test suites.
[  PASSED  ] 40 tests.

Test Categories

  1. DataManagerTest (8 tests) - Query operations and data management
  2. ClientTest (6 tests) - Network communication and reconnection
  3. ServerTest (4 tests) - Multi-client handling and integration
  4. DataStorageTest (11 tests) - File I/O and data persistence
  5. AnomalyDetectorTest (11 tests) - Anomaly detection algorithms

๐Ÿ“ Project Structure

finpro/
โ”œโ”€โ”€ ๐Ÿ“‚ src/                          # Source code
โ”‚   โ”œโ”€โ”€ Client.cpp                   # Client implementation
โ”‚   โ”œโ”€โ”€ Server.cpp                   # Server implementation
โ”‚   โ”œโ”€โ”€ DataManager.cpp              # Data management and queries
โ”‚   โ”œโ”€โ”€ DataStorage.cpp              # File I/O operations
โ”‚   โ”œโ”€โ”€ AnomalyDetector.cpp          # Anomaly detection logic
โ”‚   โ””โ”€โ”€ main.cpp                     # Multi-mode application entry
โ”œโ”€โ”€ ๐Ÿ“‚ include/                      # Header files
โ”‚   โ”œโ”€โ”€ Client.hpp                   # Client class definitions
โ”‚   โ”œโ”€โ”€ Server.hpp                   # Server class definitions
โ”‚   โ”œโ”€โ”€ DataManager.hpp              # Data management interfaces
โ”‚   โ”œโ”€โ”€ DataStorage.hpp              # Storage interfaces
โ”‚   โ”œโ”€โ”€ AnomalyDetector.hpp          # Detection interfaces
โ”‚   โ””โ”€โ”€ SensorData.hpp               # Data structures
โ”œโ”€โ”€ ๐Ÿ“‚ tests/                        # Test suite
โ”‚   โ”œโ”€โ”€ test_client.cpp              # Client functionality tests
โ”‚   โ”œโ”€โ”€ test_server.cpp              # Server and integration tests
โ”‚   โ”œโ”€โ”€ test_data_manager.cpp        # Data management tests
โ”‚   โ”œโ”€โ”€ test_data_storage.cpp        # Storage functionality tests
โ”‚   โ””โ”€โ”€ test_anomaly_detector.cpp    # Anomaly detection tests
โ”œโ”€โ”€ ๐Ÿ“‚ build/                        # Build artifacts
โ”‚   โ”œโ”€โ”€ finpro.exe                   # Main executable
โ”‚   โ””โ”€โ”€ tests/run_tests.exe          # Test runner
โ”œโ”€โ”€ ๐Ÿ“„ CMakeLists.txt                # Build configuration
โ”œโ”€โ”€ ๐Ÿ“„ demo.bat                      # Demo script
โ””โ”€โ”€ ๐Ÿ“„ README.md                     # This file

๐ŸŽฏ Usage Examples

Example 1: Interactive Data Analysis

.\finpro.exe
# Select option 1: Generate and analyze sensor data
# Select option 3: Query data with filters
# Select option 4: Export anomalies to JSON

Example 2: Distributed Monitoring

# Terminal 1 - Start server
.\finpro.exe server 8080

# Terminal 2 - Start client
.\finpro.exe client 127.0.0.1 8080

Example 3: Custom Anomaly Detection

// In your code
AnomalyDetector detector;
detector.setTemperatureRange(20.0, 24.0);  // Stricter temperature range
detector.setHumidityRange(40.0, 60.0);     // Narrower humidity range

๐Ÿ” Troubleshooting

Common Issues

Build Errors:

  • Ensure Visual Studio C++ components are installed
  • Verify CMake version is 3.15 or higher
  • Check that all dependencies are properly linked

Network Connection Issues:

  • Verify firewall settings allow the application
  • Check if the specified port is available
  • Ensure server is running before starting client

Test Failures:

  • Run tests in Release mode for optimal performance
  • Check for antivirus interference
  • Verify all test data files are accessible

Performance Optimization

  • Use Release build configuration for production
  • Consider adjusting data transmission intervals for network efficiency
  • Monitor memory usage for large datasets

About

finpro alprog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors