Álvaro Valenzuela Valdes commited on
Commit ·
1a73a61
1
Parent(s): 1ed9c25
feat: Implement auto-seeding on backend startup and absolute DB path
Browse files- Dockerfile +2 -0
- backend/app/main.py +80 -0
Dockerfile
CHANGED
|
@@ -12,6 +12,8 @@ RUN npm run build
|
|
| 12 |
# Final Image
|
| 13 |
FROM python:3.12-slim
|
| 14 |
WORKDIR /app
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Install Node.js (for running frontend in dev/ssr mode) and Nginx
|
| 17 |
RUN apt-get update && apt-get install -y \
|
|
|
|
| 12 |
# Final Image
|
| 13 |
FROM python:3.12-slim
|
| 14 |
WORKDIR /app
|
| 15 |
+
ENV DATABASE_URL="sqlite:////app/backend/andesops.db"
|
| 16 |
+
ENV PYTHONUNBUFFERED=1
|
| 17 |
|
| 18 |
# Install Node.js (for running frontend in dev/ssr mode) and Nginx
|
| 19 |
RUN apt-get update && apt-get install -y \
|
backend/app/main.py
CHANGED
|
@@ -30,6 +30,86 @@ app.include_router(analysis.router, prefix="/api", tags=["Analysis"])
|
|
| 30 |
app.include_router(company.router, prefix="/api", tags=["Company"])
|
| 31 |
app.include_router(documents.router, prefix="/api", tags=["Documents"])
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
@app.get("/")
|
| 34 |
def read_root():
|
| 35 |
return {"message": "Welcome to AndesOps AI API"}
|
|
|
|
| 30 |
app.include_router(company.router, prefix="/api", tags=["Company"])
|
| 31 |
app.include_router(documents.router, prefix="/api", tags=["Documents"])
|
| 32 |
|
| 33 |
+
@app.on_event("startup")
|
| 34 |
+
async def startup_event():
|
| 35 |
+
from app.database import SessionLocal
|
| 36 |
+
from app.models.tender import TenderModel
|
| 37 |
+
from app.models.analysis import AnalysisHistoryModel
|
| 38 |
+
from app.models.company import CompanyProfileModel
|
| 39 |
+
from datetime import datetime, timedelta
|
| 40 |
+
import json
|
| 41 |
+
|
| 42 |
+
db = SessionLocal()
|
| 43 |
+
try:
|
| 44 |
+
count = db.query(TenderModel).count()
|
| 45 |
+
if count == 0:
|
| 46 |
+
print("Database empty. Seeding data...")
|
| 47 |
+
# 1. Company Profile
|
| 48 |
+
profile = CompanyProfileModel(
|
| 49 |
+
name="Andes Digital Solutions",
|
| 50 |
+
industry="Software Engineering & AI",
|
| 51 |
+
services="Machine Learning, Custom ERP, Cloud Infrastructure",
|
| 52 |
+
experience="10+ years delivering enterprise software for the public sector.",
|
| 53 |
+
certifications="AWS Partner, ISO 9001, SCRUM Master Team",
|
| 54 |
+
regions="Metropolitana, Valparaíso, Biobío, Araucanía",
|
| 55 |
+
documents_available="RUT, Financial Statements 2023, Technical Portfolio, Staff Certifications"
|
| 56 |
+
)
|
| 57 |
+
db.add(profile)
|
| 58 |
+
|
| 59 |
+
# 2. Software Tenders
|
| 60 |
+
tenders_data = [
|
| 61 |
+
TenderModel(
|
| 62 |
+
code="2394-15-LR24",
|
| 63 |
+
name="Implementación Sistema ERP para Red de Salud Oriente",
|
| 64 |
+
description="Suministro, instalación y soporte de sistema de gestión de recursos empresariales para red hospitalaria.",
|
| 65 |
+
buyer="Servicio de Salud Metropolitano",
|
| 66 |
+
status="Publicada",
|
| 67 |
+
closing_date=(datetime.now() + timedelta(days=20)).strftime("%Y-%m-%d"),
|
| 68 |
+
estimated_amount=450000000,
|
| 69 |
+
region="Metropolitana",
|
| 70 |
+
sector="Tecnología de la Información",
|
| 71 |
+
source="Mercado Público"
|
| 72 |
+
),
|
| 73 |
+
TenderModel(
|
| 74 |
+
code="5021-10-LP24",
|
| 75 |
+
name="Plataforma de IA para Análisis de Datos Criminalísticos",
|
| 76 |
+
description="Desarrollo de algoritmos de visión computacional y análisis predictivo para seguridad ciudadana.",
|
| 77 |
+
buyer="Subsecretaría de Prevención del Delito",
|
| 78 |
+
status="Publicada",
|
| 79 |
+
closing_date=(datetime.now() + timedelta(days=12)).strftime("%Y-%m-%d"),
|
| 80 |
+
estimated_amount=180000000,
|
| 81 |
+
region="Metropolitana",
|
| 82 |
+
sector="Software & IA",
|
| 83 |
+
source="Mercado Público"
|
| 84 |
+
)
|
| 85 |
+
]
|
| 86 |
+
for t in tenders_data:
|
| 87 |
+
db.add(t)
|
| 88 |
+
|
| 89 |
+
# 3. Initial Analysis
|
| 90 |
+
history = AnalysisHistoryModel(
|
| 91 |
+
tender_code="5021-10-LP24",
|
| 92 |
+
tender_name="Plataforma de IA para Análisis de Datos Criminalísticos",
|
| 93 |
+
decision="Recommended",
|
| 94 |
+
score=92,
|
| 95 |
+
summary="Oportunidad estratégica de alto valor. Tenemos el stack tecnológico (Gemini, Python) y la experiencia previa en seguridad ciudadana.",
|
| 96 |
+
risks=json.dumps([
|
| 97 |
+
{"severity": "High", "description": "Requisito de disponibilidad 99.9% 24/7"},
|
| 98 |
+
{"severity": "Medium", "description": "Integración con bases de datos legacy de Carabineros"}
|
| 99 |
+
]),
|
| 100 |
+
technical_analysis="Factibilidad técnica excelente.",
|
| 101 |
+
legal_analysis="Cumplimos con las bases.",
|
| 102 |
+
commercial_analysis="ROI del 35%.",
|
| 103 |
+
proposal_draft="Propuesta técnica...",
|
| 104 |
+
report_markdown="# Reporte",
|
| 105 |
+
created_at=datetime.now()
|
| 106 |
+
)
|
| 107 |
+
db.add(history)
|
| 108 |
+
db.commit()
|
| 109 |
+
print("Database seeded successfully!")
|
| 110 |
+
finally:
|
| 111 |
+
db.close()
|
| 112 |
+
|
| 113 |
@app.get("/")
|
| 114 |
def read_root():
|
| 115 |
return {"message": "Welcome to AndesOps AI API"}
|