https://github.com/yar0slave/statictics_service
A FastAPI-based service for collecting, storing, and analyzing statistics from devices. Test task for Gazprom.
https://github.com/yar0slave/statictics_service
alembic fastapi locust postgresql python sqlalchemy
Last synced: about 2 months ago
JSON representation
A FastAPI-based service for collecting, storing, and analyzing statistics from devices. Test task for Gazprom.
- Host: GitHub
- URL: https://github.com/yar0slave/statictics_service
- Owner: yar0slave
- Created: 2025-04-13T12:32:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-13T12:53:22.000Z (about 1 year ago)
- Last Synced: 2025-04-13T13:37:02.490Z (about 1 year ago)
- Topics: alembic, fastapi, locust, postgresql, python, sqlalchemy
- Language: Python
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Device Statistics Service
A FastAPI-based service for collecting, storing, and analyzing statistics from devices.
## Features
- Device registration and management
- User management with device associations
- Collection of device statistics (x, y, z coordinates)
- Statistical analysis of device data:
- Minimum value
- Maximum value
- Count
- Sum
- Median
- Time-based filtering for data analysis
- User-based aggregation of statistics across multiple devices
- Containerized deployment with Docker Compose
- Load testing with Locust
## System Architecture
- **FastAPI**: High-performance web framework for building APIs
- **PostgreSQL**: Relational database for storing device data and statistics
- **SQLAlchemy**: ORM for database operations
- **Docker & Docker Compose**: Containerization for easy deployment
- **Locust**: Load testing tool for performance evaluation
## Prerequisites
- Docker and Docker Compose
## Development
### Project Structure
```
device-stats-service/
│
├── app/ # Application code
│ ├── models/ # Database models
│ ├── schemas/ # Pydantic schemas
│ ├── routers/ # API endpoints
│ └── services/ # Business logic
├── locust/ # Load testing configuration
└── alembic/ # Database migrations
```
## Getting Started
1. Clone the repository:
```bash
git clone https://github.com/yar0slave/statictics_service/
cd statictics_service
```
2. Start the services using Docker Compose:
```bash
docker-compose up -d
```
This will start:
- The FastAPI application on port 8000
- The PostgreSQL database on port 5432
- The Locust load testing interface on port 8089
3. Access the API documentation at http://localhost:8000/docs
## API Endpoints
### Users
- `GET /api/v1/users/` - List all users
- `POST /api/v1/users/` - Create a new user
- `GET /api/v1/users/{user_id}` - Get user details with associated devices
- `PUT /api/v1/users/{user_id}` - Update user details
- `DELETE /api/v1/users/{user_id}` - Delete a user
### Devices
- `GET /api/v1/devices/` - List all devices
- `POST /api/v1/devices/` - Register a new device
- `GET /api/v1/devices/{device_id}` - Get device details
- `PUT /api/v1/devices/{device_id}` - Update device details
- `DELETE /api/v1/devices/{device_id}` - Delete a device
### Statistics
- `POST /api/v1/stats/devices/{device_id}` - Submit statistics for a device
- `GET /api/v1/stats/devices/{device_id}` - Get statistics for a device
- `POST /api/v1/stats/devices/{device_id}/analyze` - Analyze statistics for a device
- `POST /api/v1/stats/users/{user_id}/analyze` - Analyze statistics for all devices of a user
## Load Testing
The service includes a Locust configuration for load testing. Access the Locust web interface at http://localhost:8089 to configure and run load tests.
