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.
- Ali Reza - 2306211471
- Mikola Syabila - 2306266741
- Fadlin Alwan Hanafi - 2306224335
- Muhammad Alif Iqbal - 2306206654
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
- โ 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
โโโโโโโโโโโโโโโโโโโ Network โโโโโโโโโโโโโโโโโโโ
โ Client โ โโโโโโโโโโโโโโโ โ Server โ
โ (Data Source) โ โ (Data Processor)โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Data Manager โ
โ (Anomaly Detection & Query) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Data Storage โ
โ (Binary Files & JSON Export) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
-
Client (
Client.cpp/hpp)- Simulates sensor data collection
- Establishes TCP connections to server
- Automatic reconnection on connection loss
- Configurable data transmission intervals
-
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
-
DataManager (
DataManager.cpp/hpp)- Anomaly detection with configurable thresholds
- Advanced querying and filtering capabilities
- Statistical analysis and data sorting
- Memory-efficient data management
-
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
-
AnomalyDetector (
AnomalyDetector.cpp/hpp)- Multi-parameter anomaly detection
- Configurable threshold system
- Detailed anomaly classification
- Batch anomaly analysis
- Windows 10/11 (Primary development environment)
- Visual Studio 2019/2022 with C++ support
- CMake 3.15+
- Google Test Framework (included in project)
- Clone and Navigate:
git clone <repository-url>
cd finpro- Build with CMake:
mkdir build
cd build
cmake ..
cmake --build . --config Release- Verify Installation:
# Run all tests
.\tests\run_tests.exe
# Should output: [ PASSED ] 40 tests.The system supports three execution modes:
.\finpro.exeFeatures:
- Interactive menu system with emoji indicators
- Real-time data generation and analysis
- Manual anomaly detection
- Query system with filtering and sorting
- Data export capabilities
.\finpro.exe server 8080Features:
- Listens for client connections on specified port
- Real-time data processing with anomaly detection
- Automatic data persistence
- Multi-client support
.\finpro.exe client 127.0.0.1 8080Features:
- Connects to specified server
- Continuous sensor data transmission
- Automatic reconnection on network issues
- Configurable transmission intervals
Use the provided demo script for a complete system demonstration:
.\demo.batThis script will:
- Start the server in background
- Run a client simulation
- Demonstrate all system features
- Show real-time anomaly detection
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
};Format: "Timestamp (ms): 1640995200000, Temp: 22.50 C, Humidity: 45.30 %, Light: 500.00 lux"
Response: "OK" or "ERROR"
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
}
]
}// Default thresholds (can be customized)
Temperature: 18.0ยฐC - 26.0ยฐC
Humidity: 30.0% - 70.0%
Light Intensity: 300.0 - 1000.0 lux// Default server settings
Port: 8080
Max Connections: 10
Connection Timeout: 5 seconds
Retry Attempts: 3Our 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
# Run all tests
.\tests\run_tests.exe
# Sample output:
[==========] Running 40 tests from 5 test suites.
[ PASSED ] 40 tests.- DataManagerTest (8 tests) - Query operations and data management
- ClientTest (6 tests) - Network communication and reconnection
- ServerTest (4 tests) - Multi-client handling and integration
- DataStorageTest (11 tests) - File I/O and data persistence
- AnomalyDetectorTest (11 tests) - Anomaly detection algorithms
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
.\finpro.exe
# Select option 1: Generate and analyze sensor data
# Select option 3: Query data with filters
# Select option 4: Export anomalies to JSON# Terminal 1 - Start server
.\finpro.exe server 8080
# Terminal 2 - Start client
.\finpro.exe client 127.0.0.1 8080// In your code
AnomalyDetector detector;
detector.setTemperatureRange(20.0, 24.0); // Stricter temperature range
detector.setHumidityRange(40.0, 60.0); // Narrower humidity rangeBuild 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
- Use Release build configuration for production
- Consider adjusting data transmission intervals for network efficiency
- Monitor memory usage for large datasets