generate_docs.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # $Id$
  2. # $Author$
  3. # $log$
  4. import os
  5. docs_dir = "docs"
  6. os.makedirs(docs_dir, exist_ok=True)
  7. docs = {
  8. "Final_Report.md": """# $Id$
  9. # Final Project Report (Living Document)
  10. ## What Has Been Done
  11. 1. **Core Architecture**: Deployed a resilient 8-container local fallback Docker Compose stack (MySQL, Streamlit UI, local Ollama LLM, anonymous SearXNG search, secure Nginx proxy, and local Zabbix Server/Web/Agent observability suite).
  12. 2. **Database Optimization**: Successfully loaded OpenFoodFacts records and utilized advanced vertical partitioning and FULLTEXT indices.
  13. 3. **Clinical Subquery Strategy**: Refactored the core Pandas/SQL query pipeline to use subquery limiting, resolving Cartesian join explosions and reducing query latency to ~0.04s.
  14. 4. **Monitoring & Security**: Nginx securely proxies traffic on Port 80. Zabbix actively monitors proxy and server health, dynamically handling SNMP/alert loops in local/offline fallback mode.
  15. 5. **Git Versioning**: Implemented Git `.gitattributes` to push `$Id$` tracking directly into the Python Application UI.
  16. ## What Needs To Be Done (Day 2 Operations)
  17. 1. **SSL/TLS Certificates**: The Nginx proxy is functional on HTTP port 80. Port 443 (HTTPS) must be configured with a Let's Encrypt certificate for true production encryption.
  18. 2. **User Acceptance Testing (UAT)**: Clinical dietitians should rigorously test the AI Chat constraints and Plate Builder to ensure edge cases are handled safely.
  19. 3. **Advanced Rate Limiting**: Limit the number of AI requests per user using a sliding window algorithm in `app.py`.
  20. ## What Is The Next Step
  21. - Execute the `data_sync.sh` cron job monthly.
  22. - Maintain the automated `backup_db.sh` 7-day retention cycle.
  23. - Begin the hand-off to the operational team for Phase 2 feature requests.
  24. """,
  25. "Backup_Procedure.md": """# $Id$
  26. # Database Backup Procedure
  27. ## Automated Backups
  28. The system utilizes a cron job pointing to `backup_db.sh`.
  29. - The script dynamically detects the active MySQL container name (`food-mysql-1` or `food_project-mysql-1`) for high-availability robustness.
  30. - It executes `mysqldump` directly inside the detected MySQL container.
  31. - Outputs are piped to `gzip` and stored in `/backups`.
  32. - A 7-day retention policy automatically purges old backups using `find ... -mtime +7 -exec rm`.
  33. ## Manual Restore
  34. To manually restore a backup (adjust container name to `food-mysql-1` or `food_project-mysql-1` as appropriate):
  35. `gunzip < backups/food_db_20260507_0200.sql.gz | docker exec -i food-mysql-1 mysql -u root -proot_pass food_db`
  36. """,
  37. "Data_Ingestion.md": """# $Id$
  38. # Data Ingestion Pipeline
  39. ## Overview
  40. The application utilizes `data_sync.sh` to update the OpenFoodFacts dataset.
  41. ## Online Mode
  42. Run `bash data_sync.sh --online`. The script will download the latest CSV directly from the official servers and trigger the ingestion pipeline.
  43. ## Offline Mode
  44. Drop a `en.openfoodfacts.org.products.csv` file into the `/data` folder and run `bash data_sync.sh`. The script detects the file and triggers the Docker ingestion container.
  45. """,
  46. "Installation_Guide.md": """# $Id$
  47. # Installation Guide
  48. ## Requirements
  49. - Ubuntu 24.04 LTS (or WSL2)
  50. - Docker & Docker Compose
  51. - 16GB RAM Minimum
  52. ## Deployment Steps
  53. 1. **Clone the Repository**:
  54. - *Online Mode*: `git clone https://git.btshub.lu/lanfr/LocalFoodAI_lanfr144.git`
  55. - *Offline/Disconnected Mode*: Copy the repository files directly to the target environment via SCP or USB storage.
  56. 2. `cd LocalFoodAI_lanfr144`
  57. 3. `chmod +x data_sync.sh backup_db.sh`
  58. 4. **Deploy Stack**:
  59. - For regular production: `docker compose up -d --build`
  60. - For local/offline single-node fallback: `docker compose -f docker-compose_skip.yml up -d`
  61. 5. Navigate to `http://localhost` (or `http://localhost:8502` for direct Streamlit port)
  62. """,
  63. "User_Guide.md": """# $Id$
  64. # User Guide
  65. ## 1. Clinical Data Search
  66. Search for products using keywords. The system utilizes FULLTEXT matching to instantly return the top 10 relevant matches alongside macronutrient data.
  67. ## 2. My Plate Builder
  68. Add portion sizes of different foods to calculate cumulative nutritional intake. Use the 🗑️ icon to remove items.
  69. ## 3. Chat with AI
  70. Ask the `llama3.1` model complex dietary questions. It natively utilizes RAG Tool Calling to silently search the database and formulate clinical answers.
  71. """,
  72. "Wiki_Home.md": """# $Id$
  73. # Documentation Home
  74. Welcome to the static documentation mirror. Please navigate the markdown files in this directory for architectural diagrams and guides.
  75. """,
  76. "Scrum_Wiki.md": """# $Id$
  77. # Scrum Wiki Master List
  78. This file aggregates references to the Scrum daily logs, plans, and retrospectives.
  79. """,
  80. "Scrum_Daily.md": """# $Id$
  81. # Daily Scrums
  82. - **26.05.07 DAILY**: Fixed time scope bug, added Nginx proxy, built sync scripts.
  83. """,
  84. "Scrum_Plan.md": """# $Id$
  85. # Sprint Plans
  86. - **Sprint 10 PLAN**: Fix LLM Tool Calling, optimize Cartesian SQL explosion, build Teams webhooks.
  87. """,
  88. "Scrum_Retro.md": """# $Id$
  89. # Sprint Retrospectives
  90. - **Sprint 10 RETROSPECTIVE**: Mitigated dirty data duplicates using SQL `GROUP BY`. Need to maintain strict Git commit tagging (`TG-XXX`).
  91. """,
  92. "Scrum_Review.md": """# $Id$
  93. # Sprint Reviews
  94. - **Sprint 10 REVIEW**: App executes sub-second searches. Nginx fully operational on Port 80.
  95. """,
  96. "Scrum_Artifacts.md": """# $Id$
  97. # Scrum Artifacts
  98. Contains User Stories, velocity tracking, and burndown charts from Taiga.
  99. """,
  100. "Test_Cases_Sprint8.md": """# $Id$
  101. # Sprint 8 Legacy Test Cases
  102. - Tested RAG AI tool integration.
  103. - Tested user authentication flows.
  104. """,
  105. "WSL_Deployment.md": """# $Id$
  106. # WSL Deployment Runbook
  107. To deploy on Windows Subsystem for Linux:
  108. 1. Ensure WSL2 backend is enabled in Docker Desktop.
  109. 2. Follow standard Installation Guide inside the WSL Ubuntu terminal.
  110. """
  111. }
  112. import subprocess
  113. try:
  114. log_info = subprocess.check_output(['git', 'log', '-1', '--format=%H %ad %an %s', '--date=format:%Y/%m/%d %H:%M:%S'], encoding='utf-8').strip()
  115. try:
  116. tag_info = subprocess.check_output(['git', 'describe', '--tags', '--always'], stderr=subprocess.DEVNULL, encoding='utf-8').strip()
  117. except Exception:
  118. tag_info = ""
  119. if tag_info:
  120. git_id = f"$Id$"
  121. else:
  122. git_id = f"$Id$"
  123. except Exception:
  124. git_id = "$Id$"
  125. for filename, content in docs.items():
  126. filepath = os.path.join(docs_dir, filename)
  127. with open(filepath, "w", encoding="utf-8") as f:
  128. f.write(content.replace('$Id$', git_id))
  129. print(f"Generated {filepath}")
  130. print("\nDocs directory perfectly mirrored.")