diff --git a/.env.back b/.env.back new file mode 100644 index 0000000..bf4dcdc --- /dev/null +++ b/.env.back @@ -0,0 +1,87 @@ +# Northern Thailand Ping River Monitor Configuration +# Copy this file to .env and customize for your environment + +# Database Configuration +DB_TYPE=postgresql +# Options: sqlite, mysql, postgresql, influxdb, victoriametrics + +# SQLite Configuration (default) +WATER_DB_PATH=water_levels.db + +# VictoriaMetrics Configuration +VM_HOST=localhost +VM_PORT=8428 +VM_URL= + +# InfluxDB Configuration +INFLUX_HOST=localhost +INFLUX_PORT=8086 +INFLUX_DATABASE=ping_river_monitoring +INFLUX_USERNAME= +INFLUX_PASSWORD= + +# PostgreSQL Configuration (Remote Server) +# Option 1: Full connection string (URL encode special characters in password) +#POSTGRES_CONNECTION_STRING=postgresql://username:url_encoded_password@your-postgres-host:5432/water_monitoring + +# Option 2: Individual components (password will be automatically URL encoded) +POSTGRES_HOST=10.0.10.201 +POSTGRES_PORT=5432 +POSTGRES_DB=ping_river +POSTGRES_USER=ping_river +POSTGRES_PASSWORD=3_%m]k:+16"rx?M#`swIA + +# Examples for connection string: +# - Local: postgresql://postgres:password@localhost:5432/water_monitoring +# - Remote: postgresql://user:pass@192.168.1.100:5432/water_monitoring +# - With special chars: postgresql://user:my%3Apass%40word@host:5432/db +# - With SSL: postgresql://user:pass@host:port/db?sslmode=require +# - Connection pooling: postgresql://user:pass@host:port/db?pool_size=20&max_overflow=0 + +# Special character URL encoding: +# : → %3A @ → %40 # → %23 ? → %3F & → %26 / → %2F % → %25 + +# MySQL Configuration +MYSQL_CONNECTION_STRING=mysql://user:password@localhost:3306/ping_river_monitoring + +# API Configuration +API_HOST=0.0.0.0 +API_PORT=8000 +API_WORKERS=1 + +# Data Collection Settings +SCRAPING_INTERVAL_HOURS=1 +REQUEST_TIMEOUT=30 +MAX_RETRIES=3 +RETRY_DELAY_SECONDS=60 + +# Data Retention +DATA_RETENTION_DAYS=365 + +# Logging Configuration +LOG_LEVEL=INFO +LOG_FILE=water_monitor.log + +# Security (for production) +SECRET_KEY=your-secret-key-here +API_KEY=your-api-key-here + +# Monitoring +ENABLE_METRICS=true +ENABLE_HEALTH_CHECKS=true + +# Geographic Settings +TIMEZONE=Asia/Bangkok +DEFAULT_LATITUDE=18.7875 +DEFAULT_LONGITUDE=99.0045 + +# External Services +NOTIFICATION_EMAIL= +SMTP_SERVER= +SMTP_PORT=587 +SMTP_USERNAME= +SMTP_PASSWORD= + +# Development Settings +DEBUG=false +DEVELOPMENT_MODE=false \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..db6ede7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,40 @@ +# Pre-commit hooks for Northern Thailand Ping River Monitor +# See https://pre-commit.com for more information + +repos: + # General file checks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-json + - id: check-toml + - id: check-added-large-files + args: ['--maxkb=1000'] + - id: check-merge-conflict + - id: check-case-conflict + - id: mixed-line-ending + + # Python code formatting with Black + - repo: https://github.com/psf/black + rev: 23.11.0 + hooks: + - id: black + language_version: python3 + args: ['--line-length=120'] + + # Import sorting with isort + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + args: ['--profile', 'black', '--line-length', '120'] + + # Linting with flake8 + - repo: https://github.com/pycqa/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + args: ['--max-line-length=120', '--extend-ignore=E203,W503'] diff --git a/src/alerting.py b/src/alerting.py index 11e0030..305f4d3 100644 --- a/src/alerting.py +++ b/src/alerting.py @@ -261,7 +261,7 @@ class WaterLevelAlertSystem: return alerts - def check_data_freshness(self, max_age_hours: int = 2) -> List[WaterAlert]: + def check_data_freshness(self, max_age_hours: int = 4) -> List[WaterAlert]: """Check if data is fresh enough""" alerts = []