dbrpp_db Project Documentation
High-Level Overview
The dbrpp_db project is a data processing and database management system supporting a mobile application. It ingests, processes, and stores both public and private data, providing up-to-date statistics and analytics. The system is composed of several Python modules for data loading, calculation, database access, and logging, orchestrated by the dbrpp_calc script, which can be run in various modes (debug, run, schedule).
Setup and Installation
- Clone the repository and navigate to the project directory.
- Install dependencies:
pip install -r requirements.txt - Configure environment variables in
.envas needed. - Refer to
README.mdfor further instructions.
Directory Structure
calculations.py: Main data processing and calculation logic.conf_log.py: Logging configuration and initialization.config.py: Database and application configuration.db.py: Database connection and utility functions.dbrpp_calc: Main entry point script for running/scheduling the process.loader.py: Data loading and writing functions.models.py: SQLAlchemy ORM models for database tables.Private.parquet: Input data file for private data processing.processes.json: Tracks running processes for scheduling.restart.sh: Script to restart the main process.logs/: Directory for log files.pl/: Plugins or additional scripts.results.md: Output and results documentation.
Running the Main Script
The main script is dbrpp_calc. It supports several modes:
- schedule: Runs the process in the background, scheduled every minute.
- debug: Runs in debug mode, writing to a test database if available.
- run: Runs the process once.
./dbrpp_calc --help
nohup ./dbrpp_calc -m schedule > logs/stdout.log 2>&1 &
./restart.sh
Logging and Configuration
- Logging is set up in
conf_log.pyand used throughout the project. Log files are stored inlogs/. - Configuration (database URLs, credentials, etc.) is managed in
config.pyand.env.
Database and Data Model
SQLAlchemy Models (models.py)
CC: Stores currency data (usd, time).Rates: Stores rates (r1, r2, r3, r4, time, votes, v1, v2, v3).RatesA: Stores alternative rates (dbr_s, dbr, aa1, aa2, aa3, aa4, time).DVotesAll: Tracks all votes (created_at, ...).DPartners: Partner data.DVotes: Individual vote data.Public: Aggregated public data (time, dbr_display, btc_display, btc_color, btc_arrow, btc_pct_display, xau_display, ...).
Each model maps to a table in the database, with fields, types, and constraints as defined in models.py.
Private.parquet
Private.parquet is a Parquet file containing private data, loaded and processed by loader.py for further calculations and database insertion.
Data Processing and Calculation
- Main flow is in
calculations.pyand orchestrated bydbrpp_calc. count_public_dataandcount_private_datafunctions aggregate, process, and format data for public and private outputs.loader.pyhandles reading fromPrivate.parquetand writing processed data to the database.db.pyprovides database connection utilities and aConnectionHandlerclass for executing queries.
Testing and Validation
format_test.pycontains unit tests for data formatting and validation functions.- Run tests using:
python format_test.py
Configuration and Logging
config.py: Defines database URLs, credentials, and other settings.conf_log.py: Sets up logging format, level, and output files.
Process and Workflow
processes.json: Tracks running process IDs for scheduling and management.restart.sh: Shell script to restart the main process.- Scheduling is handled by
scheduleindbrpp_calcand can be run in the background usingnohup.
Results and Outputs
- Output files and logs are generated in the
logs/directory. results.mddocuments output formats and results for reference.