| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A Python service for processing CSV sensor data with custom-built cloud service mocks.
# Without virtual environment:
# Install dependencies
pip install -r requirements.txt
# Option 1: Run the service without UI
python run.py
# Option 2: Run the service with Streamlit UI
python run_all.pyAccess:
Upload a file:
curl -X POST "http://localhost:8000/upload" -F "file=@sample_data/sensor_data.csv"┌─────────────────────────────────────────────────────────────────────┐
│ Client Layer │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ HTTP Client │ │ Streamlit UI │ │
│ │ (curl/browser) │ │ (Port 8501) │ │
│ └────────┬─────────┘ └────────┬─────────┘ │
└───────────┼────────────────────────────────┼──────────────────────┘
│ │
└─────────────────┬───────────────┘
│ HTTP/REST
▼
┌─────────────────────────────────────────────────────────────────────┐
│ API Layer (FastAPI) │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ POST /upload │ GET /results/{id} │ GET /status/{id} │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ FileHandler (Async Orchestration) │ │
│ │ • Concurrent file processing (asyncio) │ │
│ │ • Max X concurrent tasks (configurable) │ │
│ │ │ │
│ └───────────────────────────────────────────────────────────────┘ │
└───────────────────────────┬──────────────┬──────────────────────────┘
│ │
┌───────────────┘ └───────────────┐
│ │
▼ ▼
┌──────────────────────────┐ ┌──────────────────────────┐
│ Business Logic Layer │ │ Persistence Layer │
│ ┌────────────────────┐ │ │ ┌────────────────────┐ │
│ │ DataProcessor │ │ │ │ BlobStorage │ │
│ │ • CSV parsing │ │ │ │ (S3 wrapper) │ │
│ │ • Validation │ │ │ │ │ │
│ │ • Aggregation │ │ │ │ MetadataStorage │ │
│ │ • Error handling │ │ │ │ (DynamoDB wrap) │ │
│ └────────────────────┘ │ │ └────────────────────┘ │
└──────────────────────────┘ └─────────┬────────────────┘
│
│ (sync interface)
│
▼
┌──────────────────────────────────────┐
│ Mock Layer │
│ ┌────────────────────────────────┐ │
│ │ MockS3Client (in-memory) │ │
│ │ • Thread-safe storage │ │
│ │ • Exponential backoff retry │ │
│ │ │ │
│ │ MockDynamoDB (in-memory) │ │
│ │ • Thread-safe storage │ │
│ │ • Exponential backoff retry │ │
│ └────────────────────────────────┘ │
└──────────────────────────────────────┘
1. Layered Architecture:
2. Async Orchestration with Sync Foundations:
3. Separation of Concerns:
4. Production-Ready Design:
The mocks run automatically - no configuration needed:
python -m venv venv
venv\Scripts\activate # Windows
source venv/bin/activate # Mac/Linux
pip install -r requirements.txt
python run.pyDocker Compose provides containerized deployment for both the API and UI services.
Quick Start:
# Start both API and UI services
docker-compose -f build/docker-compose.yml up
# Start in background (detached mode)
docker-compose -f build/docker-compose.yml up -d
# Stop all services
docker-compose -f build/docker-compose.yml downService Options:
# Start API only
docker-compose -f build/docker-compose.yml up api
# Start UI only (requires API to be running)
docker-compose -f build/docker-compose.yml up ui
# View logs
docker-compose -f build/docker-compose.yml logs -fWhat's Included:
Environment Variables: Docker Compose automatically passes environment variables to containers. You can customize:
Decision: Docker Compose performs automatic health checks on the API service
Implementation:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40sBehavior:
Benefits:
Decision: Built S3 and DynamoDB mocks infrastructure
Decision: AWS DynamoDB (mocked) for results/metadata
Rationale:
Decision: Asyncio with async/await
Rationale:
Workload Analysis:
Trade-offs:
Alternatives Considered:
Threading:
Conclusion: Asyncio provides optimal balance of throughput, memory efficiency, and simplicity for this I/O-bound workload. FastAPI's native asyncio support enables seamless integration without mixing concurrency paradigms.
Decision: Retry logic in mock classes (not wrapper classes)
Rationale:
Configuration:
Decision: Two-level hierarchy with generic base classes, examples:
BlobStorageException → S3Error → NoSuchBucket MetadataStorageException → DynamoDBError → ResourceNotFoundException
Rationale:
Decision: Pydantic models for CSV validation
Rationale:
Upload CSV file, returns file_id immediately (202 Accepted)
Request:
curl -X POST "http://localhost:8000/upload" -F "file=@sample_data/sensor_data.csv"Response (202 Accepted):
{
"file_id": "abc123...",
"status": "pending",
"message": "File uploaded successfully and queued for processing"
}Get processing results and metadata
Request:
curl "http://localhost:8000/results/abc123..."Response (200 OK):
{
"file_id": "abc123...",
"status": "processed",
"filename": "sensor_data.csv",
"upload_time": "2025-12-07T10:30:00Z",
"processing_time": "2025-12-07T10:30:05Z",
"total_rows": 1000,
"valid_rows": 980,
"invalid_rows": 20,
"aggregated_data": {
"sensor_001": {"avg": 25.5, "min": 20.0, "max": 30.0, "count": 100},
"sensor_002": {"avg": 18.2, "min": 15.0, "max": 22.0, "count": 98}
}
}Get processing status only
Request:
curl "http://localhost:8000/status/abc123..."Response (200 OK):
{
"file_id": "abc123...",
"status": "processing"
}Status values: pending, processing, processed, partial, failed
Multi-layer approach:
Status values: pending, processing, processed, partial, failed
app/ ├── cloud_services_mock/ # Custom S3 & DynamoDB mocks ├── persistence/ # Storage wrappers with interfaces ├── services/ # Business logic (CSV processing) ├── utils/ # Validators, retry decorator, logger ├── main.py # FastAPI application ├── constants.py # Constants and enums ├── exceptions.py # Exception hierarchy ├── main.py # FastAPI application ├── models.py # Models and schemas └── config.py # Configuration sample_data/ # Sample CSV files ui/ # Streamlit Web UI tests/ # Unit tests build/ # Docker files load_test.py # Load testing client run.py # Run API service run_all.py # Run API + UI services requirements.txt # Python dependencies README.md # This documentation
Note: The mock implementations include additional AWS SDK methods (list_objects_v2, scan, delete_table, list_tables, delete_file, delete_metadata) beyond current requirements. These are intentionally implemented for API completeness, future extensibility, and production parity with real AWS services.
The project includes comprehensive unit tests using Python's unittest framework.
Test Coverage:
Run all tests:
python -m unittest discover tests -vRun specific test file:
python -m unittest tests.test_validators
python -m unittest tests.test_data_processor
python -m unittest tests.test_file_handlerTotal: 20 unit tests covering validators, data processing, storage mocks, and async workflows.
The project includes a load testing client to simulate high concurrency and stress test the service. Used for benchmarking and validating performance under load.
Load Test Tool:
# Basic load test: 50 files, 10 concurrent requests
python load_test.py --files 50 --concurrency 10
# Stress test: 100 large files, 20 concurrent requests
python load_test.py --files 100 --concurrency 20 --size large
# Test with error handling: include invalid rows
python load_test.py --files 30 --concurrency 10 --errors
# Wait for processing completion and show results
python load_test.py --files 50 --concurrency 15 --wait
# Extreme stress test: 500 small files
python load_test.py --files 500 --concurrency 50 --size smallOptions:
Metrics Provided:
# .env file
PORT=9001
UI_PORT=9501allowed_origins = [
"http://localhost:8501", # Local UI
"https://yourdomain.com", # Production UI
]| Back | FazBrowse Home | New Git URL |