Merge pull request #456 from Hestia-Homes/debugging-api

Debugging api
This commit is contained in:
KhalimCK 2025-07-22 18:05:32 +01:00 committed by GitHub
commit c176931ab9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 5 additions and 10 deletions

View file

@ -3,14 +3,12 @@ import json
import math
from datetime import datetime
import pandas as pd
from fastapi import APIRouter, Depends
from backend.app.dependencies import validate_token
from backend.app.plan.schemas import PlanTriggerRequest
from backend.app.config import get_settings
from sqlalchemy.orm import sessionmaker
from utils.logger import setup_logger
from utils.s3 import read_excel_from_s3
from backend.app.db.connection import db_engine
from backend.app.db.functions.recommendations_functions import create_scenario
@ -45,14 +43,8 @@ async def trigger_plan_entrypoint(body: PlanTriggerRequest):
# If file_format is domna_asset_list and type is xlsx, read and chunk it
if data.get("file_format") == "domna_asset_list" and data.get("file_type") == "xlsx":
try:
input_data: pd.DataFrame = read_excel_from_s3(
bucket_name=settings.PLAN_TRIGGER_BUCKET,
file_key=data.get("trigger_file_path"),
sheet_name=data.get("sheet_name"),
header_row=0
)
total_rows = len(input_data)
total_rows = body.get("sheet_count", 0)
chunk_size = 30
total_chunks = math.ceil(total_rows / chunk_size)

View file

@ -108,6 +108,7 @@ class PlanTriggerRequest(BaseModel):
file_type: Optional[Literal["csv", "xlsx"]] = None
file_format: Optional[Literal["domna_asset_list"]] = None
sheet_name: Optional[str] = None
sheet_count: Optional[int] = None
# If one of index_start or index_end is set, the other must be set too
index_start: Optional[int] = None
index_end: Optional[int] = None

View file

@ -8,4 +8,5 @@ cryptography==43.0.3
mangum==0.19.0
# AWS
boto3==1.35.44
# Data
openpyxl==3.1.2

View file

@ -11,6 +11,7 @@ def handler(event, context):
"""
Lambda handler that triggers the model engine for each SQS message.
"""
logger.info("Received event: %s", json.dumps(event, indent=2))
for record in event.get("Records", []):
try:
body_dict = json.loads(record["body"])