Update app.py
Browse files
app.py
CHANGED
|
@@ -141,8 +141,8 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
|
|
| 141 |
punch_list_text = str(punch_list_text) if punch_list_text else ""
|
| 142 |
missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
|
| 143 |
open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
|
| 144 |
-
# Use the provided date and time (02:
|
| 145 |
-
evaluated_at = "2025-05-
|
| 146 |
alert_sent = str(bool(escalated)).lower() # Converts True/False to "true"/"false"
|
| 147 |
logging.info(f"Setting Alert_Sent__c to: {alert_sent}")
|
| 148 |
escalation_flag = str(bool(escalated)).lower() # Ensure this is also a proper boolean string
|
|
@@ -227,11 +227,13 @@ def sanitize_input(text):
|
|
| 227 |
# Rule-based completeness engine with weighted scoring
|
| 228 |
def evaluate_readiness(logs, qa_report, punch_list_text):
|
| 229 |
try:
|
| 230 |
-
#
|
| 231 |
-
|
|
|
|
| 232 |
|
| 233 |
# Log inputs for debugging
|
| 234 |
-
logging.info(f"Inputs - Logs: {logs}, QA Report: {qa_report}, Punch List: {punch_list_text}
|
|
|
|
| 235 |
|
| 236 |
# Initialize score and lists for tracking
|
| 237 |
score = 0
|
|
@@ -247,18 +249,22 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
|
|
| 247 |
logs = sanitize_input(logs)
|
| 248 |
qa_report = sanitize_input(qa_report)
|
| 249 |
punch_list_text = sanitize_input(punch_list_text)
|
| 250 |
-
|
|
|
|
| 251 |
|
| 252 |
# Process Project Logs (30% weight)
|
| 253 |
-
# Check
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
| 255 |
if logs_pass:
|
| 256 |
score += LOGS_WEIGHT
|
| 257 |
checklist_details.append("Logs: Completed")
|
| 258 |
else:
|
| 259 |
missing_items.append("Project Logs Incomplete")
|
| 260 |
checklist_details.append("Logs: Pending")
|
| 261 |
-
logging.info(f"Logs Check: {'Pass' if logs_pass else 'Fail'}, Score so far: {score}%")
|
| 262 |
|
| 263 |
# Process QA Report (40% weight)
|
| 264 |
qa_keywords = r"approved|passed|cleared"
|
|
@@ -286,11 +292,16 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
|
|
| 286 |
open_punch_items = 0 if punch_pass else 1 # Simplified for dropdown input
|
| 287 |
|
| 288 |
# Enhanced escalation logic
|
| 289 |
-
escalated = score <
|
| 290 |
-
logging.info(f"Escalation Check: Score <
|
| 291 |
-
|
| 292 |
-
# Map
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
checklist_status = "Escalated" if escalated else ("Completed" if not missing_items else "Pending") # For UI display
|
| 295 |
|
| 296 |
# Build summaries
|
|
@@ -331,7 +342,7 @@ def generate_pdf(score, checklist_summary, missing_summary, checklist_status, lo
|
|
| 331 |
logging.info(f"Creating PDF at {pdf_path}")
|
| 332 |
|
| 333 |
# Use the provided date and time for the report
|
| 334 |
-
evaluation_datetime = "02:
|
| 335 |
|
| 336 |
# Create the PDF
|
| 337 |
c = canvas.Canvas(pdf_path, pagesize=letter)
|
|
|
|
| 141 |
punch_list_text = str(punch_list_text) if punch_list_text else ""
|
| 142 |
missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
|
| 143 |
open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
|
| 144 |
+
# Use the provided date and time (02:37 PM IST, May 24, 2025) in UTC for Salesforce
|
| 145 |
+
evaluated_at = "2025-05-24T09:07:00Z" # Converted 02:37 PM IST to UTC (IST is UTC+5:30)
|
| 146 |
alert_sent = str(bool(escalated)).lower() # Converts True/False to "true"/"false"
|
| 147 |
logging.info(f"Setting Alert_Sent__c to: {alert_sent}")
|
| 148 |
escalation_flag = str(bool(escalated)).lower() # Ensure this is also a proper boolean string
|
|
|
|
| 227 |
# Rule-based completeness engine with weighted scoring
|
| 228 |
def evaluate_readiness(logs, qa_report, punch_list_text):
|
| 229 |
try:
|
| 230 |
+
# Define keywords for completed and incomplete statuses
|
| 231 |
+
complete_keywords = r"completed|handover done|finished|closed|successful|done"
|
| 232 |
+
incomplete_keywords = r"not completed|incomplete|pending|not finished|not done|still in progress|delayed|on hold|issues remaining"
|
| 233 |
|
| 234 |
# Log inputs for debugging
|
| 235 |
+
logging.info(f"Inputs - Logs: {logs}, QA Report: {qa_report}, Punch List: {punch_list_text}")
|
| 236 |
+
logging.info(f"Complete Keywords: {complete_keywords}, Incomplete Keywords: {incomplete_keywords}")
|
| 237 |
|
| 238 |
# Initialize score and lists for tracking
|
| 239 |
score = 0
|
|
|
|
| 249 |
logs = sanitize_input(logs)
|
| 250 |
qa_report = sanitize_input(qa_report)
|
| 251 |
punch_list_text = sanitize_input(punch_list_text)
|
| 252 |
+
complete_keywords = sanitize_input(complete_keywords)
|
| 253 |
+
incomplete_keywords = sanitize_input(incomplete_keywords)
|
| 254 |
|
| 255 |
# Process Project Logs (30% weight)
|
| 256 |
+
# Check passes if complete_keywords match AND incomplete_keywords do not match
|
| 257 |
+
logs_lower = logs.lower()
|
| 258 |
+
has_complete = complete_keywords and re.search(complete_keywords, logs_lower)
|
| 259 |
+
has_incomplete = incomplete_keywords and re.search(incomplete_keywords, logs_lower)
|
| 260 |
+
logs_pass = logs and has_complete and not has_incomplete
|
| 261 |
if logs_pass:
|
| 262 |
score += LOGS_WEIGHT
|
| 263 |
checklist_details.append("Logs: Completed")
|
| 264 |
else:
|
| 265 |
missing_items.append("Project Logs Incomplete")
|
| 266 |
checklist_details.append("Logs: Pending")
|
| 267 |
+
logging.info(f"Logs Check: {'Pass' if logs_pass else 'Fail'} (Has Complete: {has_complete}, Has Incomplete: {has_incomplete}), Score so far: {score}%")
|
| 268 |
|
| 269 |
# Process QA Report (40% weight)
|
| 270 |
qa_keywords = r"approved|passed|cleared"
|
|
|
|
| 292 |
open_punch_items = 0 if punch_pass else 1 # Simplified for dropdown input
|
| 293 |
|
| 294 |
# Enhanced escalation logic
|
| 295 |
+
escalated = score < 50 or open_punch_items > 2 # Lowered escalation threshold to 50%
|
| 296 |
+
logging.info(f"Escalation Check: Score < 50 ({score < 50}), Open Punch Items > 2 ({open_punch_items > 2}), Escalated: {escalated}")
|
| 297 |
+
|
| 298 |
+
# Map status for Salesforce Status__c picklist
|
| 299 |
+
if escalated:
|
| 300 |
+
status = "Escalated"
|
| 301 |
+
elif "Logs: Pending" in checklist_details:
|
| 302 |
+
status = "In Progress" # If logs are pending, status should be "In Progress"
|
| 303 |
+
else:
|
| 304 |
+
status = "Completed" if not missing_items else "In Progress"
|
| 305 |
checklist_status = "Escalated" if escalated else ("Completed" if not missing_items else "Pending") # For UI display
|
| 306 |
|
| 307 |
# Build summaries
|
|
|
|
| 342 |
logging.info(f"Creating PDF at {pdf_path}")
|
| 343 |
|
| 344 |
# Use the provided date and time for the report
|
| 345 |
+
evaluation_datetime = "02:37 PM IST, May 24, 2025"
|
| 346 |
|
| 347 |
# Create the PDF
|
| 348 |
c = canvas.Canvas(pdf_path, pagesize=letter)
|