mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
commit
01de5d41bf
4 changed files with 5 additions and 10 deletions
|
|
@ -3,14 +3,12 @@ import json
|
||||||
import math
|
import math
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from backend.app.dependencies import validate_token
|
from backend.app.dependencies import validate_token
|
||||||
from backend.app.plan.schemas import PlanTriggerRequest
|
from backend.app.plan.schemas import PlanTriggerRequest
|
||||||
from backend.app.config import get_settings
|
from backend.app.config import get_settings
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from utils.logger import setup_logger
|
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.connection import db_engine
|
||||||
|
|
||||||
from backend.app.db.functions.recommendations_functions import create_scenario
|
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 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":
|
if data.get("file_format") == "domna_asset_list" and data.get("file_type") == "xlsx":
|
||||||
try:
|
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
|
chunk_size = 30
|
||||||
total_chunks = math.ceil(total_rows / chunk_size)
|
total_chunks = math.ceil(total_rows / chunk_size)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ class PlanTriggerRequest(BaseModel):
|
||||||
file_type: Optional[Literal["csv", "xlsx"]] = None
|
file_type: Optional[Literal["csv", "xlsx"]] = None
|
||||||
file_format: Optional[Literal["domna_asset_list"]] = None
|
file_format: Optional[Literal["domna_asset_list"]] = None
|
||||||
sheet_name: Optional[str] = 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
|
# If one of index_start or index_end is set, the other must be set too
|
||||||
index_start: Optional[int] = None
|
index_start: Optional[int] = None
|
||||||
index_end: Optional[int] = None
|
index_end: Optional[int] = None
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@ cryptography==43.0.3
|
||||||
mangum==0.19.0
|
mangum==0.19.0
|
||||||
# AWS
|
# AWS
|
||||||
boto3==1.35.44
|
boto3==1.35.44
|
||||||
|
# Data
|
||||||
|
openpyxl==3.1.2
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ def handler(event, context):
|
||||||
"""
|
"""
|
||||||
Lambda handler that triggers the model engine for each SQS message.
|
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", []):
|
for record in event.get("Records", []):
|
||||||
try:
|
try:
|
||||||
body_dict = json.loads(record["body"])
|
body_dict = json.loads(record["body"])
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue