first commit

This commit is contained in:
2026-03-19 22:54:29 +03:30
parent 1a178f39b7
commit 035bc6f74d
91 changed files with 3821 additions and 130 deletions
+77 -1
View File
@@ -6,6 +6,8 @@ from dotenv import load_dotenv
load_dotenv()
BASE_DIR = Path(__file__).resolve().parent.parent
LOG_DIR = Path(os.environ.get("LOG_DIR", BASE_DIR / "logs"))
LOG_DIR.mkdir(parents=True, exist_ok=True)
SECRET_KEY = os.environ.get("SECRET_KEY", "django-insecure-dev-only")
DEBUG = os.environ.get("DEBUG", "0") == "1"
@@ -20,10 +22,15 @@ INSTALLED_APPS = [
"django.contrib.staticfiles",
"rest_framework",
"corsheaders",
"drf_spectacular",
"drf_spectacular_sidecar",
"rag",
"tasks",
"soil_data",
"location_data",
"sensor_data",
"weather",
"plant",
"irrigation",
]
MIDDLEWARE = [
@@ -98,6 +105,25 @@ REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.AllowAny",
],
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
SPECTACULAR_SETTINGS = {
"TITLE": "CropLogic AI API",
"DESCRIPTION": "API‌های هوش مصنوعی CropLogic — داده خاک، سنسور، هواشناسی و چت RAG",
"VERSION": "1.0.0",
"SERVE_INCLUDE_SCHEMA": False,
"SWAGGER_UI_DIST": "SIDECAR",
"SWAGGER_UI_FAVICON_HREF": "SIDECAR",
"REDOC_DIST": "SIDECAR",
"COMPONENT_SPLIT_REQUEST": True,
"TAGS": [
{"name": "RAG Chat", "description": "چت هوشمند RAG"},
{"name": "Tasks", "description": "مدیریت تسک‌های Celery"},
{"name": "Soil Data", "description": "داده‌های خاک (SoilGrids)"},
{"name": "Sensor Data", "description": "داده‌های سنسور"},
{"name": "Sensor Parameters", "description": "پارامترهای سنسور"},
],
}
CORS_ALLOW_ALL_ORIGINS = DEBUG
@@ -114,4 +140,54 @@ CELERY_BEAT_SCHEDULE = {
"task": "rag.tasks.rag_ingest_task",
"schedule": 6 * 60 * 60, # ۶ ساعت
},
"weather-fetch-periodic": {
"task": "weather.tasks.fetch_weather_all_locations_task",
"schedule": 6 * 60 * 60, # ۶ ساعت
},
}
# Weather API
WEATHER_API_BASE_URL = os.environ.get(
"WEATHER_API_BASE_URL", "https://api.open-meteo.com/v1/forecast"
)
WEATHER_API_KEY = os.environ.get("WEATHER_API_KEY", "")
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"standard": {
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "standard",
},
"file": {
"class": "logging.handlers.TimedRotatingFileHandler",
"filename": str(LOG_DIR / "app.log"),
"when": "midnight",
"backupCount": 14,
"encoding": "utf-8",
"formatter": "standard",
},
},
"loggers": {
"django": {
"handlers": ["console", "file"],
"level": os.environ.get("DJANGO_LOG_LEVEL", "INFO"),
"propagate": False,
},
"rag": {
"handlers": ["console", "file"],
"level": os.environ.get("RAG_LOG_LEVEL", "INFO"),
"propagate": False,
},
},
"root": {
"handlers": ["console", "file"],
"level": os.environ.get("ROOT_LOG_LEVEL", "INFO"),
},
}